xref: /drstd/dlibc/src/unix/platform/dragonos/musl/mod.rs (revision b38c79420b3f9b2af3cf74b30d9faaadb20eb8b0)
1 pub type pthread_t = *mut ::c_void;
2 pub type clock_t = c_long;
3 
4 pub type time_t = i64;
5 pub type suseconds_t = i64;
6 pub type ino_t = u64;
7 pub type off_t = i64;
8 pub type blkcnt_t = i64;
9 
10 pub type shmatt_t = ::c_ulong;
11 pub type msgqnum_t = ::c_ulong;
12 pub type msglen_t = ::c_ulong;
13 pub type fsblkcnt_t = ::c_ulonglong;
14 pub type fsfilcnt_t = ::c_ulonglong;
15 pub type rlim_t = ::c_ulonglong;
16 
17 cfg_if! {
18     if #[cfg(doc)] {
19         // Used in `linux::arch` to define ioctl constants.
20         pub(crate) type Ioctl = ::c_int;
21     } else {
22         #[doc(hidden)]
23         pub type Ioctl = ::c_int;
24     }
25 }
26 
27 impl siginfo_t {
28     pub unsafe fn si_addr(&self) -> *mut ::c_void {
29         #[repr(C)]
30         struct siginfo_sigfault {
31             _si_signo: ::c_int,
32             _si_errno: ::c_int,
33             _si_code: ::c_int,
34             si_addr: *mut ::c_void,
35         }
36         (*(self as *const siginfo_t as *const siginfo_sigfault)).si_addr
37     }
38 
39     pub unsafe fn si_value(&self) -> ::sigval {
40         #[repr(C)]
41         struct siginfo_si_value {
42             _si_signo: ::c_int,
43             _si_errno: ::c_int,
44             _si_code: ::c_int,
45             _si_timerid: ::c_int,
46             _si_overrun: ::c_int,
47             si_value: ::sigval,
48         }
49         (*(self as *const siginfo_t as *const siginfo_si_value)).si_value
50     }
51 }
52 
53 cfg_if! {
54     if #[cfg(libc_union)] {
55         // Internal, for casts to access union fields
56         #[repr(C)]
57         struct sifields_sigchld {
58             si_pid: ::pid_t,
59             si_uid: ::uid_t,
60             si_status: ::c_int,
61             si_utime: ::c_long,
62             si_stime: ::c_long,
63         }
64         impl ::Copy for sifields_sigchld {}
65         impl ::Clone for sifields_sigchld {
66             fn clone(&self) -> sifields_sigchld {
67                 *self
68             }
69         }
70 
71         // Internal, for casts to access union fields
72         #[repr(C)]
73         union sifields {
74             _align_pointer: *mut ::c_void,
75             sigchld: sifields_sigchld,
76         }
77 
78         // Internal, for casts to access union fields. Note that some variants
79         // of sifields start with a pointer, which makes the alignment of
80         // sifields vary on 32-bit and 64-bit architectures.
81         #[repr(C)]
82         struct siginfo_f {
83             _siginfo_base: [::c_int; 3],
84             sifields: sifields,
85         }
86 
87         impl siginfo_t {
88             unsafe fn sifields(&self) -> &sifields {
89                 &(*(self as *const siginfo_t as *const siginfo_f)).sifields
90             }
91 
92             pub unsafe fn si_pid(&self) -> ::pid_t {
93                 self.sifields().sigchld.si_pid
94             }
95 
96             pub unsafe fn si_uid(&self) -> ::uid_t {
97                 self.sifields().sigchld.si_uid
98             }
99 
100             pub unsafe fn si_status(&self) -> ::c_int {
101                 self.sifields().sigchld.si_status
102             }
103 
104             pub unsafe fn si_utime(&self) -> ::c_long {
105                 self.sifields().sigchld.si_utime
106             }
107 
108             pub unsafe fn si_stime(&self) -> ::c_long {
109                 self.sifields().sigchld.si_stime
110             }
111         }
112     }
113 }
114 
115 s! {
116     pub struct aiocb {
117         pub aio_fildes: ::c_int,
118         pub aio_lio_opcode: ::c_int,
119         pub aio_reqprio: ::c_int,
120         pub aio_buf: *mut ::c_void,
121         pub aio_nbytes: ::size_t,
122         pub aio_sigevent: ::sigevent,
123         __td: *mut ::c_void,
124         __lock: [::c_int; 2],
125         __err: ::c_int,
126         __ret: ::ssize_t,
127         pub aio_offset: off_t,
128         __next: *mut ::c_void,
129         __prev: *mut ::c_void,
130         #[cfg(target_pointer_width = "32")]
131         __dummy4: [::c_char; 24],
132         #[cfg(target_pointer_width = "64")]
133         __dummy4: [::c_char; 16],
134     }
135 
136     pub struct sigaction {
137         pub sa_sigaction: ::sighandler_t,
138         pub sa_mask: ::sigset_t,
139         pub sa_flags: ::c_int,
140         pub sa_restorer: ::Option<unsafe extern fn()>,
141     }
142 
143     pub struct statvfs {
144         pub f_bsize: ::c_ulong,
145         pub f_frsize: ::c_ulong,
146         pub f_blocks: ::fsblkcnt_t,
147         pub f_bfree: ::fsblkcnt_t,
148         pub f_bavail: ::fsblkcnt_t,
149         pub f_files: ::fsfilcnt_t,
150         pub f_ffree: ::fsfilcnt_t,
151         pub f_favail: ::fsfilcnt_t,
152         #[cfg(target_endian = "little")]
153         pub f_fsid: ::c_ulong,
154         #[cfg(target_pointer_width = "32")]
155         __f_unused: ::c_int,
156         #[cfg(target_endian = "big")]
157         pub f_fsid: ::c_ulong,
158         pub f_flag: ::c_ulong,
159         pub f_namemax: ::c_ulong,
160         __f_spare: [::c_int; 6],
161     }
162 
163     pub struct termios {
164         pub c_iflag: ::tcflag_t,
165         pub c_oflag: ::tcflag_t,
166         pub c_cflag: ::tcflag_t,
167         pub c_lflag: ::tcflag_t,
168         pub c_line: ::cc_t,
169         pub c_cc: [::cc_t; ::NCCS],
170         pub __c_ispeed: ::speed_t,
171         pub __c_ospeed: ::speed_t,
172     }
173 
174     pub struct flock {
175         pub l_type: ::c_short,
176         pub l_whence: ::c_short,
177         pub l_start: ::off_t,
178         pub l_len: ::off_t,
179         pub l_pid: ::pid_t,
180     }
181 
182     pub struct flock64 {
183         pub l_type: ::c_short,
184         pub l_whence: ::c_short,
185         pub l_start: ::off64_t,
186         pub l_len: ::off64_t,
187         pub l_pid: ::pid_t,
188     }
189 
190     pub struct regex_t {
191         __re_nsub: ::size_t,
192         __opaque: *mut ::c_void,
193         __padding: [*mut ::c_void; 4usize],
194         __nsub2: ::size_t,
195         __padding2: ::c_char,
196     }
197 
198     pub struct rtentry {
199         pub rt_pad1: ::c_ulong,
200         pub rt_dst: ::sockaddr,
201         pub rt_gateway: ::sockaddr,
202         pub rt_genmask: ::sockaddr,
203         pub rt_flags: ::c_ushort,
204         pub rt_pad2: ::c_short,
205         pub rt_pad3: ::c_ulong,
206         pub rt_tos: ::c_uchar,
207         pub rt_class: ::c_uchar,
208         #[cfg(target_pointer_width = "64")]
209         pub rt_pad4: [::c_short; 3usize],
210         #[cfg(not(target_pointer_width = "64"))]
211         pub rt_pad4: [::c_short; 1usize],
212         pub rt_metric: ::c_short,
213         pub rt_dev: *mut ::c_char,
214         pub rt_mtu: ::c_ulong,
215         pub rt_window: ::c_ulong,
216         pub rt_irtt: ::c_ushort,
217     }
218 
219     pub struct __exit_status {
220         pub e_termination: ::c_short,
221         pub e_exit: ::c_short,
222     }
223 
224     pub struct Elf64_Chdr {
225         pub ch_type: ::Elf64_Word,
226         pub ch_reserved: ::Elf64_Word,
227         pub ch_size: ::Elf64_Xword,
228         pub ch_addralign: ::Elf64_Xword,
229     }
230 
231     pub struct Elf32_Chdr {
232         pub ch_type: ::Elf32_Word,
233         pub ch_size: ::Elf32_Word,
234         pub ch_addralign: ::Elf32_Word,
235     }
236 
237     pub struct timex {
238         pub modes: ::c_uint,
239         pub offset: ::c_long,
240         pub freq: ::c_long,
241         pub maxerror: ::c_long,
242         pub esterror: ::c_long,
243         pub status: ::c_int,
244         pub constant: ::c_long,
245         pub precision: ::c_long,
246         pub tolerance: ::c_long,
247         pub time: ::timeval,
248         pub tick: ::c_long,
249         pub ppsfreq: ::c_long,
250         pub jitter: ::c_long,
251         pub shift: ::c_int,
252         pub stabil: ::c_long,
253         pub jitcnt: ::c_long,
254         pub calcnt: ::c_long,
255         pub errcnt: ::c_long,
256         pub stbcnt: ::c_long,
257         pub tai: ::c_int,
258         pub __padding: [::c_int; 11],
259     }
260 
261     pub struct ntptimeval {
262         pub time: ::timeval,
263         pub maxerror: ::c_long,
264         pub esterror: ::c_long,
265     }
266 }
267 
268 s_no_extra_traits! {
269     pub struct sysinfo {
270         pub uptime: ::c_ulong,
271         pub loads: [::c_ulong; 3],
272         pub totalram: ::c_ulong,
273         pub freeram: ::c_ulong,
274         pub sharedram: ::c_ulong,
275         pub bufferram: ::c_ulong,
276         pub totalswap: ::c_ulong,
277         pub freeswap: ::c_ulong,
278         pub procs: ::c_ushort,
279         pub pad: ::c_ushort,
280         pub totalhigh: ::c_ulong,
281         pub freehigh: ::c_ulong,
282         pub mem_unit: ::c_uint,
283         pub __reserved: [::c_char; 256],
284     }
285 
286     // FIXME: musl added paddings and adjusted
287     // layout in 1.2.0 but our CI is still 1.1.24.
288     // So, I'm leaving some fields as cfg for now.
289     // ref. https://github.com/bminor/musl/commit/
290     // 1e7f0fcd7ff2096904fd93a2ee6d12a2392be392
291     //
292     // OpenHarmony uses the musl 1.2 layout.
293     pub struct utmpx {
294         pub ut_type: ::c_short,
295         __ut_pad1: ::c_short,
296         pub ut_pid: ::pid_t,
297         pub ut_line: [::c_char; 32],
298         pub ut_id: [::c_char; 4],
299         pub ut_user: [::c_char; 32],
300         pub ut_host: [::c_char; 256],
301         pub ut_exit: __exit_status,
302 
303         #[cfg(target_env = "musl")]
304         pub ut_session: ::c_long,
305 
306         #[cfg(target_env = "ohos")]
307         #[cfg(target_endian = "little")]
308         pub ut_session: ::c_int,
309         #[cfg(target_env = "ohos")]
310         #[cfg(target_endian = "little")]
311         __ut_pad2: ::c_int,
312 
313         #[cfg(target_env = "ohos")]
314         #[cfg(not(target_endian = "little"))]
315         __ut_pad2: ::c_int,
316         #[cfg(target_env = "ohos")]
317         #[cfg(not(target_endian = "little"))]
318         pub ut_session: ::c_int,
319 
320         pub ut_tv: ::timeval,
321         pub ut_addr_v6: [::c_uint; 4],
322         __unused: [::c_char; 20],
323     }
324 }
325 
326 cfg_if! {
327     if #[cfg(feature = "extra_traits")] {
328         impl PartialEq for sysinfo {
329             fn eq(&self, other: &sysinfo) -> bool {
330                 self.uptime == other.uptime
331                     && self.loads == other.loads
332                     && self.totalram == other.totalram
333                     && self.freeram == other.freeram
334                     && self.sharedram == other.sharedram
335                     && self.bufferram == other.bufferram
336                     && self.totalswap == other.totalswap
337                     && self.freeswap == other.freeswap
338                     && self.procs == other.procs
339                     && self.pad == other.pad
340                     && self.totalhigh == other.totalhigh
341                     && self.freehigh == other.freehigh
342                     && self.mem_unit == other.mem_unit
343                     && self
344                         .__reserved
345                         .iter()
346                         .zip(other.__reserved.iter())
347                         .all(|(a,b)| a == b)
348             }
349         }
350 
351         impl Eq for sysinfo {}
352 
353         impl ::fmt::Debug for sysinfo {
354             fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
355                 f.debug_struct("sysinfo")
356                     .field("uptime", &self.uptime)
357                     .field("loads", &self.loads)
358                     .field("totalram", &self.totalram)
359                     .field("freeram", &self.freeram)
360                     .field("sharedram", &self.sharedram)
361                     .field("bufferram", &self.bufferram)
362                     .field("totalswap", &self.totalswap)
363                     .field("freeswap", &self.freeswap)
364                     .field("procs", &self.procs)
365                     .field("pad", &self.pad)
366                     .field("totalhigh", &self.totalhigh)
367                     .field("freehigh", &self.freehigh)
368                     .field("mem_unit", &self.mem_unit)
369                     // FIXME: .field("__reserved", &self.__reserved)
370                     .finish()
371             }
372         }
373 
374         impl ::hash::Hash for sysinfo {
375             fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
376                 self.uptime.hash(state);
377                 self.loads.hash(state);
378                 self.totalram.hash(state);
379                 self.freeram.hash(state);
380                 self.sharedram.hash(state);
381                 self.bufferram.hash(state);
382                 self.totalswap.hash(state);
383                 self.freeswap.hash(state);
384                 self.procs.hash(state);
385                 self.pad.hash(state);
386                 self.totalhigh.hash(state);
387                 self.freehigh.hash(state);
388                 self.mem_unit.hash(state);
389                 self.__reserved.hash(state);
390             }
391         }
392 
393         impl PartialEq for utmpx {
394             fn eq(&self, other: &utmpx) -> bool {
395                 self.ut_type == other.ut_type
396                     //&& self.__ut_pad1 == other.__ut_pad1
397                     && self.ut_pid == other.ut_pid
398                     && self.ut_line == other.ut_line
399                     && self.ut_id == other.ut_id
400                     && self.ut_user == other.ut_user
401                     && self
402                         .ut_host
403                         .iter()
404                         .zip(other.ut_host.iter())
405                         .all(|(a,b)| a == b)
406                     && self.ut_exit == other.ut_exit
407                     && self.ut_session == other.ut_session
408                     //&& self.__ut_pad2 == other.__ut_pad2
409                     && self.ut_tv == other.ut_tv
410                     && self.ut_addr_v6 == other.ut_addr_v6
411                     && self.__unused == other.__unused
412             }
413         }
414 
415         impl Eq for utmpx {}
416 
417         impl ::fmt::Debug for utmpx {
418             fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
419                 f.debug_struct("utmpx")
420                     .field("ut_type", &self.ut_type)
421                     //.field("__ut_pad1", &self.__ut_pad1)
422                     .field("ut_pid", &self.ut_pid)
423                     .field("ut_line", &self.ut_line)
424                     .field("ut_id", &self.ut_id)
425                     .field("ut_user", &self.ut_user)
426                     //FIXME: .field("ut_host", &self.ut_host)
427                     .field("ut_exit", &self.ut_exit)
428                     .field("ut_session", &self.ut_session)
429                     //.field("__ut_pad2", &self.__ut_pad2)
430                     .field("ut_tv", &self.ut_tv)
431                     .field("ut_addr_v6", &self.ut_addr_v6)
432                     .field("__unused", &self.__unused)
433                     .finish()
434             }
435         }
436 
437         impl ::hash::Hash for utmpx {
438             fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
439                 self.ut_type.hash(state);
440                 //self.__ut_pad1.hash(state);
441                 self.ut_pid.hash(state);
442                 self.ut_line.hash(state);
443                 self.ut_id.hash(state);
444                 self.ut_user.hash(state);
445                 self.ut_host.hash(state);
446                 self.ut_exit.hash(state);
447                 self.ut_session.hash(state);
448                 //self.__ut_pad2.hash(state);
449                 self.ut_tv.hash(state);
450                 self.ut_addr_v6.hash(state);
451                 self.__unused.hash(state);
452             }
453         }
454     }
455 }
456 
457 // include/sys/mman.h
458 /*
459  * Huge page size encoding when MAP_HUGETLB is specified, and a huge page
460  * size other than the default is desired.  See hugetlb_encode.h.
461  * All known huge page size encodings are provided here.  It is the
462  * responsibility of the application to know which sizes are supported on
463  * the running system.  See mmap(2) man page for details.
464  */
465 pub const MAP_HUGE_SHIFT: ::c_int = 26;
466 pub const MAP_HUGE_MASK: ::c_int = 0x3f;
467 
468 pub const MAP_HUGE_64KB: ::c_int = 16 << MAP_HUGE_SHIFT;
469 pub const MAP_HUGE_512KB: ::c_int = 19 << MAP_HUGE_SHIFT;
470 pub const MAP_HUGE_1MB: ::c_int = 20 << MAP_HUGE_SHIFT;
471 pub const MAP_HUGE_2MB: ::c_int = 21 << MAP_HUGE_SHIFT;
472 pub const MAP_HUGE_8MB: ::c_int = 23 << MAP_HUGE_SHIFT;
473 pub const MAP_HUGE_16MB: ::c_int = 24 << MAP_HUGE_SHIFT;
474 pub const MAP_HUGE_32MB: ::c_int = 25 << MAP_HUGE_SHIFT;
475 pub const MAP_HUGE_256MB: ::c_int = 28 << MAP_HUGE_SHIFT;
476 pub const MAP_HUGE_512MB: ::c_int = 29 << MAP_HUGE_SHIFT;
477 pub const MAP_HUGE_1GB: ::c_int = 30 << MAP_HUGE_SHIFT;
478 pub const MAP_HUGE_2GB: ::c_int = 31 << MAP_HUGE_SHIFT;
479 pub const MAP_HUGE_16GB: ::c_int = 34 << MAP_HUGE_SHIFT;
480 
481 pub const MS_RMT_MASK: ::c_ulong = 0x02800051;
482 
483 pub const SFD_CLOEXEC: ::c_int = 0x080000;
484 
485 pub const NCCS: usize = 32;
486 
487 pub const O_TRUNC: ::c_int = 512;
488 pub const O_NOATIME: ::c_int = 0o1000000;
489 pub const O_CLOEXEC: ::c_int = 0x80000;
490 pub const O_TMPFILE: ::c_int = 0o20000000 | O_DIRECTORY;
491 
492 pub const EBFONT: ::c_int = 59;
493 pub const ENOSTR: ::c_int = 60;
494 pub const ENODATA: ::c_int = 61;
495 pub const ETIME: ::c_int = 62;
496 pub const ENOSR: ::c_int = 63;
497 pub const ENONET: ::c_int = 64;
498 pub const ENOPKG: ::c_int = 65;
499 pub const EREMOTE: ::c_int = 66;
500 pub const ENOLINK: ::c_int = 67;
501 pub const EADV: ::c_int = 68;
502 pub const ESRMNT: ::c_int = 69;
503 pub const ECOMM: ::c_int = 70;
504 pub const EPROTO: ::c_int = 71;
505 pub const EDOTDOT: ::c_int = 73;
506 
507 pub const F_RDLCK: ::c_int = 0;
508 pub const F_WRLCK: ::c_int = 1;
509 pub const F_UNLCK: ::c_int = 2;
510 
511 pub const SA_NODEFER: ::c_int = 0x40000000;
512 pub const SA_RESETHAND: ::c_int = 0x80000000;
513 pub const SA_RESTART: ::c_int = 0x10000000;
514 pub const SA_NOCLDSTOP: ::c_int = 0x00000001;
515 
516 pub const EPOLL_CLOEXEC: ::c_int = 0x80000;
517 
518 pub const EFD_CLOEXEC: ::c_int = 0x80000;
519 
520 pub const BUFSIZ: ::c_uint = 1024;
521 pub const TMP_MAX: ::c_uint = 10000;
522 pub const FOPEN_MAX: ::c_uint = 1000;
523 pub const FILENAME_MAX: ::c_uint = 4096;
524 pub const O_PATH: ::c_int = 0o10000000;
525 pub const O_EXEC: ::c_int = 0o10000000;
526 pub const O_SEARCH: ::c_int = 0o10000000;
527 pub const O_ACCMODE: ::c_int = 0o10000003;
528 pub const O_NDELAY: ::c_int = O_NONBLOCK;
529 pub const NI_MAXHOST: ::socklen_t = 255;
530 pub const PTHREAD_STACK_MIN: ::size_t = 2048;
531 
532 pub const POSIX_MADV_DONTNEED: ::c_int = 4;
533 
534 pub const MAP_ANONYMOUS: ::c_int = MAP_ANON;
535 
536 pub const SOCK_DCCP: ::c_int = 6;
537 pub const SOCK_PACKET: ::c_int = 10;
538 
539 pub const SOMAXCONN: ::c_int = 128;
540 
541 #[deprecated(since = "0.2.55", note = "Use SIGSYS instead")]
542 pub const SIGUNUSED: ::c_int = ::SIGSYS;
543 
544 pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
545 pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
546 pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
547 pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;
548 
549 pub const CPU_SETSIZE: ::c_int = 128;
550 
551 pub const PTRACE_TRACEME: ::c_int = 0;
552 pub const PTRACE_PEEKTEXT: ::c_int = 1;
553 pub const PTRACE_PEEKDATA: ::c_int = 2;
554 pub const PTRACE_PEEKUSER: ::c_int = 3;
555 pub const PTRACE_POKETEXT: ::c_int = 4;
556 pub const PTRACE_POKEDATA: ::c_int = 5;
557 pub const PTRACE_POKEUSER: ::c_int = 6;
558 pub const PTRACE_CONT: ::c_int = 7;
559 pub const PTRACE_KILL: ::c_int = 8;
560 pub const PTRACE_SINGLESTEP: ::c_int = 9;
561 pub const PTRACE_GETREGS: ::c_int = 12;
562 pub const PTRACE_SETREGS: ::c_int = 13;
563 pub const PTRACE_GETFPREGS: ::c_int = 14;
564 pub const PTRACE_SETFPREGS: ::c_int = 15;
565 pub const PTRACE_ATTACH: ::c_int = 16;
566 pub const PTRACE_DETACH: ::c_int = 17;
567 pub const PTRACE_GETFPXREGS: ::c_int = 18;
568 pub const PTRACE_SETFPXREGS: ::c_int = 19;
569 pub const PTRACE_SYSCALL: ::c_int = 24;
570 pub const PTRACE_SETOPTIONS: ::c_int = 0x4200;
571 pub const PTRACE_GETEVENTMSG: ::c_int = 0x4201;
572 pub const PTRACE_GETSIGINFO: ::c_int = 0x4202;
573 pub const PTRACE_SETSIGINFO: ::c_int = 0x4203;
574 pub const PTRACE_GETREGSET: ::c_int = 0x4204;
575 pub const PTRACE_SETREGSET: ::c_int = 0x4205;
576 pub const PTRACE_SEIZE: ::c_int = 0x4206;
577 pub const PTRACE_INTERRUPT: ::c_int = 0x4207;
578 pub const PTRACE_LISTEN: ::c_int = 0x4208;
579 pub const PTRACE_PEEKSIGINFO: ::c_int = 0x4209;
580 
581 pub const FAN_MARK_INODE: ::c_uint = 0x0000_0000;
582 pub const FAN_MARK_MOUNT: ::c_uint = 0x0000_0010;
583 // NOTE: FAN_MARK_FILESYSTEM requires Linux Kernel >= 4.20.0
584 pub const FAN_MARK_FILESYSTEM: ::c_uint = 0x0000_0100;
585 
586 pub const AF_IB: ::c_int = 27;
587 pub const AF_MPLS: ::c_int = 28;
588 pub const AF_NFC: ::c_int = 39;
589 pub const AF_VSOCK: ::c_int = 40;
590 pub const AF_XDP: ::c_int = 44;
591 pub const PF_IB: ::c_int = AF_IB;
592 pub const PF_MPLS: ::c_int = AF_MPLS;
593 pub const PF_NFC: ::c_int = AF_NFC;
594 pub const PF_VSOCK: ::c_int = AF_VSOCK;
595 pub const PF_XDP: ::c_int = AF_XDP;
596 
597 pub const EFD_NONBLOCK: ::c_int = ::O_NONBLOCK;
598 
599 pub const SFD_NONBLOCK: ::c_int = ::O_NONBLOCK;
600 
601 pub const PIDFD_NONBLOCK: ::c_uint = O_NONBLOCK as ::c_uint;
602 
603 pub const TCSANOW: ::c_int = 0;
604 pub const TCSADRAIN: ::c_int = 1;
605 pub const TCSAFLUSH: ::c_int = 2;
606 
607 pub const RTLD_GLOBAL: ::c_int = 0x100;
608 pub const RTLD_NOLOAD: ::c_int = 0x4;
609 
610 pub const CLOCK_SGI_CYCLE: ::clockid_t = 10;
611 
612 pub const B0: ::speed_t = 0o000000;
613 pub const B50: ::speed_t = 0o000001;
614 pub const B75: ::speed_t = 0o000002;
615 pub const B110: ::speed_t = 0o000003;
616 pub const B134: ::speed_t = 0o000004;
617 pub const B150: ::speed_t = 0o000005;
618 pub const B200: ::speed_t = 0o000006;
619 pub const B300: ::speed_t = 0o000007;
620 pub const B600: ::speed_t = 0o000010;
621 pub const B1200: ::speed_t = 0o000011;
622 pub const B1800: ::speed_t = 0o000012;
623 pub const B2400: ::speed_t = 0o000013;
624 pub const B4800: ::speed_t = 0o000014;
625 pub const B9600: ::speed_t = 0o000015;
626 pub const B19200: ::speed_t = 0o000016;
627 pub const B38400: ::speed_t = 0o000017;
628 pub const EXTA: ::speed_t = B19200;
629 pub const EXTB: ::speed_t = B38400;
630 
631 pub const REG_OK: ::c_int = 0;
632 
633 pub const PRIO_PROCESS: ::c_int = 0;
634 pub const PRIO_PGRP: ::c_int = 1;
635 pub const PRIO_USER: ::c_int = 2;
636 
637 pub const ADJ_OFFSET: ::c_uint = 0x0001;
638 pub const ADJ_FREQUENCY: ::c_uint = 0x0002;
639 pub const ADJ_MAXERROR: ::c_uint = 0x0004;
640 pub const ADJ_ESTERROR: ::c_uint = 0x0008;
641 pub const ADJ_STATUS: ::c_uint = 0x0010;
642 pub const ADJ_TIMECONST: ::c_uint = 0x0020;
643 pub const ADJ_TAI: ::c_uint = 0x0080;
644 pub const ADJ_SETOFFSET: ::c_uint = 0x0100;
645 pub const ADJ_MICRO: ::c_uint = 0x1000;
646 pub const ADJ_NANO: ::c_uint = 0x2000;
647 pub const ADJ_TICK: ::c_uint = 0x4000;
648 pub const ADJ_OFFSET_SINGLESHOT: ::c_uint = 0x8001;
649 pub const ADJ_OFFSET_SS_READ: ::c_uint = 0xa001;
650 pub const MOD_OFFSET: ::c_uint = ADJ_OFFSET;
651 pub const MOD_FREQUENCY: ::c_uint = ADJ_FREQUENCY;
652 pub const MOD_MAXERROR: ::c_uint = ADJ_MAXERROR;
653 pub const MOD_ESTERROR: ::c_uint = ADJ_ESTERROR;
654 pub const MOD_STATUS: ::c_uint = ADJ_STATUS;
655 pub const MOD_TIMECONST: ::c_uint = ADJ_TIMECONST;
656 pub const MOD_CLKB: ::c_uint = ADJ_TICK;
657 pub const MOD_CLKA: ::c_uint = ADJ_OFFSET_SINGLESHOT;
658 pub const MOD_TAI: ::c_uint = ADJ_TAI;
659 pub const MOD_MICRO: ::c_uint = ADJ_MICRO;
660 pub const MOD_NANO: ::c_uint = ADJ_NANO;
661 pub const STA_PLL: ::c_int = 0x0001;
662 pub const STA_PPSFREQ: ::c_int = 0x0002;
663 pub const STA_PPSTIME: ::c_int = 0x0004;
664 pub const STA_FLL: ::c_int = 0x0008;
665 pub const STA_INS: ::c_int = 0x0010;
666 pub const STA_DEL: ::c_int = 0x0020;
667 pub const STA_UNSYNC: ::c_int = 0x0040;
668 pub const STA_FREQHOLD: ::c_int = 0x0080;
669 pub const STA_PPSSIGNAL: ::c_int = 0x0100;
670 pub const STA_PPSJITTER: ::c_int = 0x0200;
671 pub const STA_PPSWANDER: ::c_int = 0x0400;
672 pub const STA_PPSERROR: ::c_int = 0x0800;
673 pub const STA_CLOCKERR: ::c_int = 0x1000;
674 pub const STA_NANO: ::c_int = 0x2000;
675 pub const STA_MODE: ::c_int = 0x4000;
676 pub const STA_CLK: ::c_int = 0x8000;
677 pub const STA_RONLY: ::c_int = STA_PPSSIGNAL
678     | STA_PPSJITTER
679     | STA_PPSWANDER
680     | STA_PPSERROR
681     | STA_CLOCKERR
682     | STA_NANO
683     | STA_MODE
684     | STA_CLK;
685 
686 pub const TIME_OK: ::c_int = 0;
687 pub const TIME_INS: ::c_int = 1;
688 pub const TIME_DEL: ::c_int = 2;
689 pub const TIME_OOP: ::c_int = 3;
690 pub const TIME_WAIT: ::c_int = 4;
691 pub const TIME_ERROR: ::c_int = 5;
692 pub const TIME_BAD: ::c_int = TIME_ERROR;
693 pub const MAXTC: ::c_long = 6;
694 
695 cfg_if! {
696     if #[cfg(target_arch = "s390x")] {
697         pub const POSIX_FADV_DONTNEED: ::c_int = 6;
698         pub const POSIX_FADV_NOREUSE: ::c_int = 7;
699     } else {
700         pub const POSIX_FADV_DONTNEED: ::c_int = 4;
701         pub const POSIX_FADV_NOREUSE: ::c_int = 5;
702     }
703 }
704 
705 extern "C" {
706     pub fn sendmmsg(
707         sockfd: ::c_int,
708         msgvec: *mut ::mmsghdr,
709         vlen: ::c_uint,
710         flags: ::c_uint,
711     ) -> ::c_int;
712     pub fn recvmmsg(
713         sockfd: ::c_int,
714         msgvec: *mut ::mmsghdr,
715         vlen: ::c_uint,
716         flags: ::c_uint,
717         timeout: *mut ::timespec,
718     ) -> ::c_int;
719 
720     pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int;
721     pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int;
722     pub fn prlimit(
723         pid: ::pid_t,
724         resource: ::c_int,
725         new_limit: *const ::rlimit,
726         old_limit: *mut ::rlimit,
727     ) -> ::c_int;
728     pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int;
729     //pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int;
730     pub fn ptrace(request: ::c_int, ...) -> ::c_long;
731     pub fn getpriority(which: ::c_int, who: ::id_t) -> ::c_int;
732     pub fn setpriority(which: ::c_int, who: ::id_t, prio: ::c_int) -> ::c_int;
733     // Musl targets need the `mask` argument of `fanotify_mark` be specified
734     // `::c_ulonglong` instead of `u64` or there will be a type mismatch between
735     // `long long unsigned int` and the expected `uint64_t`.
736     pub fn fanotify_mark(
737         fd: ::c_int,
738         flags: ::c_uint,
739         mask: ::c_ulonglong,
740         dirfd: ::c_int,
741         path: *const ::c_char,
742     ) -> ::c_int;
743     pub fn getauxval(type_: ::c_ulong) -> ::c_ulong;
744 
745     // Added in `musl` 1.1.20
746     pub fn explicit_bzero(s: *mut ::c_void, len: ::size_t);
747     // Added in `musl` 1.2.2
748     pub fn reallocarray(ptr: *mut ::c_void, nmemb: ::size_t, size: ::size_t) -> *mut ::c_void;
749 
750     pub fn adjtimex(buf: *mut ::timex) -> ::c_int;
751     pub fn clock_adjtime(clk_id: ::clockid_t, buf: *mut ::timex) -> ::c_int;
752 
753     pub fn ctermid(s: *mut ::c_char) -> *mut ::c_char;
754 
755     pub fn memfd_create(name: *const ::c_char, flags: ::c_uint) -> ::c_int;
756     pub fn mlock2(addr: *const ::c_void, len: ::size_t, flags: ::c_uint) -> ::c_int;
757     pub fn malloc_usable_size(ptr: *mut ::c_void) -> ::size_t;
758 
759     pub fn euidaccess(pathname: *const ::c_char, mode: ::c_int) -> ::c_int;
760     pub fn eaccess(pathname: *const ::c_char, mode: ::c_int) -> ::c_int;
761 
762     pub fn asctime_r(tm: *const ::tm, buf: *mut ::c_char) -> *mut ::c_char;
763 
764     pub fn strftime(
765         s: *mut ::c_char,
766         max: ::size_t,
767         format: *const ::c_char,
768         tm: *const ::tm,
769     ) -> ::size_t;
770     pub fn strptime(s: *const ::c_char, format: *const ::c_char, tm: *mut ::tm) -> *mut ::c_char;
771 
772     pub fn dirname(path: *mut ::c_char) -> *mut ::c_char;
773     pub fn basename(path: *mut ::c_char) -> *mut ::c_char;
774 }
775 
776 // Alias <foo> to <foo>64 to mimic glibc's LFS64 support
777 mod lfs64;
778 pub use self::lfs64::*;
779 
780 cfg_if! {
781     if #[cfg(any(target_arch = "x86_64",
782                  target_arch = "aarch64",
783                  target_arch = "mips64",
784                  target_arch = "powerpc64",
785                  target_arch = "s390x",
786                  target_arch = "riscv64"))] {
787         mod b64;
788         pub use self::b64::*;
789     } else if #[cfg(any(target_arch = "x86",
790                         target_arch = "mips",
791                         target_arch = "powerpc",
792                         target_arch = "hexagon",
793                         target_arch = "riscv32",
794                         target_arch = "arm"))] {
795         mod b32;
796         pub use self::b32::*;
797     } else { }
798 }
799