1 pub type shmatt_t = ::c_ulong;
2 pub type msgqnum_t = ::c_ulong;
3 pub type msglen_t = ::c_ulong;
4 pub type regoff_t = ::c_int;
5 pub type rlim_t = ::c_ulong;
6 pub type __rlimit_resource_t = ::c_ulong;
7 pub type __priority_which_t = ::c_uint;
8 
9 cfg_if! {
10     if #[cfg(doc)] {
11         // Used in `linux::arch` to define ioctl constants.
12         pub(crate) type Ioctl = ::c_ulong;
13     } else {
14         #[doc(hidden)]
15         pub type Ioctl = ::c_ulong;
16     }
17 }
18 
19 s! {
20     pub struct statvfs {  // Different than GNU!
21         pub f_bsize: ::c_ulong,
22         pub f_frsize: ::c_ulong,
23         pub f_blocks: ::fsblkcnt_t,
24         pub f_bfree: ::fsblkcnt_t,
25         pub f_bavail: ::fsblkcnt_t,
26         pub f_files: ::fsfilcnt_t,
27         pub f_ffree: ::fsfilcnt_t,
28         pub f_favail: ::fsfilcnt_t,
29         #[cfg(target_endian = "little")]
30         pub f_fsid: ::c_ulong,
31         #[cfg(target_pointer_width = "32")]
32         __f_unused: ::c_int,
33         #[cfg(target_endian = "big")]
34         pub f_fsid: ::c_ulong,
35         pub f_flag: ::c_ulong,
36         pub f_namemax: ::c_ulong,
37         __f_spare: [::c_int; 6],
38     }
39 
40     pub struct regex_t {
41         __buffer: *mut ::c_void,
42         __allocated: ::size_t,
43         __used: ::size_t,
44         __syntax: ::c_ulong,
45         __fastmap: *mut ::c_char,
46         __translate: *mut ::c_char,
47         __re_nsub: ::size_t,
48         __bitfield: u8,
49     }
50 
51     pub struct rtentry {
52         pub rt_pad1: ::c_ulong,
53         pub rt_dst: ::sockaddr,
54         pub rt_gateway: ::sockaddr,
55         pub rt_genmask: ::sockaddr,
56         pub rt_flags: ::c_ushort,
57         pub rt_pad2: ::c_short,
58         pub rt_pad3: ::c_ulong,
59         pub rt_tos: ::c_uchar,
60         pub rt_class: ::c_uchar,
61         #[cfg(target_pointer_width = "64")]
62         pub rt_pad4: [::c_short; 3usize],
63         #[cfg(not(target_pointer_width = "64"))]
64         pub rt_pad4: ::c_short,
65         pub rt_metric: ::c_short,
66         pub rt_dev: *mut ::c_char,
67         pub rt_mtu: ::c_ulong,
68         pub rt_window: ::c_ulong,
69         pub rt_irtt: ::c_ushort,
70     }
71 
72     pub struct __exit_status {
73         pub e_termination: ::c_short,
74         pub e_exit: ::c_short,
75     }
76 
77     pub struct ptrace_peeksiginfo_args {
78         pub off: ::__u64,
79         pub flags: ::__u32,
80         pub nr: ::__s32,
81     }
82 
83     #[cfg_attr(any(target_pointer_width = "32",
84                    target_arch = "x86_64",
85                    target_arch = "powerpc64",
86                    target_arch = "mips64",
87                    target_arch = "s390x",
88                    target_arch = "sparc64"),
89                repr(align(4)))]
90     #[cfg_attr(not(any(target_pointer_width = "32",
91                        target_arch = "x86_64",
92                        target_arch = "powerpc64",
93                        target_arch = "mips64",
94                        target_arch = "s390x",
95                        target_arch = "sparc64")),
96                repr(align(8)))]
97     pub struct pthread_mutexattr_t {
98         size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T],
99     }
100 
101     #[repr(align(4))]
102     pub struct pthread_condattr_t {
103         size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T],
104     }
105 }
106 
107 impl siginfo_t {
108     pub unsafe fn si_addr(&self) -> *mut ::c_void {
109         #[repr(C)]
110         struct siginfo_sigfault {
111             _si_signo: ::c_int,
112             _si_errno: ::c_int,
113             _si_code: ::c_int,
114             si_addr: *mut ::c_void,
115         }
116         (*(self as *const siginfo_t as *const siginfo_sigfault)).si_addr
117     }
118 
119     pub unsafe fn si_value(&self) -> ::sigval {
120         #[repr(C)]
121         struct siginfo_si_value {
122             _si_signo: ::c_int,
123             _si_errno: ::c_int,
124             _si_code: ::c_int,
125             _si_timerid: ::c_int,
126             _si_overrun: ::c_int,
127             si_value: ::sigval,
128         }
129         (*(self as *const siginfo_t as *const siginfo_si_value)).si_value
130     }
131 }
132 
133 // Internal, for casts to access union fields
134 #[repr(C)]
135 struct sifields_sigchld {
136     si_pid: ::pid_t,
137     si_uid: ::uid_t,
138     si_status: ::c_int,
139     si_utime: ::c_long,
140     si_stime: ::c_long,
141 }
142 impl ::Copy for sifields_sigchld {}
143 impl ::Clone for sifields_sigchld {
144     fn clone(&self) -> sifields_sigchld {
145         *self
146     }
147 }
148 
149 // Internal, for casts to access union fields
150 #[repr(C)]
151 union sifields {
152     _align_pointer: *mut ::c_void,
153     sigchld: sifields_sigchld,
154 }
155 
156 // Internal, for casts to access union fields. Note that some variants
157 // of sifields start with a pointer, which makes the alignment of
158 // sifields vary on 32-bit and 64-bit architectures.
159 #[repr(C)]
160 struct siginfo_f {
161     _siginfo_base: [::c_int; 3],
162     sifields: sifields,
163 }
164 
165 impl siginfo_t {
166     unsafe fn sifields(&self) -> &sifields {
167         &(*(self as *const siginfo_t as *const siginfo_f)).sifields
168     }
169 
170     pub unsafe fn si_pid(&self) -> ::pid_t {
171         self.sifields().sigchld.si_pid
172     }
173 
174     pub unsafe fn si_uid(&self) -> ::uid_t {
175         self.sifields().sigchld.si_uid
176     }
177 
178     pub unsafe fn si_status(&self) -> ::c_int {
179         self.sifields().sigchld.si_status
180     }
181 
182     pub unsafe fn si_utime(&self) -> ::c_long {
183         self.sifields().sigchld.si_utime
184     }
185 
186     pub unsafe fn si_stime(&self) -> ::c_long {
187         self.sifields().sigchld.si_stime
188     }
189 }
190 
191 pub const MCL_CURRENT: ::c_int = 0x0001;
192 pub const MCL_FUTURE: ::c_int = 0x0002;
193 pub const MCL_ONFAULT: ::c_int = 0x0004;
194 
195 pub const SIGEV_THREAD_ID: ::c_int = 4;
196 
197 pub const AF_VSOCK: ::c_int = 40;
198 
199 // Most `*_SUPER_MAGIC` constants are defined at the `linux_like` level; the
200 // following are only available on newer Linux versions than the versions
201 // currently used in CI in some configurations, so we define them here.
202 pub const BINDERFS_SUPER_MAGIC: ::c_long = 0x6c6f6f70;
203 pub const XFS_SUPER_MAGIC: ::c_long = 0x58465342;
204 
205 pub const PTRACE_TRACEME: ::c_int = 0;
206 pub const PTRACE_PEEKTEXT: ::c_int = 1;
207 pub const PTRACE_PEEKDATA: ::c_int = 2;
208 pub const PTRACE_PEEKUSER: ::c_int = 3;
209 pub const PTRACE_POKETEXT: ::c_int = 4;
210 pub const PTRACE_POKEDATA: ::c_int = 5;
211 pub const PTRACE_POKEUSER: ::c_int = 6;
212 pub const PTRACE_CONT: ::c_int = 7;
213 pub const PTRACE_KILL: ::c_int = 8;
214 pub const PTRACE_SINGLESTEP: ::c_int = 9;
215 pub const PTRACE_GETREGS: ::c_int = 12;
216 pub const PTRACE_SETREGS: ::c_int = 13;
217 pub const PTRACE_GETFPREGS: ::c_int = 14;
218 pub const PTRACE_SETFPREGS: ::c_int = 15;
219 pub const PTRACE_ATTACH: ::c_int = 16;
220 pub const PTRACE_DETACH: ::c_int = 17;
221 pub const PTRACE_GETFPXREGS: ::c_int = 18;
222 pub const PTRACE_SETFPXREGS: ::c_int = 19;
223 pub const PTRACE_SYSCALL: ::c_int = 24;
224 pub const PTRACE_SETOPTIONS: ::c_int = 0x4200;
225 pub const PTRACE_GETEVENTMSG: ::c_int = 0x4201;
226 pub const PTRACE_GETSIGINFO: ::c_int = 0x4202;
227 pub const PTRACE_SETSIGINFO: ::c_int = 0x4203;
228 pub const PTRACE_GETREGSET: ::c_int = 0x4204;
229 pub const PTRACE_SETREGSET: ::c_int = 0x4205;
230 pub const PTRACE_SEIZE: ::c_int = 0x4206;
231 pub const PTRACE_INTERRUPT: ::c_int = 0x4207;
232 pub const PTRACE_LISTEN: ::c_int = 0x4208;
233 
234 pub const POSIX_FADV_DONTNEED: ::c_int = 4;
235 pub const POSIX_FADV_NOREUSE: ::c_int = 5;
236 
237 // These are different than GNU!
238 pub const LC_CTYPE: ::c_int = 0;
239 pub const LC_NUMERIC: ::c_int = 1;
240 pub const LC_TIME: ::c_int = 3;
241 pub const LC_COLLATE: ::c_int = 4;
242 pub const LC_MONETARY: ::c_int = 2;
243 pub const LC_MESSAGES: ::c_int = 5;
244 pub const LC_ALL: ::c_int = 6;
245 // end different section
246 
247 // MS_ flags for mount(2)
248 pub const MS_RMT_MASK: ::c_ulong = ::MS_RDONLY | ::MS_SYNCHRONOUS | ::MS_MANDLOCK | ::MS_I_VERSION;
249 
250 pub const ENOTSUP: ::c_int = EOPNOTSUPP;
251 
252 pub const IPV6_JOIN_GROUP: ::c_int = 20;
253 pub const IPV6_LEAVE_GROUP: ::c_int = 21;
254 
255 // These are different from GNU
256 pub const ABDAY_1: ::nl_item = 0x300;
257 pub const ABDAY_2: ::nl_item = 0x301;
258 pub const ABDAY_3: ::nl_item = 0x302;
259 pub const ABDAY_4: ::nl_item = 0x303;
260 pub const ABDAY_5: ::nl_item = 0x304;
261 pub const ABDAY_6: ::nl_item = 0x305;
262 pub const ABDAY_7: ::nl_item = 0x306;
263 pub const DAY_1: ::nl_item = 0x307;
264 pub const DAY_2: ::nl_item = 0x308;
265 pub const DAY_3: ::nl_item = 0x309;
266 pub const DAY_4: ::nl_item = 0x30A;
267 pub const DAY_5: ::nl_item = 0x30B;
268 pub const DAY_6: ::nl_item = 0x30C;
269 pub const DAY_7: ::nl_item = 0x30D;
270 pub const ABMON_1: ::nl_item = 0x30E;
271 pub const ABMON_2: ::nl_item = 0x30F;
272 pub const ABMON_3: ::nl_item = 0x310;
273 pub const ABMON_4: ::nl_item = 0x311;
274 pub const ABMON_5: ::nl_item = 0x312;
275 pub const ABMON_6: ::nl_item = 0x313;
276 pub const ABMON_7: ::nl_item = 0x314;
277 pub const ABMON_8: ::nl_item = 0x315;
278 pub const ABMON_9: ::nl_item = 0x316;
279 pub const ABMON_10: ::nl_item = 0x317;
280 pub const ABMON_11: ::nl_item = 0x318;
281 pub const ABMON_12: ::nl_item = 0x319;
282 pub const MON_1: ::nl_item = 0x31A;
283 pub const MON_2: ::nl_item = 0x31B;
284 pub const MON_3: ::nl_item = 0x31C;
285 pub const MON_4: ::nl_item = 0x31D;
286 pub const MON_5: ::nl_item = 0x31E;
287 pub const MON_6: ::nl_item = 0x31F;
288 pub const MON_7: ::nl_item = 0x320;
289 pub const MON_8: ::nl_item = 0x321;
290 pub const MON_9: ::nl_item = 0x322;
291 pub const MON_10: ::nl_item = 0x323;
292 pub const MON_11: ::nl_item = 0x324;
293 pub const MON_12: ::nl_item = 0x325;
294 pub const AM_STR: ::nl_item = 0x326;
295 pub const PM_STR: ::nl_item = 0x327;
296 pub const D_T_FMT: ::nl_item = 0x328;
297 pub const D_FMT: ::nl_item = 0x329;
298 pub const T_FMT: ::nl_item = 0x32A;
299 pub const T_FMT_AMPM: ::nl_item = 0x32B;
300 pub const ERA: ::nl_item = 0x32C;
301 pub const ERA_D_FMT: ::nl_item = 0x32E;
302 pub const ALT_DIGITS: ::nl_item = 0x32F;
303 pub const ERA_D_T_FMT: ::nl_item = 0x330;
304 pub const ERA_T_FMT: ::nl_item = 0x331;
305 pub const CODESET: ::nl_item = 10;
306 pub const CRNCYSTR: ::nl_item = 0x215;
307 pub const RADIXCHAR: ::nl_item = 0x100;
308 pub const THOUSEP: ::nl_item = 0x101;
309 pub const NOEXPR: ::nl_item = 0x501;
310 pub const YESSTR: ::nl_item = 0x502;
311 pub const NOSTR: ::nl_item = 0x503;
312 
313 // Different than Gnu.
314 pub const FILENAME_MAX: ::c_uint = 4095;
315 
316 pub const PRIO_PROCESS: ::c_int = 0;
317 pub const PRIO_PGRP: ::c_int = 1;
318 pub const PRIO_USER: ::c_int = 2;
319 
320 pub const SOMAXCONN: ::c_int = 128;
321 
322 pub const ST_RELATIME: ::c_ulong = 4096;
323 
324 pub const AF_NFC: ::c_int = PF_NFC;
325 pub const BUFSIZ: ::c_int = 4096;
326 pub const EDEADLOCK: ::c_int = EDEADLK;
327 pub const EXTA: ::c_uint = B19200;
328 pub const EXTB: ::c_uint = B38400;
329 pub const EXTPROC: ::tcflag_t = 0o200000;
330 pub const FOPEN_MAX: ::c_int = 16;
331 pub const F_GETOWN: ::c_int = 9;
332 pub const F_OFD_GETLK: ::c_int = 36;
333 pub const F_OFD_SETLK: ::c_int = 37;
334 pub const F_OFD_SETLKW: ::c_int = 38;
335 pub const F_RDLCK: ::c_int = 0;
336 pub const F_SETOWN: ::c_int = 8;
337 pub const F_UNLCK: ::c_int = 2;
338 pub const F_WRLCK: ::c_int = 1;
339 pub const IPV6_MULTICAST_ALL: ::c_int = 29;
340 pub const IPV6_ROUTER_ALERT_ISOLATE: ::c_int = 30;
341 pub const MAP_HUGE_SHIFT: ::c_int = 26;
342 pub const MAP_HUGE_MASK: ::c_int = 0x3f;
343 pub const MAP_HUGE_64KB: ::c_int = 16 << MAP_HUGE_SHIFT;
344 pub const MAP_HUGE_512KB: ::c_int = 19 << MAP_HUGE_SHIFT;
345 pub const MAP_HUGE_1MB: ::c_int = 20 << MAP_HUGE_SHIFT;
346 pub const MAP_HUGE_2MB: ::c_int = 21 << MAP_HUGE_SHIFT;
347 pub const MAP_HUGE_8MB: ::c_int = 23 << MAP_HUGE_SHIFT;
348 pub const MAP_HUGE_16MB: ::c_int = 24 << MAP_HUGE_SHIFT;
349 pub const MAP_HUGE_32MB: ::c_int = 25 << MAP_HUGE_SHIFT;
350 pub const MAP_HUGE_256MB: ::c_int = 28 << MAP_HUGE_SHIFT;
351 pub const MAP_HUGE_512MB: ::c_int = 29 << MAP_HUGE_SHIFT;
352 pub const MAP_HUGE_1GB: ::c_int = 30 << MAP_HUGE_SHIFT;
353 pub const MAP_HUGE_2GB: ::c_int = 31 << MAP_HUGE_SHIFT;
354 pub const MAP_HUGE_16GB: ::c_int = 34 << MAP_HUGE_SHIFT;
355 pub const MINSIGSTKSZ: ::c_int = 2048;
356 pub const MSG_COPY: ::c_int = 0o40000;
357 pub const NI_MAXHOST: ::socklen_t = 1025;
358 pub const O_TMPFILE: ::c_int = 0o20000000 | O_DIRECTORY;
359 pub const PACKET_MR_UNICAST: ::c_int = 3;
360 pub const PF_NFC: ::c_int = 39;
361 pub const PF_VSOCK: ::c_int = 40;
362 pub const POSIX_MADV_DONTNEED: ::c_int = 4;
363 pub const PTRACE_EVENT_STOP: ::c_int = 128;
364 pub const PTRACE_GETSIGMASK: ::c_uint = 0x420a;
365 pub const PTRACE_PEEKSIGINFO: ::c_int = 0x4209;
366 pub const PTRACE_SETSIGMASK: ::c_uint = 0x420b;
367 pub const RTLD_NOLOAD: ::c_int = 0x00004;
368 pub const RUSAGE_THREAD: ::c_int = 1;
369 pub const SHM_EXEC: ::c_int = 0o100000;
370 pub const SIGPOLL: ::c_int = SIGIO;
371 pub const SOCK_DCCP: ::c_int = 6;
372 pub const SOCK_PACKET: ::c_int = 10;
373 pub const TCP_COOKIE_TRANSACTIONS: ::c_int = 15;
374 pub const UDP_GRO: ::c_int = 104;
375 pub const UDP_SEGMENT: ::c_int = 103;
376 pub const YESEXPR: ::c_int = ((5) << 8) | (0);
377 
378 extern "C" {
379     pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::timezone) -> ::c_int;
380 
381     pub fn pthread_rwlockattr_getkind_np(
382         attr: *const ::pthread_rwlockattr_t,
383         val: *mut ::c_int,
384     ) -> ::c_int;
385     pub fn pthread_rwlockattr_setkind_np(
386         attr: *mut ::pthread_rwlockattr_t,
387         val: ::c_int,
388     ) -> ::c_int;
389 
390     pub fn ptrace(request: ::c_uint, ...) -> ::c_long;
391 
392     pub fn sendmmsg(
393         sockfd: ::c_int,
394         msgvec: *mut ::mmsghdr,
395         vlen: ::c_uint,
396         flags: ::c_int,
397     ) -> ::c_int;
398     pub fn recvmmsg(
399         sockfd: ::c_int,
400         msgvec: *mut ::mmsghdr,
401         vlen: ::c_uint,
402         flags: ::c_int,
403         timeout: *mut ::timespec,
404     ) -> ::c_int;
405 
406     pub fn openpty(
407         amaster: *mut ::c_int,
408         aslave: *mut ::c_int,
409         name: *mut ::c_char,
410         termp: *mut termios,
411         winp: *mut ::winsize,
412     ) -> ::c_int;
413     pub fn forkpty(
414         amaster: *mut ::c_int,
415         name: *mut ::c_char,
416         termp: *mut termios,
417         winp: *mut ::winsize,
418     ) -> ::pid_t;
419 
420     pub fn getnameinfo(
421         sa: *const ::sockaddr,
422         salen: ::socklen_t,
423         host: *mut ::c_char,
424         hostlen: ::socklen_t,
425         serv: *mut ::c_char,
426         servlen: ::socklen_t,
427         flags: ::c_int,
428     ) -> ::c_int;
429 
430     pub fn pwritev(
431         fd: ::c_int,
432         iov: *const ::iovec,
433         iovcnt: ::c_int,
434         offset: ::off64_t,
435     ) -> ::ssize_t;
436     pub fn preadv(
437         fd: ::c_int,
438         iov: *const ::iovec,
439         iovcnt: ::c_int,
440         offset: ::off64_t,
441     ) -> ::ssize_t;
442 
443     pub fn sethostid(hostid: ::c_long) -> ::c_int;
444     pub fn fanotify_mark(
445         fd: ::c_int,
446         flags: ::c_uint,
447         mask: u64,
448         dirfd: ::c_int,
449         path: *const ::c_char,
450     ) -> ::c_int;
451     pub fn getrlimit64(resource: ::__rlimit_resource_t, rlim: *mut ::rlimit64) -> ::c_int;
452     pub fn setrlimit64(resource: ::__rlimit_resource_t, rlim: *const ::rlimit64) -> ::c_int;
453     pub fn getrlimit(resource: ::__rlimit_resource_t, rlim: *mut ::rlimit) -> ::c_int;
454     pub fn setrlimit(resource: ::__rlimit_resource_t, rlim: *const ::rlimit) -> ::c_int;
455     pub fn getpriority(which: ::__priority_which_t, who: ::id_t) -> ::c_int;
456     pub fn setpriority(which: ::__priority_which_t, who: ::id_t, prio: ::c_int) -> ::c_int;
457     pub fn getauxval(type_: ::c_ulong) -> ::c_ulong;
458 }
459 
460 cfg_if! {
461     if #[cfg(any(target_arch = "mips", target_arch = "mips64"))] {
462         mod mips;
463         pub use self::mips::*;
464     } else if #[cfg(target_arch = "x86_64")] {
465         mod x86_64;
466         pub use self::x86_64::*;
467     } else if #[cfg(target_arch = "arm")] {
468         mod arm;
469         pub use self::arm::*;
470     } else {
471         pub use unsupported_target;
472     }
473 }
474