1 // Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! C definitions used by std::sys that don't belong in liblibc
13 // These are definitions sufficient for the users in this directory.
14 // This is not a general-purpose binding to this functionality, and in
15 // some cases (notably the definition of siginfo_t), we intentionally
16 // have incomplete bindings so that we don't need to fight with unions.
18 // Note that these types need to match the definitions from the platform
19 // libc (currently glibc on Linux), not the kernel definitions / the
20 // syscall interface. This has a few weirdnesses, like glibc's sigset_t
21 // being 1024 bits on all platforms. If you're adding a new GNU/Linux
22 // port, check glibc's sysdeps/unix/sysv/linux, not the kernel headers.
25 #![allow(non_camel_case_types)]
27 pub use self::signal_os::{sigaction, siginfo, sigset_t, sigaltstack};
28 pub use self::signal_os::{SA_ONSTACK, SA_SIGINFO, SIGBUS, SIGSTKSZ, SIG_SETMASK};
32 #[cfg(any(target_os = "macos",
34 target_os = "freebsd",
35 target_os = "dragonfly",
38 target_os = "openbsd"))]
39 pub const FIOCLEX: libc::c_ulong = 0x20006601;
41 #[cfg(any(all(target_os = "linux",
42 any(target_arch = "x86",
43 target_arch = "x86_64",
45 target_arch = "aarch64")),
46 target_os = "android"))]
47 pub const FIOCLEX: libc::c_ulong = 0x5451;
49 #[cfg(all(target_os = "linux",
50 any(target_arch = "mips",
51 target_arch = "mipsel",
52 target_arch = "powerpc")))]
53 pub const FIOCLEX: libc::c_ulong = 0x6601;
55 pub const WNOHANG: libc::c_int = 1;
57 #[cfg(target_os = "linux")]
58 pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 70;
59 #[cfg(any(target_os = "macos",
60 target_os = "freebsd",
61 target_os = "dragonfly"))]
62 pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 71;
63 #[cfg(any(target_os = "bitrig",
65 target_os = "openbsd"))]
66 pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 101;
67 #[cfg(target_os = "android")]
68 pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 0x0048;
71 #[cfg(target_os = "linux")]
73 pub pw_name: *mut libc::c_char,
74 pub pw_passwd: *mut libc::c_char,
75 pub pw_uid: libc::uid_t,
76 pub pw_gid: libc::gid_t,
77 pub pw_gecos: *mut libc::c_char,
78 pub pw_dir: *mut libc::c_char,
79 pub pw_shell: *mut libc::c_char,
83 #[cfg(any(target_os = "macos",
84 target_os = "freebsd",
85 target_os = "dragonfly",
88 target_os = "openbsd"))]
90 pub pw_name: *mut libc::c_char,
91 pub pw_passwd: *mut libc::c_char,
92 pub pw_uid: libc::uid_t,
93 pub pw_gid: libc::gid_t,
94 pub pw_change: libc::time_t,
95 pub pw_class: *mut libc::c_char,
96 pub pw_gecos: *mut libc::c_char,
97 pub pw_dir: *mut libc::c_char,
98 pub pw_shell: *mut libc::c_char,
99 pub pw_expire: libc::time_t,
103 #[cfg(target_os = "android")]
105 pub pw_name: *mut libc::c_char,
106 pub pw_passwd: *mut libc::c_char,
107 pub pw_uid: libc::uid_t,
108 pub pw_gid: libc::gid_t,
109 pub pw_dir: *mut libc::c_char,
110 pub pw_shell: *mut libc::c_char,
113 // This is really a function pointer (or a union of multiple function
114 // pointers), except for constants like SIG_DFL.
115 pub type sighandler_t = *mut libc::c_void;
117 pub const SIG_DFL: sighandler_t = 0 as sighandler_t;
118 pub const SIG_ERR: sighandler_t = !0 as sighandler_t;
121 pub fn getsockopt(sockfd: libc::c_int,
123 optname: libc::c_int,
124 optval: *mut libc::c_void,
125 optlen: *mut libc::socklen_t) -> libc::c_int;
126 pub fn ioctl(fd: libc::c_int, req: libc::c_ulong, ...) -> libc::c_int;
129 pub fn waitpid(pid: libc::pid_t, status: *mut libc::c_int,
130 options: libc::c_int) -> libc::pid_t;
132 pub fn raise(signum: libc::c_int) -> libc::c_int;
134 pub fn sigaction(signum: libc::c_int,
135 act: *const sigaction,
136 oldact: *mut sigaction) -> libc::c_int;
138 pub fn sigaltstack(ss: *const sigaltstack,
139 oss: *mut sigaltstack) -> libc::c_int;
141 #[cfg(not(target_os = "android"))]
142 pub fn sigemptyset(set: *mut sigset_t) -> libc::c_int;
144 pub fn pthread_sigmask(how: libc::c_int, set: *const sigset_t,
145 oldset: *mut sigset_t) -> libc::c_int;
147 #[cfg(not(target_os = "ios"))]
148 pub fn getpwuid_r(uid: libc::uid_t,
150 buf: *mut libc::c_char,
151 buflen: libc::size_t,
152 result: *mut *mut passwd) -> libc::c_int;
154 pub fn utimes(filename: *const libc::c_char,
155 times: *const libc::timeval) -> libc::c_int;
156 pub fn gai_strerror(errcode: libc::c_int) -> *const libc::c_char;
157 pub fn setgroups(ngroups: libc::c_int,
158 ptr: *const libc::c_void) -> libc::c_int;
159 pub fn realpath(pathname: *const libc::c_char, resolved: *mut libc::c_char)
160 -> *mut libc::c_char;
163 // Ugh. This is only available as an inline until Android API 21.
164 #[cfg(target_os = "android")]
165 pub unsafe fn sigemptyset(set: *mut sigset_t) -> libc::c_int {
167 intrinsics::write_bytes(set, 0, 1);
171 #[cfg(any(target_os = "linux",
172 target_os = "android"))]
174 pub use self::arch::{SA_ONSTACK, SA_SIGINFO, SIGBUS, SIG_SETMASK,
175 sigaction, sigaltstack};
178 #[cfg(any(target_arch = "x86",
179 target_arch = "x86_64",
181 target_arch = "mips",
182 target_arch = "mipsel"))]
183 pub const SIGSTKSZ: libc::size_t = 8192;
185 // This is smaller on musl and Android, but no harm in being generous.
186 #[cfg(any(target_arch = "aarch64",
187 target_arch = "powerpc"))]
188 pub const SIGSTKSZ: libc::size_t = 16384;
190 // This definition is intentionally a subset of the C structure: the
191 // fields after si_code are actually a giant union. We're only
192 // interested in si_addr for this module, though.
198 // This structure will need extra padding here for MIPS64.
199 pub si_addr: *mut libc::c_void
202 #[cfg(all(target_os = "linux", target_pointer_width = "32"))]
204 pub struct sigset_t {
205 __val: [libc::c_ulong; 32],
208 #[cfg(all(target_os = "linux", target_pointer_width = "64"))]
210 pub struct sigset_t {
211 __val: [libc::c_ulong; 16],
214 // Android for MIPS has a 128-bit sigset_t, but we don't currently
215 // support it. Android for AArch64 technically has a structure of a
217 #[cfg(target_os = "android")]
218 pub type sigset_t = libc::c_ulong;
220 #[cfg(any(target_arch = "x86",
221 target_arch = "x86_64",
222 target_arch = "powerpc",
224 target_arch = "aarch64"))]
227 use super::super::sighandler_t;
230 pub const SA_ONSTACK: libc::c_ulong = 0x08000000;
231 pub const SA_SIGINFO: libc::c_ulong = 0x00000004;
233 pub const SIGBUS: libc::c_int = 7;
235 pub const SIG_SETMASK: libc::c_int = 2;
237 #[cfg(target_os = "linux")]
239 pub struct sigaction {
240 pub sa_sigaction: sighandler_t,
241 pub sa_mask: sigset_t,
242 pub sa_flags: libc::c_ulong,
243 _restorer: *mut libc::c_void,
246 #[cfg(all(target_os = "android", target_pointer_width = "32"))]
248 pub struct sigaction {
249 pub sa_sigaction: sighandler_t,
250 pub sa_flags: libc::c_ulong,
251 _restorer: *mut libc::c_void,
252 pub sa_mask: sigset_t,
255 #[cfg(all(target_os = "android", target_pointer_width = "64"))]
257 pub struct sigaction {
258 pub sa_flags: libc::c_uint,
259 pub sa_sigaction: sighandler_t,
260 pub sa_mask: sigset_t,
261 _restorer: *mut libc::c_void,
265 pub struct sigaltstack {
266 pub ss_sp: *mut libc::c_void,
267 pub ss_flags: libc::c_int,
268 pub ss_size: libc::size_t
272 #[cfg(any(target_arch = "mips",
273 target_arch = "mipsel"))]
276 use super::super::sighandler_t;
279 pub const SA_ONSTACK: libc::c_ulong = 0x08000000;
280 pub const SA_SIGINFO: libc::c_ulong = 0x00000008;
282 pub const SIGBUS: libc::c_int = 10;
284 pub const SIG_SETMASK: libc::c_int = 3;
286 #[cfg(all(target_os = "linux", not(target_env = "musl")))]
288 pub struct sigaction {
289 pub sa_flags: libc::c_uint,
290 pub sa_sigaction: sighandler_t,
291 pub sa_mask: sigset_t,
292 _restorer: *mut libc::c_void,
293 _resv: [libc::c_int; 1],
296 #[cfg(target_env = "musl")]
298 pub struct sigaction {
299 pub sa_sigaction: sighandler_t,
300 pub sa_mask: sigset_t,
301 pub sa_flags: libc::c_ulong,
302 _restorer: *mut libc::c_void,
305 #[cfg(target_os = "android")]
307 pub struct sigaction {
308 pub sa_flags: libc::c_uint,
309 pub sa_sigaction: sighandler_t,
310 pub sa_mask: sigset_t,
314 pub struct sigaltstack {
315 pub ss_sp: *mut libc::c_void,
316 pub ss_size: libc::size_t,
317 pub ss_flags: libc::c_int,
322 #[cfg(any(target_os = "macos",
324 target_os = "freebsd",
325 target_os = "dragonfly",
326 target_os = "bitrig",
327 target_os = "netbsd",
328 target_os = "openbsd"))]
331 use super::sighandler_t;
333 pub const SA_ONSTACK: libc::c_int = 0x0001;
334 pub const SA_SIGINFO: libc::c_int = 0x0040;
336 pub const SIGBUS: libc::c_int = 10;
338 #[cfg(any(target_os = "macos", target_os = "ios"))]
339 pub const SIGSTKSZ: libc::size_t = 131072;
340 // FreeBSD's is actually arch-dependent, but never more than 40960.
341 // No harm in being generous.
342 #[cfg(not(any(target_os = "macos", target_os = "ios")))]
343 pub const SIGSTKSZ: libc::size_t = 40960;
345 pub const SIG_SETMASK: libc::c_int = 3;
347 #[cfg(any(target_os = "macos",
349 pub type sigset_t = u32;
350 #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
352 pub struct sigset_t {
355 #[cfg(any(target_os = "bitrig", target_os = "netbsd", target_os = "openbsd"))]
356 pub type sigset_t = libc::c_uint;
358 // This structure has more fields, but we're not all that interested in
360 #[cfg(any(target_os = "macos", target_os = "ios",
361 target_os = "freebsd", target_os = "dragonfly"))]
364 pub _signo: libc::c_int,
365 pub _errno: libc::c_int,
366 pub _code: libc::c_int,
367 pub _pid: libc::pid_t,
368 pub _uid: libc::uid_t,
369 pub _status: libc::c_int,
370 pub si_addr: *mut libc::c_void
372 #[cfg(any(target_os = "bitrig", target_os = "netbsd", target_os = "openbsd"))]
375 pub si_signo: libc::c_int,
376 pub si_code: libc::c_int,
377 pub si_errno: libc::c_int,
378 pub si_addr: *mut libc::c_void
381 #[cfg(any(target_os = "macos", target_os = "ios",
382 target_os = "bitrig", target_os = "netbsd", target_os = "openbsd"))]
384 pub struct sigaction {
385 pub sa_sigaction: sighandler_t,
386 pub sa_mask: sigset_t,
387 pub sa_flags: libc::c_int,
390 #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
392 pub struct sigaction {
393 pub sa_sigaction: sighandler_t,
394 pub sa_flags: libc::c_int,
395 pub sa_mask: sigset_t,
399 pub struct sigaltstack {
400 pub ss_sp: *mut libc::c_void,
401 pub ss_size: libc::size_t,
402 pub ss_flags: libc::c_int,