libc/unix/linux_like/linux/musl/
mod.rs

1use crate::off64_t;
2use crate::prelude::*;
3
4pub type pthread_t = *mut c_void;
5pub type clock_t = c_long;
6#[cfg_attr(
7    not(feature = "rustc-dep-of-std"),
8    deprecated(
9        since = "0.2.80",
10        note = "This type is changed to 64-bit in musl 1.2.0, \
11                we'll follow that change in the future release. \
12                See #1848 for more info."
13    )
14)]
15pub type time_t = c_long;
16pub type suseconds_t = c_long;
17pub type ino_t = u64;
18pub type off_t = i64;
19pub type blkcnt_t = i64;
20
21pub type shmatt_t = c_ulong;
22pub type msgqnum_t = c_ulong;
23pub type msglen_t = c_ulong;
24pub type fsblkcnt_t = c_ulonglong;
25pub type fsblkcnt64_t = c_ulonglong;
26pub type fsfilcnt_t = c_ulonglong;
27pub type fsfilcnt64_t = c_ulonglong;
28pub type rlim_t = c_ulonglong;
29
30cfg_if! {
31    if #[cfg(doc)] {
32        // Used in `linux::arch` to define ioctl constants.
33        pub(crate) type Ioctl = c_int;
34    } else {
35        #[doc(hidden)]
36        pub type Ioctl = c_int;
37    }
38}
39
40impl siginfo_t {
41    pub unsafe fn si_addr(&self) -> *mut c_void {
42        #[repr(C)]
43        struct siginfo_sigfault {
44            _si_signo: c_int,
45            _si_errno: c_int,
46            _si_code: c_int,
47            si_addr: *mut c_void,
48        }
49        (*(self as *const siginfo_t as *const siginfo_sigfault)).si_addr
50    }
51
52    pub unsafe fn si_value(&self) -> crate::sigval {
53        #[repr(C)]
54        struct siginfo_si_value {
55            _si_signo: c_int,
56            _si_errno: c_int,
57            _si_code: c_int,
58            _si_timerid: c_int,
59            _si_overrun: c_int,
60            si_value: crate::sigval,
61        }
62        (*(self as *const siginfo_t as *const siginfo_si_value)).si_value
63    }
64}
65
66// Internal, for casts to access union fields
67#[repr(C)]
68struct sifields_sigchld {
69    si_pid: crate::pid_t,
70    si_uid: crate::uid_t,
71    si_status: c_int,
72    si_utime: c_long,
73    si_stime: c_long,
74}
75impl Copy for sifields_sigchld {}
76impl Clone for sifields_sigchld {
77    fn clone(&self) -> sifields_sigchld {
78        *self
79    }
80}
81
82// Internal, for casts to access union fields
83#[repr(C)]
84union sifields {
85    _align_pointer: *mut c_void,
86    sigchld: sifields_sigchld,
87}
88
89// Internal, for casts to access union fields. Note that some variants
90// of sifields start with a pointer, which makes the alignment of
91// sifields vary on 32-bit and 64-bit architectures.
92#[repr(C)]
93struct siginfo_f {
94    _siginfo_base: [c_int; 3],
95    sifields: sifields,
96}
97
98impl siginfo_t {
99    unsafe fn sifields(&self) -> &sifields {
100        &(*(self as *const siginfo_t as *const siginfo_f)).sifields
101    }
102
103    pub unsafe fn si_pid(&self) -> crate::pid_t {
104        self.sifields().sigchld.si_pid
105    }
106
107    pub unsafe fn si_uid(&self) -> crate::uid_t {
108        self.sifields().sigchld.si_uid
109    }
110
111    pub unsafe fn si_status(&self) -> c_int {
112        self.sifields().sigchld.si_status
113    }
114
115    pub unsafe fn si_utime(&self) -> c_long {
116        self.sifields().sigchld.si_utime
117    }
118
119    pub unsafe fn si_stime(&self) -> c_long {
120        self.sifields().sigchld.si_stime
121    }
122}
123
124s! {
125    pub struct aiocb {
126        pub aio_fildes: c_int,
127        pub aio_lio_opcode: c_int,
128        pub aio_reqprio: c_int,
129        pub aio_buf: *mut c_void,
130        pub aio_nbytes: size_t,
131        pub aio_sigevent: crate::sigevent,
132        __td: *mut c_void,
133        __lock: [c_int; 2],
134        __err: c_int,
135        __ret: ssize_t,
136        pub aio_offset: off_t,
137        __next: *mut c_void,
138        __prev: *mut c_void,
139        __dummy4: [c_char; 32 - 2 * size_of::<*const ()>()],
140    }
141
142    #[repr(align(8))]
143    pub struct fanotify_event_metadata {
144        pub event_len: c_uint,
145        pub vers: c_uchar,
146        pub reserved: c_uchar,
147        pub metadata_len: c_ushort,
148        pub mask: c_ulonglong,
149        pub fd: c_int,
150        pub pid: c_int,
151    }
152
153    // FIXME(1.0): This should not implement `PartialEq`
154    #[allow(unpredictable_function_pointer_comparisons)]
155    pub struct sigaction {
156        pub sa_sigaction: crate::sighandler_t,
157        pub sa_mask: crate::sigset_t,
158        pub sa_flags: c_int,
159        pub sa_restorer: Option<extern "C" fn()>,
160    }
161
162    // `mips*` targets swap the `s_errno` and `s_code` fields otherwise this struct is
163    // target-agnostic (see https://www.openwall.com/lists/musl/2016/01/27/1/2)
164    //
165    // FIXME(union): C implementation uses unions
166    pub struct siginfo_t {
167        pub si_signo: c_int,
168        #[cfg(not(any(target_arch = "mips", target_arch = "mips64")))]
169        pub si_errno: c_int,
170        pub si_code: c_int,
171        #[cfg(any(target_arch = "mips", target_arch = "mips64"))]
172        pub si_errno: c_int,
173        #[doc(hidden)]
174        #[deprecated(
175            since = "0.2.54",
176            note = "Please leave a comment on https://github.com/rust-lang/libc/pull/1316 \
177                  if you're using this field"
178        )]
179        pub _pad: [c_int; 29],
180        _align: [usize; 0],
181    }
182
183    pub struct statvfs {
184        pub f_bsize: c_ulong,
185        pub f_frsize: c_ulong,
186        pub f_blocks: crate::fsblkcnt_t,
187        pub f_bfree: crate::fsblkcnt_t,
188        pub f_bavail: crate::fsblkcnt_t,
189        pub f_files: crate::fsfilcnt_t,
190        pub f_ffree: crate::fsfilcnt_t,
191        pub f_favail: crate::fsfilcnt_t,
192        #[cfg(target_endian = "little")]
193        pub f_fsid: c_ulong,
194        #[cfg(target_pointer_width = "32")]
195        __pad: c_int,
196        #[cfg(target_endian = "big")]
197        pub f_fsid: c_ulong,
198        pub f_flag: c_ulong,
199        pub f_namemax: c_ulong,
200        __f_reserved: [c_int; 6],
201    }
202
203    pub struct statvfs64 {
204        pub f_bsize: c_ulong,
205        pub f_frsize: c_ulong,
206        pub f_blocks: crate::fsblkcnt64_t,
207        pub f_bfree: crate::fsblkcnt64_t,
208        pub f_bavail: crate::fsblkcnt64_t,
209        pub f_files: crate::fsfilcnt64_t,
210        pub f_ffree: crate::fsfilcnt64_t,
211        pub f_favail: crate::fsfilcnt64_t,
212        #[cfg(target_endian = "little")]
213        pub f_fsid: c_ulong,
214        #[cfg(target_pointer_width = "32")]
215        __pad: c_int,
216        #[cfg(target_endian = "big")]
217        pub f_fsid: c_ulong,
218        pub f_flag: c_ulong,
219        pub f_namemax: c_ulong,
220        __f_reserved: [c_int; 6],
221    }
222
223    // PowerPC implementations are special, see the subfolders
224    #[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
225    pub struct termios {
226        pub c_iflag: crate::tcflag_t,
227        pub c_oflag: crate::tcflag_t,
228        pub c_cflag: crate::tcflag_t,
229        pub c_lflag: crate::tcflag_t,
230        pub c_line: crate::cc_t,
231        pub c_cc: [crate::cc_t; crate::NCCS],
232        pub __c_ispeed: crate::speed_t,
233        pub __c_ospeed: crate::speed_t,
234    }
235
236    pub struct flock {
237        pub l_type: c_short,
238        pub l_whence: c_short,
239        pub l_start: off_t,
240        pub l_len: off_t,
241        pub l_pid: crate::pid_t,
242    }
243
244    pub struct flock64 {
245        pub l_type: c_short,
246        pub l_whence: c_short,
247        pub l_start: off64_t,
248        pub l_len: off64_t,
249        pub l_pid: crate::pid_t,
250    }
251
252    pub struct regex_t {
253        __re_nsub: size_t,
254        __opaque: *mut c_void,
255        __padding: [*mut c_void; 4usize],
256        __nsub2: size_t,
257        __padding2: c_char,
258    }
259
260    pub struct rtentry {
261        pub rt_pad1: c_ulong,
262        pub rt_dst: crate::sockaddr,
263        pub rt_gateway: crate::sockaddr,
264        pub rt_genmask: crate::sockaddr,
265        pub rt_flags: c_ushort,
266        pub rt_pad2: c_short,
267        pub rt_pad3: c_ulong,
268        pub rt_tos: c_uchar,
269        pub rt_class: c_uchar,
270        #[cfg(target_pointer_width = "64")]
271        pub rt_pad4: [c_short; 3usize],
272        #[cfg(not(target_pointer_width = "64"))]
273        pub rt_pad4: [c_short; 1usize],
274        pub rt_metric: c_short,
275        pub rt_dev: *mut c_char,
276        pub rt_mtu: c_ulong,
277        pub rt_window: c_ulong,
278        pub rt_irtt: c_ushort,
279    }
280
281    pub struct __exit_status {
282        pub e_termination: c_short,
283        pub e_exit: c_short,
284    }
285
286    pub struct Elf64_Chdr {
287        pub ch_type: crate::Elf64_Word,
288        pub ch_reserved: crate::Elf64_Word,
289        pub ch_size: crate::Elf64_Xword,
290        pub ch_addralign: crate::Elf64_Xword,
291    }
292
293    pub struct Elf32_Chdr {
294        pub ch_type: crate::Elf32_Word,
295        pub ch_size: crate::Elf32_Word,
296        pub ch_addralign: crate::Elf32_Word,
297    }
298
299    pub struct timex {
300        pub modes: c_uint,
301        pub offset: c_long,
302        pub freq: c_long,
303        pub maxerror: c_long,
304        pub esterror: c_long,
305        pub status: c_int,
306        pub constant: c_long,
307        pub precision: c_long,
308        pub tolerance: c_long,
309        pub time: crate::timeval,
310        pub tick: c_long,
311        pub ppsfreq: c_long,
312        pub jitter: c_long,
313        pub shift: c_int,
314        pub stabil: c_long,
315        pub jitcnt: c_long,
316        pub calcnt: c_long,
317        pub errcnt: c_long,
318        pub stbcnt: c_long,
319        pub tai: c_int,
320        pub __padding: [c_int; 11],
321    }
322
323    pub struct ntptimeval {
324        pub time: crate::timeval,
325        pub maxerror: c_long,
326        pub esterror: c_long,
327    }
328
329    // netinet/tcp.h
330
331    pub struct tcp_info {
332        pub tcpi_state: u8,
333        pub tcpi_ca_state: u8,
334        pub tcpi_retransmits: u8,
335        pub tcpi_probes: u8,
336        pub tcpi_backoff: u8,
337        pub tcpi_options: u8,
338        /// This contains the bitfields `tcpi_snd_wscale` and `tcpi_rcv_wscale`.
339        /// Each is 4 bits.
340        pub tcpi_snd_rcv_wscale: u8,
341        /// This contains the bitfields `tcpi_delivery_rate_app_limited` (1 bit) and
342        /// `tcpi_fastopen_client_fail` (2 bits).
343        pub tcpi_delivery_fastopen_bitfields: u8,
344        pub tcpi_rto: u32,
345        pub tcpi_ato: u32,
346        pub tcpi_snd_mss: u32,
347        pub tcpi_rcv_mss: u32,
348        pub tcpi_unacked: u32,
349        pub tcpi_sacked: u32,
350        pub tcpi_lost: u32,
351        pub tcpi_retrans: u32,
352        pub tcpi_fackets: u32,
353        pub tcpi_last_data_sent: u32,
354        pub tcpi_last_ack_sent: u32,
355        pub tcpi_last_data_recv: u32,
356        pub tcpi_last_ack_recv: u32,
357        pub tcpi_pmtu: u32,
358        pub tcpi_rcv_ssthresh: u32,
359        pub tcpi_rtt: u32,
360        pub tcpi_rttvar: u32,
361        pub tcpi_snd_ssthresh: u32,
362        pub tcpi_snd_cwnd: u32,
363        pub tcpi_advmss: u32,
364        pub tcpi_reordering: u32,
365        pub tcpi_rcv_rtt: u32,
366        pub tcpi_rcv_space: u32,
367        pub tcpi_total_retrans: u32,
368        pub tcpi_pacing_rate: u64,
369        pub tcpi_max_pacing_rate: u64,
370        pub tcpi_bytes_acked: u64,
371        pub tcpi_bytes_received: u64,
372        pub tcpi_segs_out: u32,
373        pub tcpi_segs_in: u32,
374        pub tcpi_notsent_bytes: u32,
375        pub tcpi_min_rtt: u32,
376        pub tcpi_data_segs_in: u32,
377        pub tcpi_data_segs_out: u32,
378        pub tcpi_delivery_rate: u64,
379        pub tcpi_busy_time: u64,
380        pub tcpi_rwnd_limited: u64,
381        pub tcpi_sndbuf_limited: u64,
382        pub tcpi_delivered: u32,
383        pub tcpi_delivered_ce: u32,
384        pub tcpi_bytes_sent: u64,
385        pub tcpi_bytes_retrans: u64,
386        pub tcpi_dsack_dups: u32,
387        pub tcpi_reord_seen: u32,
388        pub tcpi_rcv_ooopack: u32,
389        pub tcpi_snd_wnd: u32,
390    }
391
392    // MIPS/s390x implementation is special (see arch folders)
393    #[cfg(not(any(target_arch = "mips", target_arch = "mips64", target_arch = "s390x")))]
394    pub struct statfs {
395        pub f_type: c_ulong,
396        pub f_bsize: c_ulong,
397        pub f_blocks: crate::fsblkcnt_t,
398        pub f_bfree: crate::fsblkcnt_t,
399        pub f_bavail: crate::fsblkcnt_t,
400        pub f_files: crate::fsfilcnt_t,
401        pub f_ffree: crate::fsfilcnt_t,
402        pub f_fsid: crate::fsid_t,
403        pub f_namelen: c_ulong,
404        pub f_frsize: c_ulong,
405        pub f_flags: c_ulong,
406        pub f_spare: [c_ulong; 4],
407    }
408
409    // MIPS/s390x implementation is special (see arch folders)
410    #[cfg(not(any(target_arch = "mips", target_arch = "mips64", target_arch = "s390x")))]
411    pub struct statfs64 {
412        pub f_type: c_ulong,
413        pub f_bsize: c_ulong,
414        pub f_blocks: crate::fsblkcnt64_t,
415        pub f_bfree: crate::fsblkcnt64_t,
416        pub f_bavail: crate::fsblkcnt64_t,
417        pub f_files: crate::fsfilcnt64_t,
418        pub f_ffree: crate::fsfilcnt64_t,
419        pub f_fsid: crate::fsid_t,
420        pub f_namelen: c_ulong,
421        pub f_frsize: c_ulong,
422        pub f_flags: c_ulong,
423        pub f_spare: [c_ulong; 4],
424    }
425}
426
427s_no_extra_traits! {
428    pub struct sysinfo {
429        pub uptime: c_ulong,
430        pub loads: [c_ulong; 3],
431        pub totalram: c_ulong,
432        pub freeram: c_ulong,
433        pub sharedram: c_ulong,
434        pub bufferram: c_ulong,
435        pub totalswap: c_ulong,
436        pub freeswap: c_ulong,
437        pub procs: c_ushort,
438        pub pad: c_ushort,
439        pub totalhigh: c_ulong,
440        pub freehigh: c_ulong,
441        pub mem_unit: c_uint,
442        pub __reserved: [c_char; 256],
443    }
444
445    pub struct utmpx {
446        pub ut_type: c_short,
447        __ut_pad1: c_short,
448        pub ut_pid: crate::pid_t,
449        pub ut_line: [c_char; 32],
450        pub ut_id: [c_char; 4],
451        pub ut_user: [c_char; 32],
452        pub ut_host: [c_char; 256],
453        pub ut_exit: __exit_status,
454
455        #[cfg(not(musl_v1_2_3))]
456        #[deprecated(
457            since = "0.2.173",
458            note = "The ABI of this field has changed from c_long to c_int with padding, \
459                we'll follow that change in the future release. See #4443 for more info."
460        )]
461        pub ut_session: c_long,
462
463        #[cfg(musl_v1_2_3)]
464        #[cfg(not(target_endian = "little"))]
465        __ut_pad2: c_int,
466
467        #[cfg(musl_v1_2_3)]
468        pub ut_session: c_int,
469
470        #[cfg(musl_v1_2_3)]
471        #[cfg(target_endian = "little")]
472        __ut_pad2: c_int,
473
474        pub ut_tv: crate::timeval,
475        pub ut_addr_v6: [c_uint; 4],
476        __unused: [c_char; 20],
477    }
478}
479
480cfg_if! {
481    if #[cfg(feature = "extra_traits")] {
482        impl PartialEq for sysinfo {
483            fn eq(&self, other: &sysinfo) -> bool {
484                self.uptime == other.uptime
485                    && self.loads == other.loads
486                    && self.totalram == other.totalram
487                    && self.freeram == other.freeram
488                    && self.sharedram == other.sharedram
489                    && self.bufferram == other.bufferram
490                    && self.totalswap == other.totalswap
491                    && self.freeswap == other.freeswap
492                    && self.procs == other.procs
493                    && self.pad == other.pad
494                    && self.totalhigh == other.totalhigh
495                    && self.freehigh == other.freehigh
496                    && self.mem_unit == other.mem_unit
497                    && self
498                        .__reserved
499                        .iter()
500                        .zip(other.__reserved.iter())
501                        .all(|(a, b)| a == b)
502            }
503        }
504
505        impl Eq for sysinfo {}
506
507        impl hash::Hash for sysinfo {
508            fn hash<H: hash::Hasher>(&self, state: &mut H) {
509                self.uptime.hash(state);
510                self.loads.hash(state);
511                self.totalram.hash(state);
512                self.freeram.hash(state);
513                self.sharedram.hash(state);
514                self.bufferram.hash(state);
515                self.totalswap.hash(state);
516                self.freeswap.hash(state);
517                self.procs.hash(state);
518                self.pad.hash(state);
519                self.totalhigh.hash(state);
520                self.freehigh.hash(state);
521                self.mem_unit.hash(state);
522                self.__reserved.hash(state);
523            }
524        }
525
526        impl PartialEq for utmpx {
527            #[allow(deprecated)]
528            fn eq(&self, other: &utmpx) -> bool {
529                self.ut_type == other.ut_type
530                    //&& self.__ut_pad1 == other.__ut_pad1
531                    && self.ut_pid == other.ut_pid
532                    && self.ut_line == other.ut_line
533                    && self.ut_id == other.ut_id
534                    && self.ut_user == other.ut_user
535                    && self
536                        .ut_host
537                        .iter()
538                        .zip(other.ut_host.iter())
539                        .all(|(a,b)| a == b)
540                    && self.ut_exit == other.ut_exit
541                    && self.ut_session == other.ut_session
542                    //&& self.__ut_pad2 == other.__ut_pad2
543                    && self.ut_tv == other.ut_tv
544                    && self.ut_addr_v6 == other.ut_addr_v6
545                    && self.__unused == other.__unused
546            }
547        }
548
549        impl Eq for utmpx {}
550
551        impl hash::Hash for utmpx {
552            #[allow(deprecated)]
553            fn hash<H: hash::Hasher>(&self, state: &mut H) {
554                self.ut_type.hash(state);
555                //self.__ut_pad1.hash(state);
556                self.ut_pid.hash(state);
557                self.ut_line.hash(state);
558                self.ut_id.hash(state);
559                self.ut_user.hash(state);
560                self.ut_host.hash(state);
561                self.ut_exit.hash(state);
562                self.ut_session.hash(state);
563                //self.__ut_pad2.hash(state);
564                self.ut_tv.hash(state);
565                self.ut_addr_v6.hash(state);
566                self.__unused.hash(state);
567            }
568        }
569    }
570}
571
572// include/sys/mman.h
573/*
574 * Huge page size encoding when MAP_HUGETLB is specified, and a huge page
575 * size other than the default is desired.  See hugetlb_encode.h.
576 * All known huge page size encodings are provided here.  It is the
577 * responsibility of the application to know which sizes are supported on
578 * the running system.  See mmap(2) man page for details.
579 */
580pub const MAP_HUGE_SHIFT: c_int = 26;
581pub const MAP_HUGE_MASK: c_int = 0x3f;
582
583pub const MAP_HUGE_64KB: c_int = 16 << MAP_HUGE_SHIFT;
584pub const MAP_HUGE_512KB: c_int = 19 << MAP_HUGE_SHIFT;
585pub const MAP_HUGE_1MB: c_int = 20 << MAP_HUGE_SHIFT;
586pub const MAP_HUGE_2MB: c_int = 21 << MAP_HUGE_SHIFT;
587pub const MAP_HUGE_8MB: c_int = 23 << MAP_HUGE_SHIFT;
588pub const MAP_HUGE_16MB: c_int = 24 << MAP_HUGE_SHIFT;
589pub const MAP_HUGE_32MB: c_int = 25 << MAP_HUGE_SHIFT;
590pub const MAP_HUGE_256MB: c_int = 28 << MAP_HUGE_SHIFT;
591pub const MAP_HUGE_512MB: c_int = 29 << MAP_HUGE_SHIFT;
592pub const MAP_HUGE_1GB: c_int = 30 << MAP_HUGE_SHIFT;
593pub const MAP_HUGE_2GB: c_int = 31 << MAP_HUGE_SHIFT;
594pub const MAP_HUGE_16GB: c_int = 34 << MAP_HUGE_SHIFT;
595
596pub const MS_RMT_MASK: c_ulong = 0x02800051;
597
598// include/utmpx.h
599pub const EMPTY: c_short = 0;
600pub const RUN_LVL: c_short = 1;
601pub const BOOT_TIME: c_short = 2;
602pub const NEW_TIME: c_short = 3;
603pub const OLD_TIME: c_short = 4;
604pub const INIT_PROCESS: c_short = 5;
605pub const LOGIN_PROCESS: c_short = 6;
606pub const USER_PROCESS: c_short = 7;
607pub const DEAD_PROCESS: c_short = 8;
608pub const ACCOUNTING: c_short = 9;
609
610pub const SFD_CLOEXEC: c_int = 0x080000;
611
612#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
613pub const NCCS: usize = 32;
614#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
615pub const NCCS: usize = 19;
616
617pub const O_TRUNC: c_int = 512;
618pub const O_NOATIME: c_int = 0o1000000;
619pub const O_CLOEXEC: c_int = 0x80000;
620pub const O_TMPFILE: c_int = 0o20000000 | O_DIRECTORY;
621
622pub const EBFONT: c_int = 59;
623pub const ENOSTR: c_int = 60;
624pub const ENODATA: c_int = 61;
625pub const ETIME: c_int = 62;
626pub const ENOSR: c_int = 63;
627pub const ENONET: c_int = 64;
628pub const ENOPKG: c_int = 65;
629pub const EREMOTE: c_int = 66;
630pub const ENOLINK: c_int = 67;
631pub const EADV: c_int = 68;
632pub const ESRMNT: c_int = 69;
633pub const ECOMM: c_int = 70;
634pub const EPROTO: c_int = 71;
635pub const EDOTDOT: c_int = 73;
636
637pub const F_OFD_GETLK: c_int = 36;
638pub const F_OFD_SETLK: c_int = 37;
639pub const F_OFD_SETLKW: c_int = 38;
640
641pub const F_RDLCK: c_int = 0;
642pub const F_WRLCK: c_int = 1;
643pub const F_UNLCK: c_int = 2;
644
645pub const SA_NODEFER: c_int = 0x40000000;
646pub const SA_RESETHAND: c_int = 0x80000000;
647pub const SA_RESTART: c_int = 0x10000000;
648pub const SA_NOCLDSTOP: c_int = 0x00000001;
649
650pub const EPOLL_CLOEXEC: c_int = 0x80000;
651
652pub const EFD_CLOEXEC: c_int = 0x80000;
653
654pub const BUFSIZ: c_uint = 1024;
655pub const TMP_MAX: c_uint = 10000;
656pub const FOPEN_MAX: c_uint = 1000;
657pub const FILENAME_MAX: c_uint = 4096;
658pub const O_PATH: c_int = 0o10000000;
659pub const O_EXEC: c_int = 0o10000000;
660pub const O_SEARCH: c_int = 0o10000000;
661pub const O_ACCMODE: c_int = 0o10000003;
662pub const O_NDELAY: c_int = O_NONBLOCK;
663pub const NI_MAXHOST: crate::socklen_t = 255;
664pub const PTHREAD_STACK_MIN: size_t = 2048;
665
666pub const POSIX_MADV_DONTNEED: c_int = 4;
667
668pub const MAP_ANONYMOUS: c_int = MAP_ANON;
669
670pub const SOCK_SEQPACKET: c_int = 5;
671pub const SOCK_DCCP: c_int = 6;
672pub const SOCK_NONBLOCK: c_int = O_NONBLOCK;
673#[deprecated(since = "0.2.70", note = "AF_PACKET must be used instead")]
674pub const SOCK_PACKET: c_int = 10;
675
676pub const SOMAXCONN: c_int = 128;
677
678#[deprecated(since = "0.2.55", note = "Use SIGSYS instead")]
679pub const SIGUNUSED: c_int = crate::SIGSYS;
680
681pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
682pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
683pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
684pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;
685
686// FIXME(musl): Value is 1024 for all architectures since 1.2.4
687#[cfg(not(target_arch = "loongarch64"))]
688pub const CPU_SETSIZE: c_int = 128;
689#[cfg(target_arch = "loongarch64")]
690pub const CPU_SETSIZE: c_int = 1024;
691
692pub const PTRACE_TRACEME: c_int = 0;
693pub const PTRACE_PEEKTEXT: c_int = 1;
694pub const PTRACE_PEEKDATA: c_int = 2;
695pub const PTRACE_PEEKUSER: c_int = 3;
696pub const PTRACE_POKETEXT: c_int = 4;
697pub const PTRACE_POKEDATA: c_int = 5;
698pub const PTRACE_POKEUSER: c_int = 6;
699pub const PTRACE_CONT: c_int = 7;
700pub const PTRACE_KILL: c_int = 8;
701pub const PTRACE_SINGLESTEP: c_int = 9;
702pub const PTRACE_GETREGS: c_int = 12;
703pub const PTRACE_SETREGS: c_int = 13;
704pub const PTRACE_GETFPREGS: c_int = 14;
705pub const PTRACE_SETFPREGS: c_int = 15;
706pub const PTRACE_ATTACH: c_int = 16;
707pub const PTRACE_DETACH: c_int = 17;
708pub const PTRACE_GETFPXREGS: c_int = 18;
709pub const PTRACE_SETFPXREGS: c_int = 19;
710pub const PTRACE_SYSCALL: c_int = 24;
711pub const PTRACE_SETOPTIONS: c_int = 0x4200;
712pub const PTRACE_GETEVENTMSG: c_int = 0x4201;
713pub const PTRACE_GETSIGINFO: c_int = 0x4202;
714pub const PTRACE_SETSIGINFO: c_int = 0x4203;
715pub const PTRACE_GETREGSET: c_int = 0x4204;
716pub const PTRACE_SETREGSET: c_int = 0x4205;
717pub const PTRACE_SEIZE: c_int = 0x4206;
718pub const PTRACE_INTERRUPT: c_int = 0x4207;
719pub const PTRACE_LISTEN: c_int = 0x4208;
720pub const PTRACE_PEEKSIGINFO: c_int = 0x4209;
721pub const PTRACE_GETSIGMASK: c_uint = 0x420a;
722pub const PTRACE_SETSIGMASK: c_uint = 0x420b;
723
724pub const AF_IB: c_int = 27;
725pub const AF_MPLS: c_int = 28;
726pub const AF_NFC: c_int = 39;
727pub const AF_VSOCK: c_int = 40;
728pub const AF_XDP: c_int = 44;
729pub const PF_IB: c_int = AF_IB;
730pub const PF_MPLS: c_int = AF_MPLS;
731pub const PF_NFC: c_int = AF_NFC;
732pub const PF_VSOCK: c_int = AF_VSOCK;
733pub const PF_XDP: c_int = AF_XDP;
734
735pub const EFD_NONBLOCK: c_int = crate::O_NONBLOCK;
736
737pub const SFD_NONBLOCK: c_int = crate::O_NONBLOCK;
738
739pub const TCSANOW: c_int = 0;
740pub const TCSADRAIN: c_int = 1;
741pub const TCSAFLUSH: c_int = 2;
742
743pub const RTLD_GLOBAL: c_int = 0x100;
744pub const RTLD_NOLOAD: c_int = 0x4;
745
746pub const CLOCK_SGI_CYCLE: crate::clockid_t = 10;
747
748pub const B0: crate::speed_t = 0o000000;
749pub const B50: crate::speed_t = 0o000001;
750pub const B75: crate::speed_t = 0o000002;
751pub const B110: crate::speed_t = 0o000003;
752pub const B134: crate::speed_t = 0o000004;
753pub const B150: crate::speed_t = 0o000005;
754pub const B200: crate::speed_t = 0o000006;
755pub const B300: crate::speed_t = 0o000007;
756pub const B600: crate::speed_t = 0o000010;
757pub const B1200: crate::speed_t = 0o000011;
758pub const B1800: crate::speed_t = 0o000012;
759pub const B2400: crate::speed_t = 0o000013;
760pub const B4800: crate::speed_t = 0o000014;
761pub const B9600: crate::speed_t = 0o000015;
762pub const B19200: crate::speed_t = 0o000016;
763pub const B38400: crate::speed_t = 0o000017;
764pub const EXTA: crate::speed_t = B19200;
765pub const EXTB: crate::speed_t = B38400;
766
767pub const REG_OK: c_int = 0;
768
769pub const PRIO_PROCESS: c_int = 0;
770pub const PRIO_PGRP: c_int = 1;
771pub const PRIO_USER: c_int = 2;
772
773pub const ADJ_OFFSET: c_uint = 0x0001;
774pub const ADJ_FREQUENCY: c_uint = 0x0002;
775pub const ADJ_MAXERROR: c_uint = 0x0004;
776pub const ADJ_ESTERROR: c_uint = 0x0008;
777pub const ADJ_STATUS: c_uint = 0x0010;
778pub const ADJ_TIMECONST: c_uint = 0x0020;
779pub const ADJ_TAI: c_uint = 0x0080;
780pub const ADJ_SETOFFSET: c_uint = 0x0100;
781pub const ADJ_MICRO: c_uint = 0x1000;
782pub const ADJ_NANO: c_uint = 0x2000;
783pub const ADJ_TICK: c_uint = 0x4000;
784pub const ADJ_OFFSET_SINGLESHOT: c_uint = 0x8001;
785pub const ADJ_OFFSET_SS_READ: c_uint = 0xa001;
786pub const MOD_OFFSET: c_uint = ADJ_OFFSET;
787pub const MOD_FREQUENCY: c_uint = ADJ_FREQUENCY;
788pub const MOD_MAXERROR: c_uint = ADJ_MAXERROR;
789pub const MOD_ESTERROR: c_uint = ADJ_ESTERROR;
790pub const MOD_STATUS: c_uint = ADJ_STATUS;
791pub const MOD_TIMECONST: c_uint = ADJ_TIMECONST;
792pub const MOD_CLKB: c_uint = ADJ_TICK;
793pub const MOD_CLKA: c_uint = ADJ_OFFSET_SINGLESHOT;
794pub const MOD_TAI: c_uint = ADJ_TAI;
795pub const MOD_MICRO: c_uint = ADJ_MICRO;
796pub const MOD_NANO: c_uint = ADJ_NANO;
797pub const STA_PLL: c_int = 0x0001;
798pub const STA_PPSFREQ: c_int = 0x0002;
799pub const STA_PPSTIME: c_int = 0x0004;
800pub const STA_FLL: c_int = 0x0008;
801pub const STA_INS: c_int = 0x0010;
802pub const STA_DEL: c_int = 0x0020;
803pub const STA_UNSYNC: c_int = 0x0040;
804pub const STA_FREQHOLD: c_int = 0x0080;
805pub const STA_PPSSIGNAL: c_int = 0x0100;
806pub const STA_PPSJITTER: c_int = 0x0200;
807pub const STA_PPSWANDER: c_int = 0x0400;
808pub const STA_PPSERROR: c_int = 0x0800;
809pub const STA_CLOCKERR: c_int = 0x1000;
810pub const STA_NANO: c_int = 0x2000;
811pub const STA_MODE: c_int = 0x4000;
812pub const STA_CLK: c_int = 0x8000;
813pub const STA_RONLY: c_int = STA_PPSSIGNAL
814    | STA_PPSJITTER
815    | STA_PPSWANDER
816    | STA_PPSERROR
817    | STA_CLOCKERR
818    | STA_NANO
819    | STA_MODE
820    | STA_CLK;
821
822pub const TIME_OK: c_int = 0;
823pub const TIME_INS: c_int = 1;
824pub const TIME_DEL: c_int = 2;
825pub const TIME_OOP: c_int = 3;
826pub const TIME_WAIT: c_int = 4;
827pub const TIME_ERROR: c_int = 5;
828pub const TIME_BAD: c_int = TIME_ERROR;
829pub const MAXTC: c_long = 6;
830
831pub const _CS_V6_ENV: c_int = 1148;
832pub const _CS_V7_ENV: c_int = 1149;
833
834pub const CLONE_NEWTIME: c_int = 0x80;
835
836pub const UT_HOSTSIZE: usize = 256;
837pub const UT_LINESIZE: usize = 32;
838pub const UT_NAMESIZE: usize = 32;
839
840cfg_if! {
841    if #[cfg(target_arch = "s390x")] {
842        pub const POSIX_FADV_DONTNEED: c_int = 6;
843        pub const POSIX_FADV_NOREUSE: c_int = 7;
844    } else {
845        pub const POSIX_FADV_DONTNEED: c_int = 4;
846        pub const POSIX_FADV_NOREUSE: c_int = 5;
847    }
848}
849
850extern "C" {
851    pub fn sendmmsg(
852        sockfd: c_int,
853        msgvec: *mut crate::mmsghdr,
854        vlen: c_uint,
855        flags: c_uint,
856    ) -> c_int;
857    pub fn recvmmsg(
858        sockfd: c_int,
859        msgvec: *mut crate::mmsghdr,
860        vlen: c_uint,
861        flags: c_uint,
862        timeout: *mut crate::timespec,
863    ) -> c_int;
864
865    pub fn getrlimit(resource: c_int, rlim: *mut crate::rlimit) -> c_int;
866    pub fn setrlimit(resource: c_int, rlim: *const crate::rlimit) -> c_int;
867    pub fn prlimit(
868        pid: crate::pid_t,
869        resource: c_int,
870        new_limit: *const crate::rlimit,
871        old_limit: *mut crate::rlimit,
872    ) -> c_int;
873    pub fn gettimeofday(tp: *mut crate::timeval, tz: *mut c_void) -> c_int;
874    pub fn ptrace(request: c_int, ...) -> c_long;
875    pub fn getpriority(which: c_int, who: crate::id_t) -> c_int;
876    pub fn setpriority(which: c_int, who: crate::id_t, prio: c_int) -> c_int;
877    // Musl targets need the `mask` argument of `fanotify_mark` be specified
878    // `c_ulonglong` instead of `u64` or there will be a type mismatch between
879    // `long long unsigned int` and the expected `uint64_t`.
880    pub fn fanotify_mark(
881        fd: c_int,
882        flags: c_uint,
883        mask: c_ulonglong,
884        dirfd: c_int,
885        path: *const c_char,
886    ) -> c_int;
887    pub fn preadv2(
888        fd: c_int,
889        iov: *const crate::iovec,
890        iovcnt: c_int,
891        offset: off_t,
892        flags: c_int,
893    ) -> ssize_t;
894    pub fn pwritev2(
895        fd: c_int,
896        iov: *const crate::iovec,
897        iovcnt: c_int,
898        offset: off_t,
899        flags: c_int,
900    ) -> ssize_t;
901    pub fn getauxval(type_: c_ulong) -> c_ulong;
902
903    // Added in `musl` 1.1.20
904    pub fn explicit_bzero(s: *mut c_void, len: size_t);
905    // Added in `musl` 1.2.2
906    pub fn reallocarray(ptr: *mut c_void, nmemb: size_t, size: size_t) -> *mut c_void;
907
908    pub fn adjtimex(buf: *mut crate::timex) -> c_int;
909    pub fn clock_adjtime(clk_id: crate::clockid_t, buf: *mut crate::timex) -> c_int;
910
911    pub fn ctermid(s: *mut c_char) -> *mut c_char;
912
913    pub fn memfd_create(name: *const c_char, flags: c_uint) -> c_int;
914    pub fn mlock2(addr: *const c_void, len: size_t, flags: c_uint) -> c_int;
915    pub fn malloc_usable_size(ptr: *mut c_void) -> size_t;
916
917    pub fn euidaccess(pathname: *const c_char, mode: c_int) -> c_int;
918    pub fn eaccess(pathname: *const c_char, mode: c_int) -> c_int;
919
920    pub fn asctime_r(tm: *const crate::tm, buf: *mut c_char) -> *mut c_char;
921
922    pub fn dirname(path: *mut c_char) -> *mut c_char;
923    pub fn basename(path: *mut c_char) -> *mut c_char;
924
925    // Added in `musl` 1.1.20
926    pub fn getrandom(buf: *mut c_void, buflen: size_t, flags: c_uint) -> ssize_t;
927
928    // Added in `musl` 1.1.24
929    pub fn posix_spawn_file_actions_addchdir_np(
930        actions: *mut crate::posix_spawn_file_actions_t,
931        path: *const c_char,
932    ) -> c_int;
933    // Added in `musl` 1.1.24
934    pub fn posix_spawn_file_actions_addfchdir_np(
935        actions: *mut crate::posix_spawn_file_actions_t,
936        fd: c_int,
937    ) -> c_int;
938
939    #[deprecated(
940        since = "0.2.172",
941        note = "musl provides `utmp` as stubs and an alternative should be preferred; see https://wiki.musl-libc.org/faq.html"
942    )]
943    pub fn getutxent() -> *mut utmpx;
944    #[deprecated(
945        since = "0.2.172",
946        note = "musl provides `utmp` as stubs and an alternative should be preferred; see https://wiki.musl-libc.org/faq.html"
947    )]
948    pub fn getutxid(ut: *const utmpx) -> *mut utmpx;
949    #[deprecated(
950        since = "0.2.172",
951        note = "musl provides `utmp` as stubs and an alternative should be preferred; see https://wiki.musl-libc.org/faq.html"
952    )]
953    pub fn getutxline(ut: *const utmpx) -> *mut utmpx;
954    #[deprecated(
955        since = "0.2.172",
956        note = "musl provides `utmp` as stubs and an alternative should be preferred; see https://wiki.musl-libc.org/faq.html"
957    )]
958    pub fn pututxline(ut: *const utmpx) -> *mut utmpx;
959    #[deprecated(
960        since = "0.2.172",
961        note = "musl provides `utmp` as stubs and an alternative should be preferred; see https://wiki.musl-libc.org/faq.html"
962    )]
963    pub fn setutxent();
964    #[deprecated(
965        since = "0.2.172",
966        note = "musl provides `utmp` as stubs and an alternative should be preferred; see https://wiki.musl-libc.org/faq.html"
967    )]
968    pub fn endutxent();
969    #[deprecated(
970        since = "0.2.172",
971        note = "musl provides `utmp` as stubs and an alternative should be preferred; see https://wiki.musl-libc.org/faq.html"
972    )]
973    pub fn utmpxname(file: *const c_char) -> c_int;
974}
975
976// Alias <foo> to <foo>64 to mimic glibc's LFS64 support
977mod lfs64;
978pub use self::lfs64::*;
979
980cfg_if! {
981    if #[cfg(any(
982        target_arch = "x86_64",
983        target_arch = "aarch64",
984        target_arch = "mips64",
985        target_arch = "powerpc64",
986        target_arch = "s390x",
987        target_arch = "riscv64",
988        target_arch = "loongarch64",
989        // musl-linux ABI for wasm32 follows b64 convention
990        target_arch = "wasm32",
991    ))] {
992        mod b64;
993        pub use self::b64::*;
994    } else if #[cfg(any(
995        target_arch = "x86",
996        target_arch = "mips",
997        target_arch = "powerpc",
998        target_arch = "hexagon",
999        target_arch = "riscv32",
1000        target_arch = "arm"
1001    ))] {
1002        mod b32;
1003        pub use self::b32::*;
1004    } else {
1005    }
1006}