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",
37 target_os
= "openbsd"))]
38 pub const FIOCLEX
: libc
::c_ulong
= 0x20006601;
40 #[cfg(any(all(target_os = "linux",
41 any(target_arch
= "x86",
42 target_arch
= "x86_64",
44 target_arch
= "aarch64")),
45 target_os
= "android"))]
46 pub const FIOCLEX
: libc
::c_ulong
= 0x5451;
48 #[cfg(all(target_os = "linux",
49 any(target_arch
= "mips",
50 target_arch
= "mipsel",
51 target_arch
= "powerpc")))]
52 pub const FIOCLEX
: libc
::c_ulong
= 0x6601;
54 pub const WNOHANG
: libc
::c_int
= 1;
56 #[cfg(target_os = "linux")]
57 pub const _SC_GETPW_R_SIZE_MAX
: libc
::c_int
= 70;
58 #[cfg(any(target_os = "macos",
59 target_os
= "freebsd",
60 target_os
= "dragonfly"))]
61 pub const _SC_GETPW_R_SIZE_MAX
: libc
::c_int
= 71;
62 #[cfg(any(target_os = "bitrig",
63 target_os
= "openbsd"))]
64 pub const _SC_GETPW_R_SIZE_MAX
: libc
::c_int
= 101;
65 #[cfg(target_os = "android")]
66 pub const _SC_GETPW_R_SIZE_MAX
: libc
::c_int
= 0x0048;
69 #[cfg(target_os = "linux")]
71 pub pw_name
: *mut libc
::c_char
,
72 pub pw_passwd
: *mut libc
::c_char
,
73 pub pw_uid
: libc
::uid_t
,
74 pub pw_gid
: libc
::gid_t
,
75 pub pw_gecos
: *mut libc
::c_char
,
76 pub pw_dir
: *mut libc
::c_char
,
77 pub pw_shell
: *mut libc
::c_char
,
81 #[cfg(any(target_os = "macos",
82 target_os
= "freebsd",
83 target_os
= "dragonfly",
85 target_os
= "openbsd"))]
87 pub pw_name
: *mut libc
::c_char
,
88 pub pw_passwd
: *mut libc
::c_char
,
89 pub pw_uid
: libc
::uid_t
,
90 pub pw_gid
: libc
::gid_t
,
91 pub pw_change
: libc
::time_t
,
92 pub pw_class
: *mut libc
::c_char
,
93 pub pw_gecos
: *mut libc
::c_char
,
94 pub pw_dir
: *mut libc
::c_char
,
95 pub pw_shell
: *mut libc
::c_char
,
96 pub pw_expire
: libc
::time_t
,
100 #[cfg(target_os = "android")]
102 pub pw_name
: *mut libc
::c_char
,
103 pub pw_passwd
: *mut libc
::c_char
,
104 pub pw_uid
: libc
::uid_t
,
105 pub pw_gid
: libc
::gid_t
,
106 pub pw_dir
: *mut libc
::c_char
,
107 pub pw_shell
: *mut libc
::c_char
,
110 // This is really a function pointer (or a union of multiple function
111 // pointers), except for constants like SIG_DFL.
112 pub type sighandler_t
= *mut libc
::c_void
;
114 pub const SIG_DFL
: sighandler_t
= 0 as sighandler_t
;
115 pub const SIG_ERR
: sighandler_t
= !0 as sighandler_t
;
118 pub fn getsockopt(sockfd
: libc
::c_int
,
120 optname
: libc
::c_int
,
121 optval
: *mut libc
::c_void
,
122 optlen
: *mut libc
::socklen_t
) -> libc
::c_int
;
123 pub fn ioctl(fd
: libc
::c_int
, req
: libc
::c_ulong
, ...) -> libc
::c_int
;
126 pub fn waitpid(pid
: libc
::pid_t
, status
: *mut libc
::c_int
,
127 options
: libc
::c_int
) -> libc
::pid_t
;
129 pub fn raise(signum
: libc
::c_int
) -> libc
::c_int
;
131 pub fn sigaction(signum
: libc
::c_int
,
132 act
: *const sigaction
,
133 oldact
: *mut sigaction
) -> libc
::c_int
;
135 pub fn sigaltstack(ss
: *const sigaltstack
,
136 oss
: *mut sigaltstack
) -> libc
::c_int
;
138 #[cfg(not(target_os = "android"))]
139 pub fn sigemptyset(set
: *mut sigset_t
) -> libc
::c_int
;
141 pub fn pthread_sigmask(how
: libc
::c_int
, set
: *const sigset_t
,
142 oldset
: *mut sigset_t
) -> libc
::c_int
;
144 #[cfg(not(target_os = "ios"))]
145 pub fn getpwuid_r(uid
: libc
::uid_t
,
147 buf
: *mut libc
::c_char
,
148 buflen
: libc
::size_t
,
149 result
: *mut *mut passwd
) -> libc
::c_int
;
151 pub fn utimes(filename
: *const libc
::c_char
,
152 times
: *const libc
::timeval
) -> libc
::c_int
;
153 pub fn gai_strerror(errcode
: libc
::c_int
) -> *const libc
::c_char
;
154 pub fn setgroups(ngroups
: libc
::c_int
,
155 ptr
: *const libc
::c_void
) -> libc
::c_int
;
156 pub fn realpath(pathname
: *const libc
::c_char
, resolved
: *mut libc
::c_char
)
157 -> *mut libc
::c_char
;
160 // Ugh. This is only available as an inline until Android API 21.
161 #[cfg(target_os = "android")]
162 pub unsafe fn sigemptyset(set
: *mut sigset_t
) -> libc
::c_int
{
164 intrinsics
::write_bytes(set
, 0, 1);
168 #[cfg(any(target_os = "linux",
169 target_os
= "android"))]
171 pub use self::arch
::{SA_ONSTACK
, SA_SIGINFO
, SIGBUS
, SIG_SETMASK
,
172 sigaction
, sigaltstack
};
175 #[cfg(any(target_arch = "x86",
176 target_arch
= "x86_64",
178 target_arch
= "mips",
179 target_arch
= "mipsel"))]
180 pub const SIGSTKSZ
: libc
::size_t
= 8192;
182 // This is smaller on musl and Android, but no harm in being generous.
183 #[cfg(any(target_arch = "aarch64",
184 target_arch
= "powerpc"))]
185 pub const SIGSTKSZ
: libc
::size_t
= 16384;
187 // This definition is intentionally a subset of the C structure: the
188 // fields after si_code are actually a giant union. We're only
189 // interested in si_addr for this module, though.
195 // This structure will need extra padding here for MIPS64.
196 pub si_addr
: *mut libc
::c_void
199 #[cfg(all(target_os = "linux", target_pointer_width = "32"))]
201 pub struct sigset_t
{
202 __val
: [libc
::c_ulong
; 32],
205 #[cfg(all(target_os = "linux", target_pointer_width = "64"))]
207 pub struct sigset_t
{
208 __val
: [libc
::c_ulong
; 16],
211 // Android for MIPS has a 128-bit sigset_t, but we don't currently
212 // support it. Android for AArch64 technically has a structure of a
214 #[cfg(target_os = "android")]
215 pub type sigset_t
= libc
::c_ulong
;
217 #[cfg(any(target_arch = "x86",
218 target_arch
= "x86_64",
219 target_arch
= "powerpc",
221 target_arch
= "aarch64"))]
224 use super::super::sighandler_t
;
227 pub const SA_ONSTACK
: libc
::c_ulong
= 0x08000000;
228 pub const SA_SIGINFO
: libc
::c_ulong
= 0x00000004;
230 pub const SIGBUS
: libc
::c_int
= 7;
232 pub const SIG_SETMASK
: libc
::c_int
= 2;
234 #[cfg(target_os = "linux")]
236 pub struct sigaction
{
237 pub sa_sigaction
: sighandler_t
,
238 pub sa_mask
: sigset_t
,
239 pub sa_flags
: libc
::c_ulong
,
240 _restorer
: *mut libc
::c_void
,
243 #[cfg(all(target_os = "android", target_pointer_width = "32"))]
245 pub struct sigaction
{
246 pub sa_sigaction
: sighandler_t
,
247 pub sa_flags
: libc
::c_ulong
,
248 _restorer
: *mut libc
::c_void
,
249 pub sa_mask
: sigset_t
,
252 #[cfg(all(target_os = "android", target_pointer_width = "64"))]
254 pub struct sigaction
{
255 pub sa_flags
: libc
::c_uint
,
256 pub sa_sigaction
: sighandler_t
,
257 pub sa_mask
: sigset_t
,
258 _restorer
: *mut libc
::c_void
,
262 pub struct sigaltstack
{
263 pub ss_sp
: *mut libc
::c_void
,
264 pub ss_flags
: libc
::c_int
,
265 pub ss_size
: libc
::size_t
269 #[cfg(any(target_arch = "mips",
270 target_arch
= "mipsel"))]
273 use super::super::sighandler_t
;
276 pub const SA_ONSTACK
: libc
::c_ulong
= 0x08000000;
277 pub const SA_SIGINFO
: libc
::c_ulong
= 0x00000008;
279 pub const SIGBUS
: libc
::c_int
= 10;
281 pub const SIG_SETMASK
: libc
::c_int
= 3;
283 #[cfg(all(target_os = "linux", not(target_env = "musl")))]
285 pub struct sigaction
{
286 pub sa_flags
: libc
::c_uint
,
287 pub sa_sigaction
: sighandler_t
,
288 pub sa_mask
: sigset_t
,
289 _restorer
: *mut libc
::c_void
,
290 _resv
: [libc
::c_int
; 1],
293 #[cfg(target_env = "musl")]
295 pub struct sigaction
{
296 pub sa_sigaction
: sighandler_t
,
297 pub sa_mask
: sigset_t
,
298 pub sa_flags
: libc
::c_ulong
,
299 _restorer
: *mut libc
::c_void
,
302 #[cfg(target_os = "android")]
304 pub struct sigaction
{
305 pub sa_flags
: libc
::c_uint
,
306 pub sa_sigaction
: sighandler_t
,
307 pub sa_mask
: sigset_t
,
311 pub struct sigaltstack
{
312 pub ss_sp
: *mut libc
::c_void
,
313 pub ss_size
: libc
::size_t
,
314 pub ss_flags
: libc
::c_int
,
319 #[cfg(any(target_os = "macos",
321 target_os
= "freebsd",
322 target_os
= "dragonfly",
323 target_os
= "bitrig",
324 target_os
= "openbsd"))]
327 use super::sighandler_t
;
329 pub const SA_ONSTACK
: libc
::c_int
= 0x0001;
330 pub const SA_SIGINFO
: libc
::c_int
= 0x0040;
332 pub const SIGBUS
: libc
::c_int
= 10;
334 #[cfg(any(target_os = "macos", target_os = "ios"))]
335 pub const SIGSTKSZ
: libc
::size_t
= 131072;
336 // FreeBSD's is actually arch-dependent, but never more than 40960.
337 // No harm in being generous.
338 #[cfg(not(any(target_os = "macos", target_os = "ios")))]
339 pub const SIGSTKSZ
: libc
::size_t
= 40960;
341 pub const SIG_SETMASK
: libc
::c_int
= 3;
343 #[cfg(any(target_os = "macos",
345 pub type sigset_t
= u32;
346 #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
348 pub struct sigset_t
{
351 #[cfg(any(target_os = "bitrig", target_os = "openbsd"))]
352 pub type sigset_t
= libc
::c_uint
;
354 // This structure has more fields, but we're not all that interested in
356 #[cfg(any(target_os = "macos", target_os = "ios",
357 target_os
= "freebsd", target_os
= "dragonfly"))]
360 pub _signo
: libc
::c_int
,
361 pub _errno
: libc
::c_int
,
362 pub _code
: libc
::c_int
,
363 pub _pid
: libc
::pid_t
,
364 pub _uid
: libc
::uid_t
,
365 pub _status
: libc
::c_int
,
366 pub si_addr
: *mut libc
::c_void
368 #[cfg(any(target_os = "bitrig", target_os = "openbsd"))]
371 pub si_signo
: libc
::c_int
,
372 pub si_code
: libc
::c_int
,
373 pub si_errno
: libc
::c_int
,
374 pub si_addr
: *mut libc
::c_void
377 #[cfg(any(target_os = "macos", target_os = "ios",
378 target_os
= "bitrig", target_os
= "openbsd"))]
380 pub struct sigaction
{
381 pub sa_sigaction
: sighandler_t
,
382 pub sa_mask
: sigset_t
,
383 pub sa_flags
: libc
::c_int
,
386 #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
388 pub struct sigaction
{
389 pub sa_sigaction
: sighandler_t
,
390 pub sa_flags
: libc
::c_int
,
391 pub sa_mask
: sigset_t
,
395 pub struct sigaltstack
{
396 pub ss_sp
: *mut libc
::c_void
,
397 pub ss_size
: libc
::size_t
,
398 pub ss_flags
: libc
::c_int
,