interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / libc / src / unix / newlib / mod.rs

975 lines · 30360 bytes Raw Blame History
1use crate::prelude::*;
2
3pub type blkcnt_t = i32;
4pub type blksize_t = i32;
5
6pub type clockid_t = c_ulong;
7
8cfg_if! {
9 if #[cfg(any(target_os = "espidf"))] {
10 pub type dev_t = c_short;
11 pub type ino_t = c_ushort;
12 pub type off_t = c_long;
13 } else if #[cfg(any(target_os = "vita"))] {
14 pub type dev_t = c_short;
15 pub type ino_t = c_ushort;
16 pub type off_t = c_int;
17 } else {
18 pub type dev_t = u32;
19 pub type ino_t = u32;
20 pub type off_t = i64;
21 }
22}
23
24pub type fsblkcnt_t = u64;
25pub type fsfilcnt_t = u32;
26pub type id_t = u32;
27pub type key_t = c_int;
28pub type loff_t = c_longlong;
29pub type mode_t = c_uint;
30pub type nfds_t = u32;
31pub type nlink_t = c_ushort;
32pub type pthread_t = c_ulong;
33pub type pthread_key_t = c_uint;
34pub type rlim_t = u32;
35
36cfg_if! {
37 if #[cfg(target_os = "horizon")] {
38 pub type sa_family_t = u16;
39 } else {
40 pub type sa_family_t = u8;
41 }
42}
43
44pub type socklen_t = u32;
45pub type speed_t = u32;
46pub type suseconds_t = i32;
47cfg_if! {
48 if #[cfg(target_os = "espidf")] {
49 pub type tcflag_t = u16;
50 } else {
51 pub type tcflag_t = c_uint;
52 }
53}
54pub type useconds_t = u32;
55
56cfg_if! {
57 if #[cfg(any(
58 target_os = "horizon",
59 all(target_os = "espidf", not(espidf_time32))
60 ))] {
61 pub type time_t = c_longlong;
62 } else {
63 pub type time_t = i32;
64 }
65}
66
67s! {
68 // The order of the `ai_addr` field in this struct is crucial
69 // for converting between the Rust and C types.
70 pub struct addrinfo {
71 pub ai_flags: c_int,
72 pub ai_family: c_int,
73 pub ai_socktype: c_int,
74 pub ai_protocol: c_int,
75 pub ai_addrlen: socklen_t,
76
77 #[cfg(target_os = "espidf")]
78 pub ai_addr: *mut sockaddr,
79
80 pub ai_canonname: *mut c_char,
81
82 #[cfg(not(any(
83 target_os = "espidf",
84 all(target_arch = "powerpc", target_vendor = "nintendo")
85 )))]
86 pub ai_addr: *mut sockaddr,
87
88 pub ai_next: *mut addrinfo,
89 }
90
91 pub struct ip_mreq {
92 pub imr_multiaddr: in_addr,
93 pub imr_interface: in_addr,
94 }
95
96 pub struct in_addr {
97 pub s_addr: crate::in_addr_t,
98 }
99
100 pub struct lconv {
101 pub decimal_point: *mut c_char,
102 pub thousands_sep: *mut c_char,
103 pub grouping: *mut c_char,
104 pub int_curr_symbol: *mut c_char,
105 pub currency_symbol: *mut c_char,
106 pub mon_decimal_point: *mut c_char,
107 pub mon_thousands_sep: *mut c_char,
108 pub mon_grouping: *mut c_char,
109 pub positive_sign: *mut c_char,
110 pub negative_sign: *mut c_char,
111 pub int_frac_digits: c_char,
112 pub frac_digits: c_char,
113 pub p_cs_precedes: c_char,
114 pub p_sep_by_space: c_char,
115 pub n_cs_precedes: c_char,
116 pub n_sep_by_space: c_char,
117 pub p_sign_posn: c_char,
118 pub n_sign_posn: c_char,
119 pub int_n_cs_precedes: c_char,
120 pub int_n_sep_by_space: c_char,
121 pub int_n_sign_posn: c_char,
122 pub int_p_cs_precedes: c_char,
123 pub int_p_sep_by_space: c_char,
124 pub int_p_sign_posn: c_char,
125 }
126
127 pub struct tm {
128 pub tm_sec: c_int,
129 pub tm_min: c_int,
130 pub tm_hour: c_int,
131 pub tm_mday: c_int,
132 pub tm_mon: c_int,
133 pub tm_year: c_int,
134 pub tm_wday: c_int,
135 pub tm_yday: c_int,
136 pub tm_isdst: c_int,
137 }
138
139 pub struct statvfs {
140 pub f_bsize: c_ulong,
141 pub f_frsize: c_ulong,
142 pub f_blocks: fsblkcnt_t,
143 pub f_bfree: fsblkcnt_t,
144 pub f_bavail: fsblkcnt_t,
145 pub f_files: fsfilcnt_t,
146 pub f_ffree: fsfilcnt_t,
147 pub f_favail: fsfilcnt_t,
148 pub f_fsid: c_ulong,
149 pub f_flag: c_ulong,
150 pub f_namemax: c_ulong,
151 }
152
153 // FIXME(1.0): This should not implement `PartialEq`
154 #[allow(unpredictable_function_pointer_comparisons)]
155 pub struct sigaction {
156 pub sa_handler: extern "C" fn(arg1: c_int),
157 pub sa_mask: sigset_t,
158 pub sa_flags: c_int,
159 }
160
161 pub struct stack_t {
162 pub ss_sp: *mut c_void,
163 pub ss_flags: c_int,
164 pub ss_size: usize,
165 }
166
167 pub struct fd_set {
168 // Unverified
169 fds_bits: [c_ulong; FD_SETSIZE as usize / ULONG_SIZE],
170 }
171
172 pub struct passwd {
173 // Unverified
174 pub pw_name: *mut c_char,
175 pub pw_passwd: *mut c_char,
176 pub pw_uid: crate::uid_t,
177 pub pw_gid: crate::gid_t,
178 pub pw_gecos: *mut c_char,
179 pub pw_dir: *mut c_char,
180 pub pw_shell: *mut c_char,
181 }
182
183 pub struct termios {
184 // Unverified
185 pub c_iflag: crate::tcflag_t,
186 pub c_oflag: crate::tcflag_t,
187 pub c_cflag: crate::tcflag_t,
188 pub c_lflag: crate::tcflag_t,
189 pub c_line: crate::cc_t,
190 pub c_cc: [crate::cc_t; crate::NCCS],
191 #[cfg(target_os = "espidf")]
192 pub c_ispeed: u32,
193 #[cfg(target_os = "espidf")]
194 pub c_ospeed: u32,
195 }
196
197 pub struct sem_t {
198 // Unverified
199 __size: [c_char; 16],
200 }
201
202 pub struct Dl_info {
203 // Unverified
204 pub dli_fname: *const c_char,
205 pub dli_fbase: *mut c_void,
206 pub dli_sname: *const c_char,
207 pub dli_saddr: *mut c_void,
208 }
209
210 pub struct utsname {
211 // Unverified
212 pub sysname: [c_char; 65],
213 pub nodename: [c_char; 65],
214 pub release: [c_char; 65],
215 pub version: [c_char; 65],
216 pub machine: [c_char; 65],
217 pub domainname: [c_char; 65],
218 }
219
220 pub struct cpu_set_t {
221 // Unverified
222 bits: [u32; 32],
223 }
224
225 pub struct pthread_attr_t {
226 // Unverified
227 #[cfg(not(target_os = "espidf"))]
228 __size: [u8; __SIZEOF_PTHREAD_ATTR_T],
229 #[cfg(target_os = "espidf")]
230 pub is_initialized: i32,
231 #[cfg(target_os = "espidf")]
232 pub stackaddr: *mut c_void,
233 #[cfg(target_os = "espidf")]
234 pub stacksize: i32,
235 #[cfg(target_os = "espidf")]
236 pub contentionscope: i32,
237 #[cfg(target_os = "espidf")]
238 pub inheritsched: i32,
239 #[cfg(target_os = "espidf")]
240 pub schedpolicy: i32,
241 #[cfg(target_os = "espidf")]
242 pub schedparam: i32,
243 #[cfg(target_os = "espidf")]
244 pub detachstate: i32,
245 }
246
247 pub struct pthread_rwlockattr_t {
248 // Unverified
249 __size: [u8; __SIZEOF_PTHREAD_RWLOCKATTR_T],
250 }
251
252 #[cfg_attr(
253 all(
254 target_pointer_width = "32",
255 any(target_arch = "mips", target_arch = "arm", target_arch = "powerpc")
256 ),
257 repr(align(4))
258 )]
259 #[cfg_attr(
260 any(
261 target_pointer_width = "64",
262 not(any(target_arch = "mips", target_arch = "arm", target_arch = "powerpc"))
263 ),
264 repr(align(8))
265 )]
266 pub struct pthread_mutex_t {
267 // Unverified
268 size: [u8; crate::__SIZEOF_PTHREAD_MUTEX_T],
269 }
270
271 #[cfg_attr(
272 all(
273 target_pointer_width = "32",
274 any(target_arch = "mips", target_arch = "arm", target_arch = "powerpc")
275 ),
276 repr(align(4))
277 )]
278 #[cfg_attr(
279 any(
280 target_pointer_width = "64",
281 not(any(target_arch = "mips", target_arch = "arm", target_arch = "powerpc"))
282 ),
283 repr(align(8))
284 )]
285 pub struct pthread_rwlock_t {
286 // Unverified
287 size: [u8; crate::__SIZEOF_PTHREAD_RWLOCK_T],
288 }
289
290 #[cfg_attr(
291 any(
292 target_pointer_width = "32",
293 target_arch = "x86_64",
294 target_arch = "powerpc64",
295 target_arch = "mips64",
296 target_arch = "s390x",
297 target_arch = "sparc64"
298 ),
299 repr(align(4))
300 )]
301 #[cfg_attr(
302 not(any(
303 target_pointer_width = "32",
304 target_arch = "x86_64",
305 target_arch = "powerpc64",
306 target_arch = "mips64",
307 target_arch = "s390x",
308 target_arch = "sparc64"
309 )),
310 repr(align(8))
311 )]
312 pub struct pthread_mutexattr_t {
313 // Unverified
314 size: [u8; crate::__SIZEOF_PTHREAD_MUTEXATTR_T],
315 }
316
317 #[repr(align(8))]
318 pub struct pthread_cond_t {
319 // Unverified
320 size: [u8; crate::__SIZEOF_PTHREAD_COND_T],
321 }
322
323 #[repr(align(4))]
324 pub struct pthread_condattr_t {
325 // Unverified
326 size: [u8; crate::__SIZEOF_PTHREAD_CONDATTR_T],
327 }
328}
329
330// unverified constants
331pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
332 size: [__PTHREAD_INITIALIZER_BYTE; __SIZEOF_PTHREAD_MUTEX_T],
333};
334pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
335 size: [__PTHREAD_INITIALIZER_BYTE; __SIZEOF_PTHREAD_COND_T],
336};
337pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
338 size: [__PTHREAD_INITIALIZER_BYTE; __SIZEOF_PTHREAD_RWLOCK_T],
339};
340
341cfg_if! {
342 if #[cfg(target_os = "espidf")] {
343 pub const NCCS: usize = 11;
344 } else {
345 pub const NCCS: usize = 32;
346 }
347}
348
349cfg_if! {
350 if #[cfg(target_os = "espidf")] {
351 const __PTHREAD_INITIALIZER_BYTE: u8 = 0xff;
352 pub const __SIZEOF_PTHREAD_ATTR_T: usize = 32;
353 pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 4;
354 pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 12;
355 pub const __SIZEOF_PTHREAD_COND_T: usize = 4;
356 pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 8;
357 pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 4;
358 pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 12;
359 pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;
360 } else if #[cfg(target_os = "vita")] {
361 const __PTHREAD_INITIALIZER_BYTE: u8 = 0xff;
362 pub const __SIZEOF_PTHREAD_ATTR_T: usize = 4;
363 pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 4;
364 pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
365 pub const __SIZEOF_PTHREAD_COND_T: usize = 4;
366 pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
367 pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 4;
368 pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 4;
369 pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 4;
370 } else if #[cfg(target_os = "rtems")] {
371 const __PTHREAD_INITIALIZER_BYTE: u8 = 0x00;
372 pub const __SIZEOF_PTHREAD_ATTR_T: usize = 96;
373 pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 64;
374 pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 24;
375 pub const __SIZEOF_PTHREAD_COND_T: usize = 28;
376 pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 24;
377 pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32;
378 pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
379 pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;
380 } else {
381 const __PTHREAD_INITIALIZER_BYTE: u8 = 0;
382 pub const __SIZEOF_PTHREAD_ATTR_T: usize = 56;
383 pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
384 pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
385 pub const __SIZEOF_PTHREAD_COND_T: usize = 48;
386 pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
387 pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
388 pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
389 pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;
390 }
391}
392
393pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;
394pub const __PTHREAD_MUTEX_HAVE_PREV: usize = 1;
395pub const __PTHREAD_RWLOCK_INT_FLAGS_SHARED: usize = 1;
396pub const PTHREAD_MUTEX_NORMAL: c_int = 0;
397pub const PTHREAD_MUTEX_RECURSIVE: c_int = 1;
398pub const PTHREAD_MUTEX_ERRORCHECK: c_int = 2;
399
400cfg_if! {
401 if #[cfg(any(target_os = "horizon", target_os = "espidf"))] {
402 pub const FD_SETSIZE: usize = 64;
403 } else if #[cfg(target_os = "vita")] {
404 pub const FD_SETSIZE: usize = 256;
405 } else {
406 pub const FD_SETSIZE: usize = 1024;
407 }
408}
409// intentionally not public, only used for fd_set
410const ULONG_SIZE: usize = 32;
411
412// Other constants
413pub const EPERM: c_int = 1;
414pub const ENOENT: c_int = 2;
415pub const ESRCH: c_int = 3;
416pub const EINTR: c_int = 4;
417pub const EIO: c_int = 5;
418pub const ENXIO: c_int = 6;
419pub const E2BIG: c_int = 7;
420pub const ENOEXEC: c_int = 8;
421pub const EBADF: c_int = 9;
422pub const ECHILD: c_int = 10;
423pub const EAGAIN: c_int = 11;
424pub const ENOMEM: c_int = 12;
425pub const EACCES: c_int = 13;
426pub const EFAULT: c_int = 14;
427pub const EBUSY: c_int = 16;
428pub const EEXIST: c_int = 17;
429pub const EXDEV: c_int = 18;
430pub const ENODEV: c_int = 19;
431pub const ENOTDIR: c_int = 20;
432pub const EISDIR: c_int = 21;
433pub const EINVAL: c_int = 22;
434pub const ENFILE: c_int = 23;
435pub const EMFILE: c_int = 24;
436pub const ENOTTY: c_int = 25;
437pub const ETXTBSY: c_int = 26;
438pub const EFBIG: c_int = 27;
439pub const ENOSPC: c_int = 28;
440pub const ESPIPE: c_int = 29;
441pub const EROFS: c_int = 30;
442pub const EMLINK: c_int = 31;
443pub const EPIPE: c_int = 32;
444pub const EDOM: c_int = 33;
445pub const ERANGE: c_int = 34;
446pub const ENOMSG: c_int = 35;
447pub const EIDRM: c_int = 36;
448pub const EDEADLK: c_int = 45;
449pub const ENOLCK: c_int = 46;
450pub const ENOSTR: c_int = 60;
451pub const ENODATA: c_int = 61;
452pub const ETIME: c_int = 62;
453pub const ENOSR: c_int = 63;
454pub const ENOLINK: c_int = 67;
455pub const EPROTO: c_int = 71;
456pub const EMULTIHOP: c_int = 74;
457pub const EBADMSG: c_int = 77;
458pub const EFTYPE: c_int = 79;
459pub const ENOSYS: c_int = 88;
460pub const ENOTEMPTY: c_int = 90;
461pub const ENAMETOOLONG: c_int = 91;
462pub const ELOOP: c_int = 92;
463pub const EOPNOTSUPP: c_int = 95;
464pub const EPFNOSUPPORT: c_int = 96;
465pub const ECONNRESET: c_int = 104;
466pub const ENOBUFS: c_int = 105;
467pub const EAFNOSUPPORT: c_int = 106;
468pub const EPROTOTYPE: c_int = 107;
469pub const ENOTSOCK: c_int = 108;
470pub const ENOPROTOOPT: c_int = 109;
471pub const ECONNREFUSED: c_int = 111;
472pub const EADDRINUSE: c_int = 112;
473pub const ECONNABORTED: c_int = 113;
474pub const ENETUNREACH: c_int = 114;
475pub const ENETDOWN: c_int = 115;
476pub const ETIMEDOUT: c_int = 116;
477pub const EHOSTDOWN: c_int = 117;
478pub const EHOSTUNREACH: c_int = 118;
479pub const EINPROGRESS: c_int = 119;
480pub const EALREADY: c_int = 120;
481pub const EDESTADDRREQ: c_int = 121;
482pub const EMSGSIZE: c_int = 122;
483pub const EPROTONOSUPPORT: c_int = 123;
484pub const EADDRNOTAVAIL: c_int = 125;
485pub const ENETRESET: c_int = 126;
486pub const EISCONN: c_int = 127;
487pub const ENOTCONN: c_int = 128;
488pub const ETOOMANYREFS: c_int = 129;
489pub const EDQUOT: c_int = 132;
490pub const ESTALE: c_int = 133;
491pub const ENOTSUP: c_int = 134;
492pub const EILSEQ: c_int = 138;
493pub const EOVERFLOW: c_int = 139;
494pub const ECANCELED: c_int = 140;
495pub const ENOTRECOVERABLE: c_int = 141;
496pub const EOWNERDEAD: c_int = 142;
497pub const EWOULDBLOCK: c_int = 11;
498
499pub const F_DUPFD: c_int = 0;
500pub const F_GETFD: c_int = 1;
501pub const F_SETFD: c_int = 2;
502pub const F_GETFL: c_int = 3;
503pub const F_SETFL: c_int = 4;
504pub const F_GETOWN: c_int = 5;
505pub const F_SETOWN: c_int = 6;
506pub const F_GETLK: c_int = 7;
507pub const F_SETLK: c_int = 8;
508pub const F_SETLKW: c_int = 9;
509pub const F_RGETLK: c_int = 10;
510pub const F_RSETLK: c_int = 11;
511pub const F_CNVT: c_int = 12;
512pub const F_RSETLKW: c_int = 13;
513pub const F_DUPFD_CLOEXEC: c_int = 14;
514
515pub const O_RDONLY: c_int = 0;
516pub const O_WRONLY: c_int = 1;
517pub const O_RDWR: c_int = 2;
518cfg_if! {
519 if #[cfg(espidf_picolibc)] {
520 pub const O_APPEND: c_int = 1024;
521 pub const O_CREAT: c_int = 64;
522 pub const O_TRUNC: c_int = 512;
523 } else {
524 pub const O_APPEND: c_int = 8;
525 pub const O_CREAT: c_int = 512;
526 pub const O_TRUNC: c_int = 1024;
527 }
528}
529pub const O_EXCL: c_int = 2048;
530pub const O_SYNC: c_int = 8192;
531pub const O_NONBLOCK: c_int = 16384;
532
533pub const O_ACCMODE: c_int = 3;
534cfg_if! {
535 if #[cfg(target_os = "espidf")] {
536 pub const O_CLOEXEC: c_int = 0x40000;
537 } else {
538 pub const O_CLOEXEC: c_int = 0x80000;
539 }
540}
541
542pub const RTLD_LAZY: c_int = 0x1;
543
544pub const SEEK_SET: c_int = 0;
545pub const SEEK_CUR: c_int = 1;
546pub const SEEK_END: c_int = 2;
547
548pub const FIOCLEX: c_ulong = 0x20006601;
549pub const FIONCLEX: c_ulong = 0x20006602;
550
551pub const S_BLKSIZE: mode_t = 1024;
552pub const S_IREAD: mode_t = 0o0400;
553pub const S_IWRITE: mode_t = 0o0200;
554pub const S_IEXEC: mode_t = 0o0100;
555pub const S_ENFMT: mode_t = 0o2000;
556pub const S_IFMT: mode_t = 0o17_0000;
557pub const S_IFDIR: mode_t = 0o4_0000;
558pub const S_IFCHR: mode_t = 0o2_0000;
559pub const S_IFBLK: mode_t = 0o6_0000;
560pub const S_IFREG: mode_t = 0o10_0000;
561pub const S_IFLNK: mode_t = 0o12_0000;
562pub const S_IFSOCK: mode_t = 0o14_0000;
563pub const S_IFIFO: mode_t = 0o1_0000;
564pub const S_IRUSR: mode_t = 0o0400;
565pub const S_IWUSR: mode_t = 0o0200;
566pub const S_IXUSR: mode_t = 0o0100;
567pub const S_IRGRP: mode_t = 0o0040;
568pub const S_IWGRP: mode_t = 0o0020;
569pub const S_IXGRP: mode_t = 0o0010;
570pub const S_IROTH: mode_t = 0o0004;
571pub const S_IWOTH: mode_t = 0o0002;
572pub const S_IXOTH: mode_t = 0o0001;
573
574pub const SOL_TCP: c_int = 6;
575
576pub const PF_UNSPEC: c_int = 0;
577pub const PF_INET: c_int = 2;
578cfg_if! {
579 if #[cfg(target_os = "espidf")] {
580 pub const PF_INET6: c_int = 10;
581 } else {
582 pub const PF_INET6: c_int = 23;
583 }
584}
585
586pub const AF_UNSPEC: c_int = 0;
587pub const AF_INET: c_int = 2;
588
589pub const CLOCK_REALTIME: crate::clockid_t = 1;
590pub const CLOCK_MONOTONIC: crate::clockid_t = 4;
591pub const CLOCK_BOOTTIME: crate::clockid_t = 4;
592
593pub const SOCK_STREAM: c_int = 1;
594pub const SOCK_DGRAM: c_int = 2;
595
596pub const SHUT_RD: c_int = 0;
597pub const SHUT_WR: c_int = 1;
598pub const SHUT_RDWR: c_int = 2;
599
600pub const SO_BINTIME: c_int = 0x2000;
601pub const SO_NO_OFFLOAD: c_int = 0x4000;
602pub const SO_NO_DDP: c_int = 0x8000;
603pub const SO_REUSEPORT_LB: c_int = 0x10000;
604pub const SO_LABEL: c_int = 0x1009;
605pub const SO_PEERLABEL: c_int = 0x1010;
606pub const SO_LISTENQLIMIT: c_int = 0x1011;
607pub const SO_LISTENQLEN: c_int = 0x1012;
608pub const SO_LISTENINCQLEN: c_int = 0x1013;
609pub const SO_SETFIB: c_int = 0x1014;
610pub const SO_USER_COOKIE: c_int = 0x1015;
611pub const SO_PROTOCOL: c_int = 0x1016;
612pub const SO_PROTOTYPE: c_int = SO_PROTOCOL;
613pub const SO_VENDOR: c_int = u32_cast_int(0x80000000);
614pub const SO_DEBUG: c_int = 0x01;
615pub const SO_ACCEPTCONN: c_int = 0x0002;
616pub const SO_REUSEADDR: c_int = 0x0004;
617pub const SO_KEEPALIVE: c_int = 0x0008;
618pub const SO_DONTROUTE: c_int = 0x0010;
619pub const SO_BROADCAST: c_int = 0x0020;
620pub const SO_USELOOPBACK: c_int = 0x0040;
621pub const SO_LINGER: c_int = 0x0080;
622pub const SO_OOBINLINE: c_int = 0x0100;
623pub const SO_REUSEPORT: c_int = 0x0200;
624pub const SO_TIMESTAMP: c_int = 0x0400;
625pub const SO_NOSIGPIPE: c_int = 0x0800;
626pub const SO_ACCEPTFILTER: c_int = 0x1000;
627pub const SO_SNDBUF: c_int = 0x1001;
628pub const SO_RCVBUF: c_int = 0x1002;
629pub const SO_SNDLOWAT: c_int = 0x1003;
630pub const SO_RCVLOWAT: c_int = 0x1004;
631pub const SO_SNDTIMEO: c_int = 0x1005;
632pub const SO_RCVTIMEO: c_int = 0x1006;
633cfg_if! {
634 if #[cfg(target_os = "horizon")] {
635 pub const SO_ERROR: c_int = 0x1009;
636 } else {
637 pub const SO_ERROR: c_int = 0x1007;
638 }
639}
640pub const SO_TYPE: c_int = 0x1008;
641
642pub const SOCK_CLOEXEC: c_int = O_CLOEXEC;
643
644pub const INET_ADDRSTRLEN: c_int = 16;
645
646// https://github.com/bminor/newlib/blob/HEAD/newlib/libc/sys/linux/include/net/if.h#L121
647pub const IFF_UP: c_int = 0x1; // interface is up
648pub const IFF_BROADCAST: c_int = 0x2; // broadcast address valid
649pub const IFF_DEBUG: c_int = 0x4; // turn on debugging
650pub const IFF_LOOPBACK: c_int = 0x8; // is a loopback net
651pub const IFF_POINTOPOINT: c_int = 0x10; // interface is point-to-point link
652pub const IFF_NOTRAILERS: c_int = 0x20; // avoid use of trailers
653pub const IFF_RUNNING: c_int = 0x40; // resources allocated
654pub const IFF_NOARP: c_int = 0x80; // no address resolution protocol
655pub const IFF_PROMISC: c_int = 0x100; // receive all packets
656pub const IFF_ALLMULTI: c_int = 0x200; // receive all multicast packets
657pub const IFF_OACTIVE: c_int = 0x400; // transmission in progress
658pub const IFF_SIMPLEX: c_int = 0x800; // can't hear own transmissions
659pub const IFF_LINK0: c_int = 0x1000; // per link layer defined bit
660pub const IFF_LINK1: c_int = 0x2000; // per link layer defined bit
661pub const IFF_LINK2: c_int = 0x4000; // per link layer defined bit
662pub const IFF_ALTPHYS: c_int = IFF_LINK2; // use alternate physical connection
663pub const IFF_MULTICAST: c_int = 0x8000; // supports multicast
664
665cfg_if! {
666 if #[cfg(target_os = "vita")] {
667 pub const TCP_NODELAY: c_int = 1;
668 pub const TCP_MAXSEG: c_int = 2;
669 } else if #[cfg(target_os = "espidf")] {
670 pub const TCP_NODELAY: c_int = 1;
671 pub const TCP_MAXSEG: c_int = 8194;
672 } else {
673 pub const TCP_NODELAY: c_int = 8193;
674 pub const TCP_MAXSEG: c_int = 8194;
675 }
676}
677
678pub const TCP_NOPUSH: c_int = 4;
679pub const TCP_NOOPT: c_int = 8;
680cfg_if! {
681 if #[cfg(target_os = "espidf")] {
682 pub const TCP_KEEPIDLE: c_int = 3;
683 pub const TCP_KEEPINTVL: c_int = 4;
684 pub const TCP_KEEPCNT: c_int = 5;
685 } else {
686 pub const TCP_KEEPIDLE: c_int = 256;
687 pub const TCP_KEEPINTVL: c_int = 512;
688 pub const TCP_KEEPCNT: c_int = 1024;
689 }
690}
691
692cfg_if! {
693 if #[cfg(target_os = "horizon")] {
694 pub const IP_TOS: c_int = 7;
695 } else if #[cfg(target_os = "espidf")] {
696 pub const IP_TOS: c_int = 1;
697 } else {
698 pub const IP_TOS: c_int = 3;
699 }
700}
701cfg_if! {
702 if #[cfg(target_os = "vita")] {
703 pub const IP_TTL: c_int = 4;
704 } else if #[cfg(target_os = "espidf")] {
705 pub const IP_TTL: c_int = 2;
706 } else {
707 pub const IP_TTL: c_int = 8;
708 }
709}
710
711cfg_if! {
712 if #[cfg(target_os = "espidf")] {
713 pub const IP_MULTICAST_IF: c_int = 6;
714 pub const IP_MULTICAST_TTL: c_int = 5;
715 pub const IP_MULTICAST_LOOP: c_int = 7;
716 } else {
717 pub const IP_MULTICAST_IF: c_int = 9;
718 pub const IP_MULTICAST_TTL: c_int = 10;
719 pub const IP_MULTICAST_LOOP: c_int = 11;
720 }
721}
722
723cfg_if! {
724 if #[cfg(target_os = "vita")] {
725 pub const IP_ADD_MEMBERSHIP: c_int = 12;
726 pub const IP_DROP_MEMBERSHIP: c_int = 13;
727 } else if #[cfg(target_os = "espidf")] {
728 pub const IP_ADD_MEMBERSHIP: c_int = 3;
729 pub const IP_DROP_MEMBERSHIP: c_int = 4;
730 } else {
731 pub const IP_ADD_MEMBERSHIP: c_int = 11;
732 pub const IP_DROP_MEMBERSHIP: c_int = 12;
733 }
734}
735pub const IPV6_UNICAST_HOPS: c_int = 4;
736cfg_if! {
737 if #[cfg(target_os = "espidf")] {
738 pub const IPV6_MULTICAST_IF: c_int = 768;
739 pub const IPV6_MULTICAST_HOPS: c_int = 769;
740 pub const IPV6_MULTICAST_LOOP: c_int = 770;
741 } else {
742 pub const IPV6_MULTICAST_IF: c_int = 9;
743 pub const IPV6_MULTICAST_HOPS: c_int = 10;
744 pub const IPV6_MULTICAST_LOOP: c_int = 11;
745 }
746}
747pub const IPV6_V6ONLY: c_int = 27;
748pub const IPV6_JOIN_GROUP: c_int = 12;
749pub const IPV6_LEAVE_GROUP: c_int = 13;
750pub const IPV6_ADD_MEMBERSHIP: c_int = 12;
751pub const IPV6_DROP_MEMBERSHIP: c_int = 13;
752
753cfg_if! {
754 if #[cfg(target_os = "espidf")] {
755 pub const HOST_NOT_FOUND: c_int = 210;
756 pub const NO_DATA: c_int = 211;
757 pub const NO_RECOVERY: c_int = 212;
758 pub const TRY_AGAIN: c_int = 213;
759 } else {
760 pub const HOST_NOT_FOUND: c_int = 1;
761 pub const NO_DATA: c_int = 2;
762 pub const NO_RECOVERY: c_int = 3;
763 pub const TRY_AGAIN: c_int = 4;
764 }
765}
766pub const NO_ADDRESS: c_int = 2;
767
768pub const AI_PASSIVE: c_int = 1;
769pub const AI_CANONNAME: c_int = 2;
770pub const AI_NUMERICHOST: c_int = 4;
771cfg_if! {
772 if #[cfg(target_os = "espidf")] {
773 pub const AI_NUMERICSERV: c_int = 8;
774 pub const AI_ADDRCONFIG: c_int = 64;
775 } else {
776 pub const AI_NUMERICSERV: c_int = 0;
777 pub const AI_ADDRCONFIG: c_int = 0;
778 }
779}
780
781pub const NI_MAXHOST: c_int = 1025;
782pub const NI_MAXSERV: c_int = 32;
783pub const NI_NOFQDN: c_int = 1;
784pub const NI_NUMERICHOST: c_int = 2;
785pub const NI_NAMEREQD: c_int = 4;
786cfg_if! {
787 if #[cfg(target_os = "espidf")] {
788 pub const NI_NUMERICSERV: c_int = 8;
789 pub const NI_DGRAM: c_int = 16;
790 } else {
791 pub const NI_NUMERICSERV: c_int = 0;
792 pub const NI_DGRAM: c_int = 0;
793 }
794}
795
796cfg_if! {
797 // Defined in vita/mod.rs for "vita"
798 if #[cfg(target_os = "espidf")] {
799 pub const EAI_FAMILY: c_int = 204;
800 pub const EAI_MEMORY: c_int = 203;
801 pub const EAI_NONAME: c_int = 200;
802 pub const EAI_SOCKTYPE: c_int = 10;
803 } else if #[cfg(not(target_os = "vita"))] {
804 pub const EAI_FAMILY: c_int = -303;
805 pub const EAI_MEMORY: c_int = -304;
806 pub const EAI_NONAME: c_int = -305;
807 pub const EAI_SOCKTYPE: c_int = -307;
808 }
809}
810
811pub const EXIT_SUCCESS: c_int = 0;
812pub const EXIT_FAILURE: c_int = 1;
813
814pub const PRIO_PROCESS: c_int = 0;
815pub const PRIO_PGRP: c_int = 1;
816pub const PRIO_USER: c_int = 2;
817
818f! {
819 pub unsafe fn FD_CLR(fd: c_int, set: *mut fd_set) -> () {
820 let bits = size_of_val(&(*set).fds_bits[0]) * 8;
821 let fd = fd as usize;
822 (*set).fds_bits[fd / bits] &= !(1 << (fd % bits));
823 return;
824 }
825
826 pub unsafe fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool {
827 let bits = size_of_val(&(*set).fds_bits[0]) * 8;
828 let fd = fd as usize;
829 return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0;
830 }
831
832 pub unsafe fn FD_SET(fd: c_int, set: *mut fd_set) -> () {
833 let bits = size_of_val(&(*set).fds_bits[0]) * 8;
834 let fd = fd as usize;
835 (*set).fds_bits[fd / bits] |= 1 << (fd % bits);
836 return;
837 }
838
839 pub unsafe fn FD_ZERO(set: *mut fd_set) -> () {
840 (*set).fds_bits.fill(0);
841 }
842}
843
844extern "C" {
845 pub fn getrlimit(resource: c_int, rlim: *mut crate::rlimit) -> c_int;
846 pub fn setrlimit(resource: c_int, rlim: *const crate::rlimit) -> c_int;
847
848 #[cfg_attr(target_os = "linux", link_name = "__xpg_strerror_r")]
849 pub fn strerror_r(errnum: c_int, buf: *mut c_char, buflen: size_t) -> c_int;
850
851 pub fn sem_destroy(sem: *mut sem_t) -> c_int;
852 pub fn sem_init(sem: *mut sem_t, pshared: c_int, value: c_uint) -> c_int;
853
854 pub fn abs(i: c_int) -> c_int;
855 pub fn labs(i: c_long) -> c_long;
856 pub fn rand() -> c_int;
857 pub fn srand(seed: c_uint);
858
859 #[cfg(not(all(target_arch = "powerpc", target_vendor = "nintendo")))]
860 #[cfg_attr(target_os = "espidf", link_name = "lwip_bind")]
861 pub fn bind(fd: c_int, addr: *const sockaddr, len: socklen_t) -> c_int;
862 pub fn clock_settime(clock_id: crate::clockid_t, tp: *const crate::timespec) -> c_int;
863 pub fn clock_gettime(clock_id: crate::clockid_t, tp: *mut crate::timespec) -> c_int;
864 pub fn clock_getres(clock_id: crate::clockid_t, res: *mut crate::timespec) -> c_int;
865 #[cfg_attr(target_os = "espidf", link_name = "lwip_close")]
866 pub fn closesocket(sockfd: c_int) -> c_int;
867 pub fn ioctl(fd: c_int, request: c_ulong, ...) -> c_int;
868 #[cfg(not(all(target_arch = "powerpc", target_vendor = "nintendo")))]
869 #[cfg_attr(target_os = "espidf", link_name = "lwip_recvfrom")]
870 pub fn recvfrom(
871 fd: c_int,
872 buf: *mut c_void,
873 n: usize,
874 flags: c_int,
875 addr: *mut sockaddr,
876 addr_len: *mut socklen_t,
877 ) -> isize;
878 #[cfg(not(all(target_arch = "powerpc", target_vendor = "nintendo")))]
879 pub fn getnameinfo(
880 sa: *const sockaddr,
881 salen: socklen_t,
882 host: *mut c_char,
883 hostlen: socklen_t,
884 serv: *mut c_char,
885 servlen: socklen_t,
886 flags: c_int,
887 ) -> c_int;
888 pub fn memalign(align: size_t, size: size_t) -> *mut c_void;
889
890 // DIFF(main): changed to `*const *mut` in e77f551de9
891 pub fn fexecve(fd: c_int, argv: *const *const c_char, envp: *const *const c_char) -> c_int;
892
893 pub fn gettimeofday(tp: *mut crate::timeval, tz: *mut c_void) -> c_int;
894 pub fn getgrgid_r(
895 gid: crate::gid_t,
896 grp: *mut crate::group,
897 buf: *mut c_char,
898 buflen: size_t,
899 result: *mut *mut crate::group,
900 ) -> c_int;
901 pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> c_int;
902 pub fn sem_close(sem: *mut sem_t) -> c_int;
903 pub fn getdtablesize() -> c_int;
904 pub fn getgrnam_r(
905 name: *const c_char,
906 grp: *mut crate::group,
907 buf: *mut c_char,
908 buflen: size_t,
909 result: *mut *mut crate::group,
910 ) -> c_int;
911 pub fn pthread_sigmask(how: c_int, set: *const sigset_t, oldset: *mut sigset_t) -> c_int;
912 pub fn sem_open(name: *const c_char, oflag: c_int, ...) -> *mut sem_t;
913 pub fn getgrnam(name: *const c_char) -> *mut crate::group;
914 pub fn pthread_kill(thread: crate::pthread_t, sig: c_int) -> c_int;
915 pub fn sem_unlink(name: *const c_char) -> c_int;
916 pub fn daemon(nochdir: c_int, noclose: c_int) -> c_int;
917 pub fn getpwnam_r(
918 name: *const c_char,
919 pwd: *mut passwd,
920 buf: *mut c_char,
921 buflen: size_t,
922 result: *mut *mut passwd,
923 ) -> c_int;
924 pub fn getpwuid_r(
925 uid: crate::uid_t,
926 pwd: *mut passwd,
927 buf: *mut c_char,
928 buflen: size_t,
929 result: *mut *mut passwd,
930 ) -> c_int;
931 pub fn sigwait(set: *const sigset_t, sig: *mut c_int) -> c_int;
932 pub fn pthread_atfork(
933 prepare: Option<unsafe extern "C" fn()>,
934 parent: Option<unsafe extern "C" fn()>,
935 child: Option<unsafe extern "C" fn()>,
936 ) -> c_int;
937 pub fn getgrgid(gid: crate::gid_t) -> *mut crate::group;
938 pub fn popen(command: *const c_char, mode: *const c_char) -> *mut crate::FILE;
939 pub fn uname(buf: *mut crate::utsname) -> c_int;
940}
941
942mod generic;
943
944cfg_if! {
945 if #[cfg(target_os = "espidf")] {
946 mod espidf;
947 pub use self::espidf::*;
948 } else if #[cfg(target_os = "horizon")] {
949 mod horizon;
950 pub use self::horizon::*;
951 } else if #[cfg(target_os = "vita")] {
952 mod vita;
953 pub use self::vita::*;
954 } else if #[cfg(target_arch = "arm")] {
955 mod arm;
956 pub use self::arm::*;
957 } else if #[cfg(target_arch = "aarch64")] {
958 mod aarch64;
959 pub use self::aarch64::*;
960 } else if #[cfg(target_arch = "powerpc")] {
961 mod powerpc;
962 pub use self::powerpc::*;
963 } else {
964 // Only tested on ARM so far. Other platforms might have different
965 // definitions for types and constants.
966 pub use target_arch_not_implemented;
967 }
968}
969
970cfg_if! {
971 if #[cfg(target_os = "rtems")] {
972 mod rtems;
973 pub use self::rtems::*;
974 }
975}