xref: /third_party/rust/crates/libc/src/unix/hermit/mod.rs (revision 2add0d91)
1// liblibc port for HermitCore (https://hermitcore.org)
2// HermitCore is a unikernel based on lwIP, newlib, and
3// pthread-embedded.
4// Consider these definitions when porting liblibc to another
5// lwIP/newlib/pte-based target.
6//
7// Ported by Colin Finck <colin.finck@rwth-aachen.de>
8
9pub type c_long = i64;
10pub type c_ulong = u64;
11
12pub type speed_t = ::c_uint;
13pub type mode_t = u32;
14pub type dev_t = i16;
15pub type nfds_t = ::c_ulong;
16pub type socklen_t = u32;
17pub type sa_family_t = u8;
18pub type clock_t = c_ulong;
19pub type time_t = c_long;
20pub type suseconds_t = c_long;
21pub type off_t = i64;
22pub type rlim_t = ::c_ulonglong;
23pub type sigset_t = ::c_ulong;
24pub type ino_t = u16;
25pub type nlink_t = u16;
26pub type blksize_t = c_long;
27pub type blkcnt_t = c_long;
28pub type stat64 = stat;
29pub type clockid_t = c_ulong;
30pub type pthread_t = pte_handle_t;
31pub type pthread_attr_t = usize;
32pub type pthread_cond_t = usize;
33pub type pthread_condattr_t = usize;
34pub type pthread_key_t = usize;
35pub type pthread_mutex_t = usize;
36pub type pthread_mutexattr_t = usize;
37pub type pthread_rwlock_t = usize;
38pub type pthread_rwlockattr_t = usize;
39
40s_no_extra_traits! {
41    pub struct dirent {
42        pub d_ino: ::c_long,
43        pub d_off: off_t,
44        pub d_reclen: u16,
45        pub d_name: [::c_char; 256],
46    }
47
48    // Dummy
49    pub struct sockaddr_un {
50        pub sun_family: sa_family_t,
51        pub sun_path: [::c_char; 108],
52    }
53
54    pub struct sockaddr {
55        pub sa_len: u8,
56        pub sa_family: sa_family_t,
57        pub sa_data: [::c_char; 14],
58    }
59
60    pub struct sockaddr_in {
61        pub sin_len: u8,
62        pub sin_family: sa_family_t,
63        pub sin_port: ::in_port_t,
64        pub sin_addr: ::in_addr,
65        pub sin_zero: [::c_char; 8],
66    }
67
68    pub struct fd_set {
69        fds_bits: [::c_ulong; FD_SETSIZE / ULONG_SIZE],
70    }
71
72    pub struct sockaddr_storage {
73        pub s2_len: u8,
74        pub ss_family: sa_family_t,
75        pub s2_data1: [::c_char; 2],
76        pub s2_data2: [u32; 3],
77        pub s2_data3: [u32; 3],
78    }
79
80    pub struct stat {
81        pub st_dev: ::dev_t,
82        pub st_ino: ::ino_t,
83        pub st_mode: ::mode_t,
84        pub st_nlink: ::nlink_t,
85        pub st_uid: ::uid_t,
86        pub st_gid: ::gid_t,
87        pub st_rdev: dev_t,
88        pub st_size: off_t,
89        pub st_atime: time_t,
90        pub st_atime_nsec: ::c_long,
91        pub st_mtime: time_t,
92        pub st_mtime_nsec: ::c_long,
93        pub st_ctime: time_t,
94        pub st_ctime_nsec: ::c_long,
95        pub st_blksize: blksize_t,
96        pub st_blocks: blkcnt_t,
97        pub st_spare4: [::c_long; 2],
98    }
99}
100
101cfg_if! {
102    if #[cfg(feature = "extra_traits")] {
103        impl PartialEq for dirent {
104            fn eq(&self, other: &dirent) -> bool {
105                self.d_ino == other.d_ino
106                    && self.d_off == other.d_off
107                    && self.d_reclen == other.d_reclen
108                    && self
109                    .d_name
110                    .iter()
111                    .zip(other.d_name.iter())
112                    .all(|(a,b)| a == b)
113            }
114        }
115        impl Eq for dirent {}
116        impl ::fmt::Debug for dirent {
117            fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
118                f.debug_struct("dirent")
119                    .field("d_ino", &self.d_ino)
120                    .field("d_off", &self.d_off)
121                    .field("d_reclen", &self.d_reclen)
122                    // FIXME: .field("d_name", &self.d_name)
123                    .finish()
124            }
125        }
126        impl ::hash::Hash for dirent {
127            fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
128                self.d_ino.hash(state);
129                self.d_off.hash(state);
130                self.d_reclen.hash(state);
131                self.d_name.hash(state);
132            }
133        }
134
135        impl PartialEq for sockaddr_un {
136            fn eq(&self, other: &sockaddr_un) -> bool {
137                self.sun_family == other.sun_family
138                    && self
139                    .sun_path
140                    .iter()
141                    .zip(other.sun_path.iter())
142                    .all(|(a,b)| a == b)
143            }
144        }
145        impl Eq for sockaddr_un {}
146        impl ::fmt::Debug for sockaddr_un {
147            fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
148                f.debug_struct("sockaddr_un")
149                    .field("sun_family", &self.sun_family)
150                    // FIXME: .field("sun_path", &self.sun_path)
151                    .finish()
152            }
153        }
154        impl ::hash::Hash for sockaddr_un {
155            fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
156                self.sun_family.hash(state);
157                self.sun_path.hash(state);
158            }
159        }
160
161        impl PartialEq for sockaddr {
162            fn eq(&self, other: &sockaddr) -> bool {
163                self.sa_len == other.sa_len
164                    && self.sa_family == other.sa_family
165                    && self
166                    .sa_data
167                    .iter()
168                    .zip(other.sa_data.iter())
169                    .all(|(a,b)| a == b)
170            }
171        }
172        impl Eq for sockaddr {}
173        impl ::fmt::Debug for sockaddr {
174            fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
175                f.debug_struct("sockaddr")
176                    .field("sa_len", &self.sa_len)
177                    .field("sa_family", &self.sa_family)
178                    // FIXME: .field("sa_data", &self.sa_data)
179                    .finish()
180            }
181        }
182        impl ::hash::Hash for sockaddr {
183            fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
184                self.sa_len.hash(state);
185                self.sa_family.hash(state);
186                self.sa_data.hash(state);
187            }
188        }
189
190        impl PartialEq for sockaddr_in {
191            fn eq(&self, other: &sockaddr_in) -> bool {
192                self.sin_len == other.sin_len
193                    && self.sin_family == other.sin_family
194                    && self.sin_port == other.sin_port
195                    && self.sin_addr == other.sin_addr
196                    && self
197                    .sin_zero
198                    .iter()
199                    .zip(other.sin_zero.iter())
200                    .all(|(a,b)| a == b)
201            }
202        }
203        impl Eq for sockaddr_in {}
204        impl ::fmt::Debug for sockaddr_in {
205            fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
206                f.debug_struct("sockaddr_in")
207                    .field("sin_len", &self.sin_len)
208                    .field("sin_family", &self.sin_family)
209                    .field("sin_port", &self.sin_port)
210                    .field("sin_addr", &self.sin_addr)
211                    // FIXME: .field("sin_zero", &self.sin_zero)
212                    .finish()
213            }
214        }
215        impl ::hash::Hash for sockaddr_in {
216            fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
217                self.sin_len.hash(state);
218                self.sin_family.hash(state);
219                self.sin_port.hash(state);
220                self.sin_addr.hash(state);
221                self.sin_zero.hash(state);
222            }
223        }
224
225        impl PartialEq for fd_set {
226            fn eq(&self, other: &fd_set) -> bool {
227                self.fds_bits
228                    .iter()
229                    .zip(other.fds_bits.iter())
230                    .all(|(a,b)| a == b)
231            }
232        }
233        impl Eq for fd_set {}
234        impl ::fmt::Debug for fd_set {
235            fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
236                f.debug_struct("fd_set")
237                    // FIXME: .field("fds_bits", &self.fds_bits)
238                    .finish()
239            }
240        }
241        impl ::hash::Hash for fd_set {
242            fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
243                self.fds_bits.hash(state);
244            }
245        }
246
247        impl PartialEq for sockaddr_storage {
248            fn eq(&self, other: &sockaddr_storage) -> bool {
249                self.s2_len == other.s2_len
250                    && self.ss_family == other.ss_family
251                    && self.s2_data1
252                    .iter()
253                    .zip(other.s2_data1.iter())
254                    .all(|(a,b)| a == b)
255                    && self.s2_data2
256                    .iter()
257                    .zip(other.s2_data2.iter())
258                    .all(|(a,b)| a == b)
259                    && self.s2_data3
260                    .iter()
261                    .zip(other.s2_data3.iter())
262                    .all(|(a,b)| a == b)
263            }
264        }
265        impl Eq for sockaddr_storage {}
266        impl ::fmt::Debug for sockaddr_storage {
267            fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
268                f.debug_struct("sockaddr_storage")
269                    .field("s2_len", &self.s2_len)
270                    .field("ss_family", &self.ss_family)
271                    // FIXME: .field("s2_data1", &self.s2_data1)
272                    // FIXME: .field("s2_data2", &self.s2_data2)
273                    // FIXME: .field("s2_data3", &self.s2_data3)
274                    .finish()
275            }
276        }
277        impl ::hash::Hash for sockaddr_storage {
278            fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
279                self.s2_len.hash(state);
280                self.ss_family.hash(state);
281                self.s2_data1.hash(state);
282                self.s2_data2.hash(state);
283                self.s2_data3.hash(state);
284            }
285        }
286
287        impl PartialEq for stat {
288            fn eq(&self, other: &stat) -> bool {
289                self.st_dev == other.st_dev
290                    && self.st_ino == other.st_ino
291                    && self.st_mode == other.st_mode
292                    && self.st_nlink == other.st_nlink
293                    && self.st_uid == other.st_uid
294                    && self.st_gid == other.st_gid
295                    && self.st_rdev == other.st_rdev
296                    && self.st_size == other.st_size
297                    && self.st_atime == other.st_atime
298                    && self.st_atime_nsec == other.st_atime_nsec
299                    && self.st_mtime == other.st_mtime
300                    && self.st_mtime_nsec == other.st_mtime_nsec
301                    && self.st_ctime == other.st_ctime
302                    && self.st_ctime_nsec == other.st_ctime_nsec
303                    && self.st_blksize == other.st_blksize
304                    && self.st_blocks == other.st_blocks
305                    && self
306                    .st_spare4
307                    .iter()
308                    .zip(other.st_spare4.iter())
309                    .all(|(a,b)| a == b)
310            }
311        }
312        impl Eq for stat {}
313        impl ::fmt::Debug for stat {
314            fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
315                f.debug_struct("stat")
316                    .field("st_dev", &self.st_dev)
317                    .field("st_ino", &self.st_ino)
318                    .field("st_mode", &self.st_mode)
319                    .field("st_nlink", &self.st_nlink)
320                    .field("st_uid", &self.st_uid)
321                    .field("st_gid", &self.st_gid)
322                    .field("st_rdev", &self.st_rdev)
323                    .field("st_size", &self.st_size)
324                    .field("st_atime", &self.st_atime)
325                    .field("st_atime_nsec", &self.st_atime_nsec)
326                    .field("st_mtime", &self.st_mtime)
327                    .field("st_mtime_nsec", &self.st_mtime_nsec)
328                    .field("st_ctime", &self.st_ctime)
329                    .field("st_ctime_nsec", &self.st_ctime_nsec)
330                    .field("st_blksize", &self.st_blksize)
331                    .field("st_blocks", &self.st_blocks)
332                    // FIXME: .field("st_spare4", &self.st_spare4)
333                    .finish()
334            }
335        }
336        impl ::hash::Hash for stat {
337            fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
338                self.st_dev.hash(state);
339                self.st_ino.hash(state);
340                self.st_mode.hash(state);
341                self.st_nlink.hash(state);
342                self.st_uid.hash(state);
343                self.st_gid.hash(state);
344                self.st_rdev.hash(state);
345                self.st_size.hash(state);
346                self.st_atime.hash(state);
347                self.st_atime_nsec.hash(state);
348                self.st_mtime.hash(state);
349                self.st_mtime_nsec.hash(state);
350                self.st_ctime.hash(state);
351                self.st_ctime_nsec.hash(state);
352                self.st_blksize.hash(state);
353                self.st_blocks.hash(state);
354                self.st_spare4.hash(state);
355            }
356        }
357    }
358}
359
360s! {
361    pub struct in_addr {
362        pub s_addr: ::in_addr_t,
363    }
364
365    pub struct ip_mreq {
366        pub imr_multiaddr: in_addr,
367        pub imr_interface: in_addr,
368    }
369
370    pub struct addrinfo {
371        pub ai_flags: ::c_int,
372        pub ai_family: ::c_int,
373        pub ai_socktype: ::c_int,
374        pub ai_protocol: ::c_int,
375        pub ai_addrlen: socklen_t,
376        pub ai_addr: *mut ::sockaddr,
377        pub ai_canonname: *mut c_char,
378        pub ai_next: *mut addrinfo,
379    }
380
381    pub struct Dl_info {}
382
383    pub struct lconv {
384        pub decimal_point: *mut ::c_char,
385        pub thousands_sep: *mut ::c_char,
386        pub grouping: *mut ::c_char,
387        pub int_curr_symbol: *mut ::c_char,
388        pub currency_symbol: *mut ::c_char,
389        pub mon_decimal_point: *mut ::c_char,
390        pub mon_thousands_sep: *mut ::c_char,
391        pub mon_grouping: *mut ::c_char,
392        pub positive_sign: *mut ::c_char,
393        pub negative_sign: *mut ::c_char,
394        pub int_frac_digits: ::c_char,
395        pub frac_digits: ::c_char,
396        pub p_cs_precedes: ::c_char,
397        pub p_sep_by_space: ::c_char,
398        pub n_cs_precedes: ::c_char,
399        pub n_sep_by_space: ::c_char,
400        pub p_sign_posn: ::c_char,
401        pub n_sign_posn: ::c_char,
402        pub int_p_cs_precedes: ::c_char,
403        pub int_p_sep_by_space: ::c_char,
404        pub int_n_cs_precedes: ::c_char,
405        pub int_n_sep_by_space: ::c_char,
406        pub int_p_sign_posn: ::c_char,
407        pub int_n_sign_posn: ::c_char,
408    }
409
410    pub struct passwd { // Unverified
411        pub pw_name: *mut ::c_char,
412        pub pw_passwd: *mut ::c_char,
413        pub pw_uid: ::uid_t,
414        pub pw_gid: ::gid_t,
415        pub pw_gecos: *mut ::c_char,
416        pub pw_dir: *mut ::c_char,
417        pub pw_shell: *mut ::c_char,
418    }
419
420    pub struct pte_handle_t {
421        pub p: usize,
422        pub x: ::c_uint,
423    }
424
425    pub struct sched_param {
426        pub sched_priority: ::c_int,
427    }
428
429    pub struct sem_t {
430        pub value: i32,
431        pub lock: usize,
432        pub sem: usize,
433    }
434
435    pub struct sigaction {
436        pub sa_flags: ::c_int,
437        pub sa_mask: sigset_t,
438        pub sa_handler: usize,
439    }
440
441    pub struct sockaddr_in6 {
442        pub sin6_len: u8,
443        pub sin6_family: sa_family_t,
444        pub sin6_port: ::in_port_t,
445        pub sin6_flowinfo: u32,
446        pub sin6_addr: ::in6_addr,
447        pub sin6_scope_id: u32,
448    }
449
450    pub struct statvfs {}
451
452    pub struct tm {
453        pub tm_sec: ::c_int,
454        pub tm_min: ::c_int,
455        pub tm_hour: ::c_int,
456        pub tm_mday: ::c_int,
457        pub tm_mon: ::c_int,
458        pub tm_year: ::c_int,
459        pub tm_wday: ::c_int,
460        pub tm_yday: ::c_int,
461        pub tm_isdst: ::c_int,
462    }
463
464    pub struct tms {
465        pub tms_utime: ::clock_t,
466        pub tms_stime: ::clock_t,
467        pub tms_cutime: ::clock_t,
468        pub tms_cstime: ::clock_t,
469    }
470
471    pub struct termios {}
472
473    pub struct utsname {}
474}
475
476pub const AF_UNSPEC: ::c_int = 0;
477pub const AF_INET: ::c_int = 2;
478pub const AF_INET6: ::c_int = 10;
479
480// Dummy
481pub const AF_UNIX: ::c_int = 1;
482
483pub const CLOCK_REALTIME: ::clockid_t = 1;
484pub const CLOCK_MONOTONIC: ::clockid_t = 4;
485
486// Dummy
487pub const EAI_SYSTEM: ::c_int = -11;
488
489pub const EPERM: ::c_int = 1;
490pub const ENOENT: ::c_int = 2;
491pub const ESRCH: ::c_int = 3;
492pub const EINTR: ::c_int = 4;
493pub const EIO: ::c_int = 5;
494pub const ENXIO: ::c_int = 6;
495pub const E2BIG: ::c_int = 7;
496pub const ENOEXEC: ::c_int = 8;
497pub const EBADF: ::c_int = 9;
498pub const ECHILD: ::c_int = 10;
499pub const EAGAIN: ::c_int = 11;
500pub const ENOMEM: ::c_int = 12;
501pub const EACCES: ::c_int = 13;
502pub const EFAULT: ::c_int = 14;
503pub const EBUSY: ::c_int = 16;
504pub const EEXIST: ::c_int = 17;
505pub const EXDEV: ::c_int = 18;
506pub const ENODEV: ::c_int = 19;
507pub const ENOTDIR: ::c_int = 20;
508pub const EISDIR: ::c_int = 21;
509pub const EINVAL: ::c_int = 22;
510pub const ENFILE: ::c_int = 23;
511pub const EMFILE: ::c_int = 24;
512pub const ENOTTY: ::c_int = 25;
513pub const ETXTBSY: ::c_int = 26;
514pub const EFBIG: ::c_int = 27;
515pub const ENOSPC: ::c_int = 28;
516pub const ESPIPE: ::c_int = 29;
517pub const EROFS: ::c_int = 30;
518pub const EMLINK: ::c_int = 31;
519pub const EPIPE: ::c_int = 32;
520pub const EDOM: ::c_int = 33;
521pub const ERANGE: ::c_int = 34;
522pub const EDEADLK: ::c_int = 35;
523pub const ENAMETOOLONG: ::c_int = 36;
524pub const ENOLCK: ::c_int = 37;
525pub const ENOSYS: ::c_int = 38;
526pub const ENOTEMPTY: ::c_int = 39;
527pub const ELOOP: ::c_int = 40;
528pub const EWOULDBLOCK: ::c_int = EAGAIN;
529pub const ENOMSG: ::c_int = 42;
530pub const EIDRM: ::c_int = 43;
531pub const ECHRNG: ::c_int = 44;
532pub const EL2NSYNC: ::c_int = 45;
533pub const EL3HLT: ::c_int = 46;
534pub const EL3RST: ::c_int = 47;
535pub const ELNRNG: ::c_int = 48;
536pub const EUNATCH: ::c_int = 49;
537pub const ENOCSI: ::c_int = 50;
538pub const EL2HLT: ::c_int = 51;
539pub const EBADE: ::c_int = 52;
540pub const EBADR: ::c_int = 53;
541pub const EXFULL: ::c_int = 54;
542pub const ENOANO: ::c_int = 55;
543pub const EBADRQC: ::c_int = 56;
544pub const EBADSLT: ::c_int = 57;
545pub const EDEADLOCK: ::c_int = EDEADLK;
546pub const EBFONT: ::c_int = 59;
547pub const ENOSTR: ::c_int = 60;
548pub const ENODATA: ::c_int = 61;
549pub const ETIME: ::c_int = 62;
550pub const ENOSR: ::c_int = 63;
551pub const ENONET: ::c_int = 64;
552pub const ENOPKG: ::c_int = 65;
553pub const EREMOTE: ::c_int = 66;
554pub const ENOLINK: ::c_int = 67;
555pub const EADV: ::c_int = 68;
556pub const ESRMNT: ::c_int = 69;
557pub const ECOMM: ::c_int = 70;
558pub const EPROTO: ::c_int = 71;
559pub const EMULTIHOP: ::c_int = 72;
560pub const EDOTDOT: ::c_int = 73;
561pub const EBADMSG: ::c_int = 74;
562pub const EOVERFLOW: ::c_int = 75;
563pub const ENOTUNIQ: ::c_int = 76;
564pub const EBADFD: ::c_int = 77;
565pub const EREMCHG: ::c_int = 78;
566pub const ELIBACC: ::c_int = 79;
567pub const ELIBBAD: ::c_int = 80;
568pub const ELIBSCN: ::c_int = 81;
569pub const ELIBMAX: ::c_int = 82;
570pub const ELIBEXEC: ::c_int = 83;
571pub const EILSEQ: ::c_int = 84;
572pub const ERESTART: ::c_int = 85;
573pub const ESTRPIPE: ::c_int = 86;
574pub const EUSERS: ::c_int = 87;
575pub const ENOTSOCK: ::c_int = 88;
576pub const EDESTADDRREQ: ::c_int = 89;
577pub const EMSGSIZE: ::c_int = 90;
578pub const EPROTOTYPE: ::c_int = 91;
579pub const ENOPROTOOPT: ::c_int = 92;
580pub const EPROTONOSUPPORT: ::c_int = 93;
581pub const ESOCKTNOSUPPORT: ::c_int = 94;
582pub const EOPNOTSUPP: ::c_int = 95;
583pub const EPFNOSUPPORT: ::c_int = 96;
584pub const EAFNOSUPPORT: ::c_int = 97;
585pub const EADDRINUSE: ::c_int = 98;
586pub const EADDRNOTAVAIL: ::c_int = 99;
587pub const ENETDOWN: ::c_int = 100;
588pub const ENETUNREACH: ::c_int = 101;
589pub const ENETRESET: ::c_int = 102;
590pub const ECONNABORTED: ::c_int = 103;
591pub const ECONNRESET: ::c_int = 104;
592pub const ENOBUFS: ::c_int = 105;
593pub const EISCONN: ::c_int = 106;
594pub const ENOTCONN: ::c_int = 107;
595pub const ESHUTDOWN: ::c_int = 108;
596pub const ETOOMANYREFS: ::c_int = 109;
597pub const ETIMEDOUT: ::c_int = 110;
598pub const ECONNREFUSED: ::c_int = 111;
599pub const EHOSTDOWN: ::c_int = 112;
600pub const EHOSTUNREACH: ::c_int = 113;
601pub const EALREADY: ::c_int = 114;
602pub const EINPROGRESS: ::c_int = 115;
603pub const ESTALE: ::c_int = 116;
604pub const EUCLEAN: ::c_int = 117;
605pub const ENOTNAM: ::c_int = 118;
606pub const ENAVAIL: ::c_int = 119;
607pub const EISNAM: ::c_int = 120;
608pub const EREMOTEIO: ::c_int = 121;
609pub const EDQUOT: ::c_int = 122;
610pub const ENOMEDIUM: ::c_int = 123;
611pub const EMEDIUMTYPE: ::c_int = 124;
612pub const ECANCELED: ::c_int = 125;
613pub const ENOKEY: ::c_int = 126;
614pub const EKEYEXPIRED: ::c_int = 127;
615pub const EKEYREVOKED: ::c_int = 128;
616pub const EKEYREJECTED: ::c_int = 129;
617pub const EOWNERDEAD: ::c_int = 130;
618pub const ENOTRECOVERABLE: ::c_int = 131;
619pub const ERFKILL: ::c_int = 132;
620pub const EHWPOISON: ::c_int = 133;
621
622pub const EXIT_FAILURE: ::c_int = 1;
623pub const EXIT_SUCCESS: ::c_int = 0;
624
625pub const F_DUPFD: ::c_int = 0;
626pub const F_GETFD: ::c_int = 1;
627pub const F_SETFD: ::c_int = 2;
628pub const F_GETFL: ::c_int = 3;
629pub const F_SETFL: ::c_int = 4;
630pub const F_GETOWN: ::c_int = 5;
631pub const F_SETOWN: ::c_int = 6;
632pub const F_GETLK: ::c_int = 7;
633pub const F_SETLK: ::c_int = 8;
634pub const F_SETLKW: ::c_int = 9;
635pub const F_RGETLK: ::c_int = 10;
636pub const F_RSETLK: ::c_int = 11;
637pub const F_CNVT: ::c_int = 12;
638pub const F_RSETLKW: ::c_int = 13;
639pub const F_DUPFD_CLOEXEC: ::c_int = 14;
640
641pub const FD_SETSIZE: usize = 1024;
642
643// Dummy
644pub const FIOCLEX: ::c_int = 0x5451;
645
646pub const FIONBIO: ::c_int = 0x8004667e;
647pub const FIONREAD: ::c_int = 0x4004667f;
648
649pub const IP_ADD_MEMBERSHIP: ::c_int = 3;
650pub const IP_DROP_MEMBERSHIP: ::c_int = 4;
651
652pub const IP_TOS: ::c_int = 1;
653pub const IP_TTL: ::c_int = 2;
654
655pub const IP_MULTICAST_TTL: ::c_int = 5;
656pub const IP_MULTICAST_IF: ::c_int = 6;
657pub const IP_MULTICAST_LOOP: ::c_int = 7;
658
659pub const IPV6_JOIN_GROUP: ::c_int = 12;
660pub const IPV6_ADD_MEMBERSHIP: ::c_int = 12;
661pub const IPV6_LEAVE_GROUP: ::c_int = 13;
662pub const IPV6_DROP_MEMBERSHIP: ::c_int = 13;
663pub const IPV6_V6ONLY: ::c_int = 27;
664
665// Dummy
666pub const IPV6_MULTICAST_LOOP: ::c_int = 7;
667
668pub const MSG_PEEK: ::c_int = 0x01;
669pub const MSG_WAITALL: ::c_int = 0x02;
670pub const MSG_OOB: ::c_int = 0x04;
671pub const MSG_DONTWAIT: ::c_int = 0x08;
672pub const MSG_MORE: ::c_int = 0x10;
673
674pub const O_ACCMODE: ::c_int = 3;
675pub const O_RDONLY: ::c_int = 0;
676pub const O_WRONLY: ::c_int = 1;
677pub const O_RDWR: ::c_int = 2;
678pub const O_APPEND: ::c_int = 1024;
679pub const O_CREAT: ::c_int = 64;
680pub const O_EXCL: ::c_int = 128;
681pub const O_NOCTTY: ::c_int = 256;
682pub const O_NONBLOCK: ::c_int = 2048;
683pub const O_TRUNC: ::c_int = 512;
684pub const O_CLOEXEC: ::c_int = 524288;
685
686pub const POLLIN: ::c_short = 0x1;
687pub const POLLPRI: ::c_short = 0x2;
688pub const POLLOUT: ::c_short = 0x4;
689pub const POLLERR: ::c_short = 0x8;
690pub const POLLHUP: ::c_short = 0x10;
691pub const POLLNVAL: ::c_short = 0x20;
692
693pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = usize::max_value();
694pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = usize::max_value();
695pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = usize::max_value();
696
697pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0;
698pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1;
699pub const PTHREAD_STACK_MIN: ::size_t = 0;
700
701// Dummy
702pub const RTLD_DEFAULT: *mut ::c_void = 0i64 as *mut ::c_void;
703
704pub const _SC_ARG_MAX: ::c_int = 0;
705pub const _SC_CHILD_MAX: ::c_int = 1;
706pub const _SC_CLK_TCK: ::c_int = 2;
707pub const _SC_NGROUPS_MAX: ::c_int = 3;
708pub const _SC_OPEN_MAX: ::c_int = 4;
709pub const _SC_JOB_CONTROL: ::c_int = 5;
710pub const _SC_SAVED_IDS: ::c_int = 6;
711pub const _SC_VERSION: ::c_int = 7;
712pub const _SC_PAGESIZE: ::c_int = 8;
713pub const _SC_PAGE_SIZE: ::c_int = _SC_PAGESIZE;
714pub const _SC_NPROCESSORS_CONF: ::c_int = 9;
715pub const _SC_NPROCESSORS_ONLN: ::c_int = 10;
716pub const _SC_PHYS_PAGES: ::c_int = 11;
717pub const _SC_AVPHYS_PAGES: ::c_int = 12;
718pub const _SC_MQ_OPEN_MAX: ::c_int = 13;
719pub const _SC_MQ_PRIO_MAX: ::c_int = 14;
720pub const _SC_RTSIG_MAX: ::c_int = 15;
721pub const _SC_SEM_NSEMS_MAX: ::c_int = 16;
722pub const _SC_SEM_VALUE_MAX: ::c_int = 17;
723pub const _SC_SIGQUEUE_MAX: ::c_int = 18;
724pub const _SC_TIMER_MAX: ::c_int = 19;
725pub const _SC_TZNAME_MAX: ::c_int = 20;
726pub const _SC_ASYNCHRONOUS_IO: ::c_int = 21;
727pub const _SC_FSYNC: ::c_int = 22;
728pub const _SC_MAPPED_FILES: ::c_int = 23;
729pub const _SC_MEMLOCK: ::c_int = 24;
730pub const _SC_MEMLOCK_RANGE: ::c_int = 25;
731pub const _SC_MEMORY_PROTECTION: ::c_int = 26;
732pub const _SC_MESSAGE_PASSING: ::c_int = 27;
733pub const _SC_PRIORITIZED_IO: ::c_int = 28;
734pub const _SC_REALTIME_SIGNALS: ::c_int = 29;
735pub const _SC_SEMAPHORES: ::c_int = 30;
736pub const _SC_SHARED_MEMORY_OBJECTS: ::c_int = 31;
737pub const _SC_SYNCHRONIZED_IO: ::c_int = 32;
738pub const _SC_TIMERS: ::c_int = 33;
739pub const _SC_AIO_LISTIO_MAX: ::c_int = 34;
740pub const _SC_AIO_MAX: ::c_int = 35;
741pub const _SC_AIO_PRIO_DELTA_MAX: ::c_int = 36;
742pub const _SC_DELAYTIMER_MAX: ::c_int = 37;
743pub const _SC_THREAD_KEYS_MAX: ::c_int = 38;
744pub const _SC_THREAD_STACK_MIN: ::c_int = 39;
745pub const _SC_THREAD_THREADS_MAX: ::c_int = 40;
746pub const _SC_TTY_NAME_MAX: ::c_int = 41;
747pub const _SC_THREADS: ::c_int = 42;
748pub const _SC_THREAD_ATTR_STACKADDR: ::c_int = 43;
749pub const _SC_THREAD_ATTR_STACKSIZE: ::c_int = 44;
750pub const _SC_THREAD_PRIORITY_SCHEDULING: ::c_int = 45;
751pub const _SC_THREAD_PRIO_INHERIT: ::c_int = 46;
752pub const _SC_THREAD_PRIO_PROTECT: ::c_int = 47;
753pub const _SC_THREAD_PRIO_CEILING: ::c_int = _SC_THREAD_PRIO_PROTECT;
754pub const _SC_THREAD_PROCESS_SHARED: ::c_int = 48;
755pub const _SC_THREAD_SAFE_FUNCTIONS: ::c_int = 49;
756pub const _SC_GETGR_R_SIZE_MAX: ::c_int = 50;
757pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 51;
758pub const _SC_LOGIN_NAME_MAX: ::c_int = 52;
759pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: ::c_int = 53;
760pub const _SC_ADVISORY_INFO: ::c_int = 54;
761pub const _SC_ATEXIT_MAX: ::c_int = 55;
762pub const _SC_BARRIERS: ::c_int = 56;
763pub const _SC_BC_BASE_MAX: ::c_int = 57;
764pub const _SC_BC_DIM_MAX: ::c_int = 58;
765pub const _SC_BC_SCALE_MAX: ::c_int = 59;
766pub const _SC_BC_STRING_MAX: ::c_int = 60;
767pub const _SC_CLOCK_SELECTION: ::c_int = 61;
768pub const _SC_COLL_WEIGHTS_MAX: ::c_int = 62;
769pub const _SC_CPUTIME: ::c_int = 63;
770pub const _SC_EXPR_NEST_MAX: ::c_int = 64;
771pub const _SC_HOST_NAME_MAX: ::c_int = 65;
772pub const _SC_IOV_MAX: ::c_int = 66;
773pub const _SC_IPV6: ::c_int = 67;
774pub const _SC_LINE_MAX: ::c_int = 68;
775pub const _SC_MONOTONIC_CLOCK: ::c_int = 69;
776pub const _SC_RAW_SOCKETS: ::c_int = 70;
777pub const _SC_READER_WRITER_LOCKS: ::c_int = 71;
778pub const _SC_REGEXP: ::c_int = 72;
779pub const _SC_RE_DUP_MAX: ::c_int = 73;
780pub const _SC_SHELL: ::c_int = 74;
781pub const _SC_SPAWN: ::c_int = 75;
782pub const _SC_SPIN_LOCKS: ::c_int = 76;
783pub const _SC_SPORADIC_SERVER: ::c_int = 77;
784pub const _SC_SS_REPL_MAX: ::c_int = 78;
785pub const _SC_SYMLOOP_MAX: ::c_int = 79;
786pub const _SC_THREAD_CPUTIME: ::c_int = 80;
787pub const _SC_THREAD_SPORADIC_SERVER: ::c_int = 81;
788pub const _SC_TIMEOUTS: ::c_int = 82;
789pub const _SC_TRACE: ::c_int = 83;
790pub const _SC_TRACE_EVENT_FILTER: ::c_int = 84;
791pub const _SC_TRACE_EVENT_NAME_MAX: ::c_int = 85;
792pub const _SC_TRACE_INHERIT: ::c_int = 86;
793pub const _SC_TRACE_LOG: ::c_int = 87;
794pub const _SC_TRACE_NAME_MAX: ::c_int = 88;
795pub const _SC_TRACE_SYS_MAX: ::c_int = 89;
796pub const _SC_TRACE_USER_EVENT_MAX: ::c_int = 90;
797pub const _SC_TYPED_MEMORY_OBJECTS: ::c_int = 91;
798pub const _SC_V7_ILP32_OFF32: ::c_int = 92;
799pub const _SC_V6_ILP32_OFF32: ::c_int = _SC_V7_ILP32_OFF32;
800pub const _SC_XBS5_ILP32_OFF32: ::c_int = _SC_V7_ILP32_OFF32;
801pub const _SC_V7_ILP32_OFFBIG: ::c_int = 93;
802pub const _SC_V6_ILP32_OFFBIG: ::c_int = _SC_V7_ILP32_OFFBIG;
803pub const _SC_XBS5_ILP32_OFFBIG: ::c_int = _SC_V7_ILP32_OFFBIG;
804pub const _SC_V7_LP64_OFF64: ::c_int = 94;
805pub const _SC_V6_LP64_OFF64: ::c_int = _SC_V7_LP64_OFF64;
806pub const _SC_XBS5_LP64_OFF64: ::c_int = _SC_V7_LP64_OFF64;
807pub const _SC_V7_LPBIG_OFFBIG: ::c_int = 95;
808pub const _SC_V6_LPBIG_OFFBIG: ::c_int = _SC_V7_LPBIG_OFFBIG;
809pub const _SC_XBS5_LPBIG_OFFBIG: ::c_int = _SC_V7_LPBIG_OFFBIG;
810pub const _SC_XOPEN_CRYPT: ::c_int = 96;
811pub const _SC_XOPEN_ENH_I18N: ::c_int = 97;
812pub const _SC_XOPEN_LEGACY: ::c_int = 98;
813pub const _SC_XOPEN_REALTIME: ::c_int = 99;
814pub const _SC_STREAM_MAX: ::c_int = 100;
815pub const _SC_PRIORITY_SCHEDULING: ::c_int = 101;
816pub const _SC_XOPEN_REALTIME_THREADS: ::c_int = 102;
817pub const _SC_XOPEN_SHM: ::c_int = 103;
818pub const _SC_XOPEN_STREAMS: ::c_int = 104;
819pub const _SC_XOPEN_UNIX: ::c_int = 105;
820pub const _SC_XOPEN_VERSION: ::c_int = 106;
821pub const _SC_2_CHAR_TERM: ::c_int = 107;
822pub const _SC_2_C_BIND: ::c_int = 108;
823pub const _SC_2_C_DEV: ::c_int = 109;
824pub const _SC_2_FORT_DEV: ::c_int = 110;
825pub const _SC_2_FORT_RUN: ::c_int = 111;
826pub const _SC_2_LOCALEDEF: ::c_int = 112;
827pub const _SC_2_PBS: ::c_int = 113;
828pub const _SC_2_PBS_ACCOUNTING: ::c_int = 114;
829pub const _SC_2_PBS_CHECKPOINT: ::c_int = 115;
830pub const _SC_2_PBS_LOCATE: ::c_int = 116;
831pub const _SC_2_PBS_MESSAGE: ::c_int = 117;
832pub const _SC_2_PBS_TRACK: ::c_int = 118;
833pub const _SC_2_SW_DEV: ::c_int = 119;
834pub const _SC_2_UPE: ::c_int = 120;
835pub const _SC_2_VERSION: ::c_int = 121;
836pub const _SC_THREAD_ROBUST_PRIO_INHERIT: ::c_int = 122;
837pub const _SC_THREAD_ROBUST_PRIO_PROTECT: ::c_int = 123;
838pub const _SC_XOPEN_UUCP: ::c_int = 124;
839pub const _SC_LEVEL1_ICACHE_SIZE: ::c_int = 125;
840pub const _SC_LEVEL1_ICACHE_ASSOC: ::c_int = 126;
841pub const _SC_LEVEL1_ICACHE_LINESIZE: ::c_int = 127;
842pub const _SC_LEVEL1_DCACHE_SIZE: ::c_int = 128;
843pub const _SC_LEVEL1_DCACHE_ASSOC: ::c_int = 129;
844pub const _SC_LEVEL1_DCACHE_LINESIZE: ::c_int = 130;
845pub const _SC_LEVEL2_CACHE_SIZE: ::c_int = 131;
846pub const _SC_LEVEL2_CACHE_ASSOC: ::c_int = 132;
847pub const _SC_LEVEL2_CACHE_LINESIZE: ::c_int = 133;
848pub const _SC_LEVEL3_CACHE_SIZE: ::c_int = 134;
849pub const _SC_LEVEL3_CACHE_ASSOC: ::c_int = 135;
850pub const _SC_LEVEL3_CACHE_LINESIZE: ::c_int = 136;
851pub const _SC_LEVEL4_CACHE_SIZE: ::c_int = 137;
852pub const _SC_LEVEL4_CACHE_ASSOC: ::c_int = 138;
853pub const _SC_LEVEL4_CACHE_LINESIZE: ::c_int = 139;
854
855pub const S_BLKSIZE: ::mode_t = 1024;
856pub const S_IREAD: ::mode_t = 256;
857pub const S_IWRITE: ::mode_t = 128;
858pub const S_IEXEC: ::mode_t = 64;
859pub const S_ENFMT: ::mode_t = 1024;
860pub const S_IFMT: ::mode_t = 61440;
861pub const S_IFDIR: ::mode_t = 16384;
862pub const S_IFCHR: ::mode_t = 8192;
863pub const S_IFBLK: ::mode_t = 24576;
864pub const S_IFREG: ::mode_t = 32768;
865pub const S_IFLNK: ::mode_t = 40960;
866pub const S_IFSOCK: ::mode_t = 49152;
867pub const S_IFIFO: ::mode_t = 4096;
868pub const S_IRUSR: ::mode_t = 256;
869pub const S_IWUSR: ::mode_t = 128;
870pub const S_IXUSR: ::mode_t = 64;
871pub const S_IRGRP: ::mode_t = 32;
872pub const S_IWGRP: ::mode_t = 16;
873pub const S_IXGRP: ::mode_t = 8;
874pub const S_IROTH: ::mode_t = 4;
875pub const S_IWOTH: ::mode_t = 2;
876pub const S_IXOTH: ::mode_t = 1;
877
878pub const SEEK_SET: ::c_int = 0;
879pub const SEEK_CUR: ::c_int = 1;
880pub const SEEK_END: ::c_int = 2;
881
882pub const SHUT_RD: ::c_int = 0;
883pub const SHUT_WR: ::c_int = 1;
884pub const SHUT_RDWR: ::c_int = 2;
885
886pub const SIG_SETMASK: ::c_int = 0;
887
888pub const SIGHUP: ::c_int = 1;
889pub const SIGINT: ::c_int = 2;
890pub const SIGQUIT: ::c_int = 3;
891pub const SIGILL: ::c_int = 4;
892pub const SIGABRT: ::c_int = 6;
893pub const SIGEMT: ::c_int = 7;
894pub const SIGFPE: ::c_int = 8;
895pub const SIGKILL: ::c_int = 9;
896pub const SIGSEGV: ::c_int = 11;
897pub const SIGPIPE: ::c_int = 13;
898pub const SIGALRM: ::c_int = 14;
899pub const SIGTERM: ::c_int = 15;
900
901pub const SO_DEBUG: ::c_int = 0x0001;
902pub const SO_ACCEPTCONN: ::c_int = 0x0002;
903pub const SO_REUSEADDR: ::c_int = 0x0004;
904pub const SO_KEEPALIVE: ::c_int = 0x0008;
905pub const SO_DONTROUTE: ::c_int = 0x0010;
906pub const SO_BROADCAST: ::c_int = 0x0020;
907pub const SO_USELOOPBACK: ::c_int = 0x0040;
908pub const SO_LINGER: ::c_int = 0x0080;
909pub const SO_OOBINLINE: ::c_int = 0x0100;
910pub const SO_REUSEPORT: ::c_int = 0x0200;
911pub const SO_SNDBUF: ::c_int = 0x1001;
912pub const SO_RCVBUF: ::c_int = 0x1002;
913pub const SO_SNDLOWAT: ::c_int = 0x1003;
914pub const SO_RCVLOWAT: ::c_int = 0x1004;
915pub const SO_SNDTIMEO: ::c_int = 0x1005;
916pub const SO_RCVTIMEO: ::c_int = 0x1006;
917pub const SO_ERROR: ::c_int = 0x1007;
918pub const SO_TYPE: ::c_int = 0x1008;
919pub const SO_CONTIMEO: ::c_int = 0x1009;
920pub const SO_NO_CHECK: ::c_int = 0x100a;
921
922pub const SOCK_STREAM: ::c_int = 1;
923pub const SOCK_DGRAM: ::c_int = 2;
924pub const SOCK_RAW: ::c_int = 3;
925
926pub const SOL_SOCKET: ::c_int = 0xfff;
927
928pub const STDIN_FILENO: ::c_int = 0;
929pub const STDOUT_FILENO: ::c_int = 1;
930pub const STDERR_FILENO: ::c_int = 2;
931
932pub const TCP_NODELAY: ::c_int = 0x01;
933pub const TCP_KEEPALIVE: ::c_int = 0x02;
934pub const TCP_KEEPIDLE: ::c_int = 0x03;
935pub const TCP_KEEPINTVL: ::c_int = 0x04;
936pub const TCP_KEEPCNT: ::c_int = 0x05;
937
938const ULONG_SIZE: usize = 64;
939
940pub const WNOHANG: ::c_int = 0x00000001;
941
942pub const PRIO_PROCESS: ::c_int = 0;
943pub const PRIO_PGRP: ::c_int = 1;
944pub const PRIO_USER: ::c_int = 2;
945
946safe_f! {
947    pub {const} fn WEXITSTATUS(status: ::c_int) -> ::c_int {
948        (status >> 8) & 0xff
949    }
950
951    pub {const} fn WIFEXITED(status: ::c_int) -> bool {
952        (status & 0xff) == 0
953    }
954
955    pub {const} fn WTERMSIG(status: ::c_int) -> ::c_int {
956        status & 0x7f
957    }
958}
959
960extern "C" {
961    pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int;
962    pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int;
963    pub fn strerror_r(errnum: ::c_int, buf: *mut c_char, buflen: ::size_t) -> ::c_int;
964
965    pub fn sem_destroy(sem: *mut sem_t) -> ::c_int;
966    pub fn sem_init(sem: *mut sem_t, pshared: ::c_int, value: ::c_uint) -> ::c_int;
967
968    pub fn abs(i: ::c_int) -> ::c_int;
969    pub fn labs(i: ::c_long) -> ::c_long;
970    pub fn rand() -> ::c_int;
971    pub fn srand(seed: ::c_uint);
972
973    pub fn bind(s: ::c_int, name: *const ::sockaddr, namelen: ::socklen_t) -> ::c_int;
974
975    pub fn clock_gettime(clock_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int;
976
977    pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int;
978    pub fn getpwuid_r(
979        uid: ::uid_t,
980        pwd: *mut passwd,
981        buf: *mut ::c_char,
982        buflen: ::size_t,
983        result: *mut *mut passwd,
984    ) -> ::c_int;
985
986    // Dummy
987    pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int;
988
989    pub fn memalign(align: ::size_t, nbytes: ::size_t) -> *mut ::c_void;
990
991    pub fn pthread_create(
992        tid: *mut ::pthread_t,
993        attr: *const ::pthread_attr_t,
994        start: extern "C" fn(*mut ::c_void) -> *mut ::c_void,
995        arg: *mut ::c_void,
996    ) -> ::c_int;
997
998    pub fn pthread_sigmask(how: ::c_int, set: *const ::sigset_t, oset: *mut ::sigset_t) -> ::c_int;
999
1000    pub fn recvfrom(
1001        s: ::c_int,
1002        mem: *mut ::c_void,
1003        len: ::size_t,
1004        flags: ::c_int,
1005        from: *mut ::sockaddr,
1006        fromlen: *mut ::socklen_t,
1007    ) -> ::c_int;
1008
1009    pub fn setgroups(ngroups: ::c_int, grouplist: *const ::gid_t) -> ::c_int;
1010    pub fn uname(buf: *mut ::utsname) -> ::c_int;
1011}
1012
1013cfg_if! {
1014    if #[cfg(target_arch = "aarch64")] {
1015        mod aarch64;
1016        pub use self::aarch64::*;
1017    } else if #[cfg(target_arch = "x86_64")] {
1018        mod x86_64;
1019        pub use self::x86_64::*;
1020    } else {
1021        // Unknown target_arch
1022    }
1023}
1024