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 / teeos / mod.rs

1349 lines · 30017 bytes Raw Blame History
1//! Libc bindings for teeos
2//!
3//! Apparently the loader just dynamically links it anyway, but fails
4//! when linking is explicitly requested.
5#![allow(non_camel_case_types)]
6#![allow(non_snake_case)]
7
8use crate::prelude::*;
9
10pub type c_bool = i32;
11
12pub type intmax_t = i64;
13
14pub type uintmax_t = u64;
15
16pub type size_t = usize;
17
18pub type ptrdiff_t = isize;
19
20pub type intptr_t = isize;
21
22pub type uintptr_t = usize;
23
24pub type ssize_t = isize;
25
26pub type pid_t = c_int;
27
28pub type wchar_t = u32;
29
30// long double in C means A float point value, which has 128bit length.
31// but some bit maybe not used, so the real length of long double could be 80(x86) or 128(power pc/IEEE)
32// this is different from f128(not stable and not included default) in Rust, so we use u128 for FFI(Rust to C).
33// this is unstable and will cause to memfault/data abort.
34pub type c_longdouble = _CLongDouble;
35
36pub type pthread_t = c_ulong;
37
38pub type pthread_key_t = c_uint;
39
40pub type pthread_spinlock_t = c_int;
41
42pub type off_t = i64;
43
44pub type time_t = i64;
45
46pub type clock_t = c_long;
47
48pub type clockid_t = c_int;
49
50pub type suseconds_t = c_long;
51
52pub type once_fn = extern "C" fn();
53
54pub type pthread_once_t = c_int;
55
56pub type va_list = *mut c_char;
57
58pub type wint_t = c_uint;
59
60pub type wctype_t = c_ulong;
61
62pub type cmpfunc = extern "C" fn(x: *const c_void, y: *const c_void) -> c_int;
63
64s_paren! {
65 #[repr(align(16))]
66 pub struct _CLongDouble(pub u128);
67}
68
69s! {
70 #[repr(align(8))]
71 pub struct pthread_cond_t {
72 #[doc(hidden)]
73 size: [u8; __SIZEOF_PTHREAD_COND_T],
74 }
75
76 #[repr(align(8))]
77 pub struct pthread_mutex_t {
78 #[doc(hidden)]
79 size: [u8; __SIZEOF_PTHREAD_MUTEX_T],
80 }
81
82 #[repr(align(4))]
83 pub struct pthread_mutexattr_t {
84 #[doc(hidden)]
85 size: [u8; __SIZEOF_PTHREAD_MUTEXATTR_T],
86 }
87
88 #[repr(align(4))]
89 pub struct pthread_condattr_t {
90 #[doc(hidden)]
91 size: [u8; __SIZEOF_PTHREAD_CONDATTR_T],
92 }
93
94 pub struct pthread_attr_t {
95 __size: [u64; 7],
96 }
97
98 pub struct cpu_set_t {
99 bits: [c_ulong; 128 / size_of::<c_ulong>()],
100 }
101
102 #[derive(Default)]
103 pub struct timespec {
104 pub tv_sec: time_t,
105 pub tv_nsec: c_long,
106 }
107
108 #[derive(Default)]
109 pub struct timeval {
110 pub tv_sec: time_t,
111 pub tv_usec: suseconds_t,
112 }
113
114 pub struct tm {
115 pub tm_sec: c_int,
116 pub tm_min: c_int,
117 pub tm_hour: c_int,
118 pub tm_mday: c_int,
119 pub tm_mon: c_int,
120 pub tm_year: c_int,
121 pub tm_wday: c_int,
122 pub tm_yday: c_int,
123 pub tm_isdst: c_int,
124 pub __tm_gmtoff: c_long,
125 pub __tm_zone: *const c_char,
126 }
127
128 pub struct mbstate_t {
129 pub __opaque1: c_uint,
130 pub __opaque2: c_uint,
131 }
132
133 pub struct sem_t {
134 pub __val: [c_int; 4 * size_of::<c_long>() / size_of::<c_int>()],
135 }
136
137 pub struct div_t {
138 pub quot: c_int,
139 pub rem: c_int,
140 }
141}
142
143// fcntl
144pub const O_CREAT: u32 = 0o100;
145
146pub const O_EXCL: u32 = 0o200;
147
148pub const O_NOCTTY: u32 = 0o400;
149
150pub const O_TRUNC: u32 = 0o1000;
151
152pub const O_APPEND: u32 = 0o2000;
153
154pub const O_NONBLOCK: u32 = 0o4000;
155
156pub const O_DSYNC: u32 = 0o10000;
157
158pub const O_SYNC: u32 = 0o4010000;
159
160pub const O_RSYNC: u32 = 0o4010000;
161
162pub const O_DIRECTORY: u32 = 0o200000;
163
164pub const O_NOFOLLOW: u32 = 0o400000;
165
166pub const O_CLOEXEC: u32 = 0o2000000;
167
168pub const O_ASYNC: u32 = 0o20000;
169
170pub const O_DIRECT: u32 = 0o40000;
171
172pub const O_LARGEFILE: u32 = 0o100000;
173
174pub const O_NOATIME: u32 = 0o1000000;
175
176pub const O_PATH: u32 = 0o10000000;
177
178pub const O_TMPFILE: u32 = 0o20200000;
179
180pub const O_NDELAY: u32 = O_NONBLOCK;
181
182pub const F_DUPFD: u32 = 0;
183
184pub const F_GETFD: u32 = 1;
185
186pub const F_SETFD: u32 = 2;
187
188pub const F_GETFL: u32 = 3;
189
190pub const F_SETFL: u32 = 4;
191
192pub const F_SETOWN: u32 = 8;
193
194pub const F_GETOWN: u32 = 9;
195
196pub const F_SETSIG: u32 = 10;
197
198pub const F_GETSIG: u32 = 11;
199
200pub const F_GETLK: u32 = 12;
201
202pub const F_SETLK: u32 = 13;
203
204pub const F_SETLKW: u32 = 14;
205
206pub const F_SETOWN_EX: u32 = 15;
207
208pub const F_GETOWN_EX: u32 = 16;
209
210pub const F_GETOWNER_UIDS: u32 = 17;
211
212// mman
213pub const MAP_FAILED: u64 = 0xffffffffffffffff;
214
215pub const MAP_FIXED_NOREPLACE: u32 = 0x100000;
216
217pub const MAP_SHARED_VALIDATE: u32 = 0x03;
218
219pub const MAP_SHARED: u32 = 0x01;
220
221pub const MAP_PRIVATE: u32 = 0x02;
222
223pub const MAP_TYPE: u32 = 0x0f;
224
225pub const MAP_FIXED: u32 = 0x10;
226
227pub const MAP_ANON: u32 = 0x20;
228
229pub const MAP_ANONYMOUS: u32 = MAP_ANON;
230
231pub const MAP_NORESERVE: u32 = 0x4000;
232
233pub const MAP_GROWSDOWN: u32 = 0x0100;
234
235pub const MAP_DENYWRITE: u32 = 0x0800;
236
237pub const MAP_EXECUTABLE: u32 = 0x1000;
238
239pub const MAP_LOCKED: u32 = 0x2000;
240
241pub const MAP_POPULATE: u32 = 0x8000;
242
243pub const MAP_NONBLOCK: u32 = 0x10000;
244
245pub const MAP_STACK: u32 = 0x20000;
246
247pub const MAP_HUGETLB: u32 = 0x40000;
248
249pub const MAP_SYNC: u32 = 0x80000;
250
251pub const MAP_FILE: u32 = 0;
252
253pub const MAP_HUGE_SHIFT: u32 = 26;
254
255pub const MAP_HUGE_MASK: u32 = 0x3f;
256
257pub const MAP_HUGE_16KB: u32 = 14 << 26;
258
259pub const MAP_HUGE_64KB: u32 = 16 << 26;
260
261pub const MAP_HUGE_512KB: u32 = 19 << 26;
262
263pub const MAP_HUGE_1MB: u32 = 20 << 26;
264
265pub const MAP_HUGE_2MB: u32 = 21 << 26;
266
267pub const MAP_HUGE_8MB: u32 = 23 << 26;
268
269pub const MAP_HUGE_16MB: u32 = 24 << 26;
270
271pub const MAP_HUGE_32MB: u32 = 25 << 26;
272
273pub const MAP_HUGE_256MB: u32 = 28 << 26;
274
275pub const MAP_HUGE_512MB: u32 = 29 << 26;
276
277pub const MAP_HUGE_1GB: u32 = 30 << 26;
278
279pub const MAP_HUGE_2GB: u32 = 31 << 26;
280
281pub const MAP_HUGE_16GB: u32 = 34u32 << 26;
282
283pub const PROT_NONE: u32 = 0;
284
285pub const PROT_READ: u32 = 1;
286
287pub const PROT_WRITE: u32 = 2;
288
289pub const PROT_EXEC: u32 = 4;
290
291pub const PROT_GROWSDOWN: u32 = 0x01000000;
292
293pub const PROT_GROWSUP: u32 = 0x02000000;
294
295pub const MS_ASYNC: u32 = 1;
296
297pub const MS_INVALIDATE: u32 = 2;
298
299pub const MS_SYNC: u32 = 4;
300
301pub const MCL_CURRENT: u32 = 1;
302
303pub const MCL_FUTURE: u32 = 2;
304
305pub const MCL_ONFAULT: u32 = 4;
306
307pub const POSIX_MADV_NORMAL: u32 = 0;
308
309pub const POSIX_MADV_RANDOM: u32 = 1;
310
311pub const POSIX_MADV_SEQUENTIAL: u32 = 2;
312
313pub const POSIX_MADV_WILLNEED: u32 = 3;
314
315pub const POSIX_MADV_DONTNEED: u32 = 4;
316
317// wctype
318pub const WCTYPE_ALNUM: u64 = 1;
319
320pub const WCTYPE_ALPHA: u64 = 2;
321
322pub const WCTYPE_BLANK: u64 = 3;
323
324pub const WCTYPE_CNTRL: u64 = 4;
325
326pub const WCTYPE_DIGIT: u64 = 5;
327
328pub const WCTYPE_GRAPH: u64 = 6;
329
330pub const WCTYPE_LOWER: u64 = 7;
331
332pub const WCTYPE_PRINT: u64 = 8;
333
334pub const WCTYPE_PUNCT: u64 = 9;
335
336pub const WCTYPE_SPACE: u64 = 10;
337
338pub const WCTYPE_UPPER: u64 = 11;
339
340pub const WCTYPE_XDIGIT: u64 = 12;
341
342// locale
343pub const LC_CTYPE: i32 = 0;
344
345pub const LC_NUMERIC: i32 = 1;
346
347pub const LC_TIME: i32 = 2;
348
349pub const LC_COLLATE: i32 = 3;
350
351pub const LC_MONETARY: i32 = 4;
352
353pub const LC_MESSAGES: i32 = 5;
354
355pub const LC_ALL: i32 = 6;
356
357// pthread
358pub const __SIZEOF_PTHREAD_COND_T: usize = 48;
359
360pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
361
362pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
363
364pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
365
366// errno.h
367pub const EPERM: c_int = 1;
368
369pub const ENOENT: c_int = 2;
370
371pub const ESRCH: c_int = 3;
372
373pub const EINTR: c_int = 4;
374
375pub const EIO: c_int = 5;
376
377pub const ENXIO: c_int = 6;
378
379pub const E2BIG: c_int = 7;
380
381pub const ENOEXEC: c_int = 8;
382
383pub const EBADF: c_int = 9;
384
385pub const ECHILD: c_int = 10;
386
387pub const EAGAIN: c_int = 11;
388
389pub const ENOMEM: c_int = 12;
390
391pub const EACCES: c_int = 13;
392
393pub const EFAULT: c_int = 14;
394
395pub const ENOTBLK: c_int = 15;
396
397pub const EBUSY: c_int = 16;
398
399pub const EEXIST: c_int = 17;
400
401pub const EXDEV: c_int = 18;
402
403pub const ENODEV: c_int = 19;
404
405pub const ENOTDIR: c_int = 20;
406
407pub const EISDIR: c_int = 21;
408
409pub const EINVAL: c_int = 22;
410
411pub const ENFILE: c_int = 23;
412
413pub const EMFILE: c_int = 24;
414
415pub const ENOTTY: c_int = 25;
416
417pub const ETXTBSY: c_int = 26;
418
419pub const EFBIG: c_int = 27;
420
421pub const ENOSPC: c_int = 28;
422
423pub const ESPIPE: c_int = 29;
424
425pub const EROFS: c_int = 30;
426
427pub const EMLINK: c_int = 31;
428
429pub const EPIPE: c_int = 32;
430
431pub const EDOM: c_int = 33;
432
433pub const ERANGE: c_int = 34;
434
435pub const EDEADLK: c_int = 35;
436
437pub const ENAMETOOLONG: c_int = 36;
438
439pub const ENOLCK: c_int = 37;
440
441pub const ENOSYS: c_int = 38;
442
443pub const ENOTEMPTY: c_int = 39;
444
445pub const ELOOP: c_int = 40;
446
447pub const EWOULDBLOCK: c_int = EAGAIN;
448
449pub const ENOMSG: c_int = 42;
450
451pub const EIDRM: c_int = 43;
452
453pub const ECHRNG: c_int = 44;
454
455pub const EL2NSYNC: c_int = 45;
456
457pub const EL3HLT: c_int = 46;
458
459pub const EL3RST: c_int = 47;
460
461pub const ELNRNG: c_int = 48;
462
463pub const EUNATCH: c_int = 49;
464
465pub const ENOCSI: c_int = 50;
466
467pub const EL2HLT: c_int = 51;
468
469pub const EBADE: c_int = 52;
470
471pub const EBADR: c_int = 53;
472
473pub const EXFULL: c_int = 54;
474
475pub const ENOANO: c_int = 55;
476
477pub const EBADRQC: c_int = 56;
478
479pub const EBADSLT: c_int = 57;
480
481pub const EDEADLOCK: c_int = EDEADLK;
482
483pub const EBFONT: c_int = 59;
484
485pub const ENOSTR: c_int = 60;
486
487pub const ENODATA: c_int = 61;
488
489pub const ETIME: c_int = 62;
490
491pub const ENOSR: c_int = 63;
492
493pub const ENONET: c_int = 64;
494
495pub const ENOPKG: c_int = 65;
496
497pub const EREMOTE: c_int = 66;
498
499pub const ENOLINK: c_int = 67;
500
501pub const EADV: c_int = 68;
502
503pub const ESRMNT: c_int = 69;
504
505pub const ECOMM: c_int = 70;
506
507pub const EPROTO: c_int = 71;
508
509pub const EMULTIHOP: c_int = 72;
510
511pub const EDOTDOT: c_int = 73;
512
513pub const EBADMSG: c_int = 74;
514
515pub const EOVERFLOW: c_int = 75;
516
517pub const ENOTUNIQ: c_int = 76;
518
519pub const EBADFD: c_int = 77;
520
521pub const EREMCHG: c_int = 78;
522
523pub const ELIBACC: c_int = 79;
524
525pub const ELIBBAD: c_int = 80;
526
527pub const ELIBSCN: c_int = 81;
528
529pub const ELIBMAX: c_int = 82;
530
531pub const ELIBEXEC: c_int = 83;
532
533pub const EILSEQ: c_int = 84;
534
535pub const ERESTART: c_int = 85;
536
537pub const ESTRPIPE: c_int = 86;
538
539pub const EUSERS: c_int = 87;
540
541pub const ENOTSOCK: c_int = 88;
542
543pub const EDESTADDRREQ: c_int = 89;
544
545pub const EMSGSIZE: c_int = 90;
546
547pub const EPROTOTYPE: c_int = 91;
548
549pub const ENOPROTOOPT: c_int = 92;
550
551pub const EPROTONOSUPPOR: c_int = 93;
552
553pub const ESOCKTNOSUPPOR: c_int = 94;
554
555pub const EOPNOTSUPP: c_int = 95;
556
557pub const ENOTSUP: c_int = EOPNOTSUPP;
558
559pub const EPFNOSUPPORT: c_int = 96;
560
561pub const EAFNOSUPPORT: c_int = 97;
562
563pub const EADDRINUSE: c_int = 98;
564
565pub const EADDRNOTAVAIL: c_int = 99;
566
567pub const ENETDOWN: c_int = 100;
568
569pub const ENETUNREACH: c_int = 101;
570
571pub const ENETRESET: c_int = 102;
572
573pub const ECONNABORTED: c_int = 103;
574
575pub const ECONNRESET: c_int = 104;
576
577pub const ENOBUFS: c_int = 105;
578
579pub const EISCONN: c_int = 106;
580
581pub const ENOTCONN: c_int = 107;
582
583pub const ESHUTDOWN: c_int = 108;
584
585pub const ETOOMANYREFS: c_int = 109;
586
587pub const ETIMEDOUT: c_int = 110;
588
589pub const ECONNREFUSED: c_int = 111;
590
591pub const EHOSTDOWN: c_int = 112;
592
593pub const EHOSTUNREACH: c_int = 113;
594
595pub const EALREADY: c_int = 114;
596
597pub const EINPROGRESS: c_int = 115;
598
599pub const ESTALE: c_int = 116;
600
601pub const EUCLEAN: c_int = 117;
602
603pub const ENOTNAM: c_int = 118;
604
605pub const ENAVAIL: c_int = 119;
606
607pub const EISNAM: c_int = 120;
608
609pub const EREMOTEIO: c_int = 121;
610
611pub const EDQUOT: c_int = 122;
612
613pub const ENOMEDIUM: c_int = 123;
614
615pub const EMEDIUMTYPE: c_int = 124;
616
617pub const ECANCELED: c_int = 125;
618
619pub const ENOKEY: c_int = 126;
620
621pub const EKEYEXPIRED: c_int = 127;
622
623pub const EKEYREVOKED: c_int = 128;
624
625pub const EKEYREJECTED: c_int = 129;
626
627pub const EOWNERDEAD: c_int = 130;
628
629pub const ENOTRECOVERABLE: c_int = 131;
630
631pub const ERFKILL: c_int = 132;
632
633pub const EHWPOISON: c_int = 133;
634
635// pthread_attr.h
636pub const TEESMP_THREAD_ATTR_CA_WILDCARD: c_int = 0;
637
638pub const TEESMP_THREAD_ATTR_CA_INHERIT: c_int = -1;
639
640pub const TEESMP_THREAD_ATTR_TASK_ID_INHERIT: c_int = -1;
641
642pub const TEESMP_THREAD_ATTR_HAS_SHADOW: c_int = 0x1;
643
644pub const TEESMP_THREAD_ATTR_NO_SHADOW: c_int = 0x0;
645
646// unistd.h
647pub const _SC_ARG_MAX: c_int = 0;
648
649pub const _SC_CHILD_MAX: c_int = 1;
650
651pub const _SC_CLK_TCK: c_int = 2;
652
653pub const _SC_NGROUPS_MAX: c_int = 3;
654
655pub const _SC_OPEN_MAX: c_int = 4;
656
657pub const _SC_STREAM_MAX: c_int = 5;
658
659pub const _SC_TZNAME_MAX: c_int = 6;
660
661pub const _SC_JOB_CONTROL: c_int = 7;
662
663pub const _SC_SAVED_IDS: c_int = 8;
664
665pub const _SC_REALTIME_SIGNALS: c_int = 9;
666
667pub const _SC_PRIORITY_SCHEDULING: c_int = 10;
668
669pub const _SC_TIMERS: c_int = 11;
670
671pub const _SC_ASYNCHRONOUS_IO: c_int = 12;
672
673pub const _SC_PRIORITIZED_IO: c_int = 13;
674
675pub const _SC_SYNCHRONIZED_IO: c_int = 14;
676
677pub const _SC_FSYNC: c_int = 15;
678
679pub const _SC_MAPPED_FILES: c_int = 16;
680
681pub const _SC_MEMLOCK: c_int = 17;
682
683pub const _SC_MEMLOCK_RANGE: c_int = 18;
684
685pub const _SC_MEMORY_PROTECTION: c_int = 19;
686
687pub const _SC_MESSAGE_PASSING: c_int = 20;
688
689pub const _SC_SEMAPHORES: c_int = 21;
690
691pub const _SC_SHARED_MEMORY_OBJECTS: c_int = 22;
692
693pub const _SC_AIO_LISTIO_MAX: c_int = 23;
694
695pub const _SC_AIO_MAX: c_int = 24;
696
697pub const _SC_AIO_PRIO_DELTA_MAX: c_int = 25;
698
699pub const _SC_DELAYTIMER_MAX: c_int = 26;
700
701pub const _SC_MQ_OPEN_MAX: c_int = 27;
702
703pub const _SC_MQ_PRIO_MAX: c_int = 28;
704
705pub const _SC_VERSION: c_int = 29;
706
707pub const _SC_PAGE_SIZE: c_int = 30;
708
709pub const _SC_PAGESIZE: c_int = 30; /* !! */
710
711pub const _SC_RTSIG_MAX: c_int = 31;
712
713pub const _SC_SEM_NSEMS_MAX: c_int = 32;
714
715pub const _SC_SEM_VALUE_MAX: c_int = 33;
716
717pub const _SC_SIGQUEUE_MAX: c_int = 34;
718
719pub const _SC_TIMER_MAX: c_int = 35;
720
721pub const _SC_BC_BASE_MAX: c_int = 36;
722
723pub const _SC_BC_DIM_MAX: c_int = 37;
724
725pub const _SC_BC_SCALE_MAX: c_int = 38;
726
727pub const _SC_BC_STRING_MAX: c_int = 39;
728
729pub const _SC_COLL_WEIGHTS_MAX: c_int = 40;
730
731pub const _SC_EXPR_NEST_MAX: c_int = 42;
732
733pub const _SC_LINE_MAX: c_int = 43;
734
735pub const _SC_RE_DUP_MAX: c_int = 44;
736
737pub const _SC_2_VERSION: c_int = 46;
738
739pub const _SC_2_C_BIND: c_int = 47;
740
741pub const _SC_2_C_DEV: c_int = 48;
742
743pub const _SC_2_FORT_DEV: c_int = 49;
744
745pub const _SC_2_FORT_RUN: c_int = 50;
746
747pub const _SC_2_SW_DEV: c_int = 51;
748
749pub const _SC_2_LOCALEDEF: c_int = 52;
750
751pub const _SC_UIO_MAXIOV: c_int = 60; /* !! */
752
753pub const _SC_IOV_MAX: c_int = 60;
754
755pub const _SC_THREADS: c_int = 67;
756
757pub const _SC_THREAD_SAFE_FUNCTIONS: c_int = 68;
758
759pub const _SC_GETGR_R_SIZE_MAX: c_int = 69;
760
761pub const _SC_GETPW_R_SIZE_MAX: c_int = 70;
762
763pub const _SC_LOGIN_NAME_MAX: c_int = 71;
764
765pub const _SC_TTY_NAME_MAX: c_int = 72;
766
767pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: c_int = 73;
768
769pub const _SC_THREAD_KEYS_MAX: c_int = 74;
770
771pub const _SC_THREAD_STACK_MIN: c_int = 75;
772
773pub const _SC_THREAD_THREADS_MAX: c_int = 76;
774
775pub const _SC_THREAD_ATTR_STACKADDR: c_int = 77;
776
777pub const _SC_THREAD_ATTR_STACKSIZE: c_int = 78;
778
779pub const _SC_THREAD_PRIORITY_SCHEDULING: c_int = 79;
780
781pub const _SC_THREAD_PRIO_INHERIT: c_int = 80;
782
783pub const _SC_THREAD_PRIO_PROTECT: c_int = 81;
784
785pub const _SC_THREAD_PROCESS_SHARED: c_int = 82;
786
787pub const _SC_NPROCESSORS_CONF: c_int = 83;
788
789pub const _SC_NPROCESSORS_ONLN: c_int = 84;
790
791pub const _SC_PHYS_PAGES: c_int = 85;
792
793pub const _SC_AVPHYS_PAGES: c_int = 86;
794
795pub const _SC_ATEXIT_MAX: c_int = 87;
796
797pub const _SC_PASS_MAX: c_int = 88;
798
799pub const _SC_XOPEN_VERSION: c_int = 89;
800
801pub const _SC_XOPEN_XCU_VERSION: c_int = 90;
802
803pub const _SC_XOPEN_UNIX: c_int = 91;
804
805pub const _SC_XOPEN_CRYPT: c_int = 92;
806
807pub const _SC_XOPEN_ENH_I18N: c_int = 93;
808
809pub const _SC_XOPEN_SHM: c_int = 94;
810
811pub const _SC_2_CHAR_TERM: c_int = 95;
812
813pub const _SC_2_UPE: c_int = 97;
814
815pub const _SC_XOPEN_XPG2: c_int = 98;
816
817pub const _SC_XOPEN_XPG3: c_int = 99;
818
819pub const _SC_XOPEN_XPG4: c_int = 100;
820
821pub const _SC_NZERO: c_int = 109;
822
823pub const _SC_XBS5_ILP32_OFF32: c_int = 125;
824
825pub const _SC_XBS5_ILP32_OFFBIG: c_int = 126;
826
827pub const _SC_XBS5_LP64_OFF64: c_int = 127;
828
829pub const _SC_XBS5_LPBIG_OFFBIG: c_int = 128;
830
831pub const _SC_XOPEN_LEGACY: c_int = 129;
832
833pub const _SC_XOPEN_REALTIME: c_int = 130;
834
835pub const _SC_XOPEN_REALTIME_THREADS: c_int = 131;
836
837pub const _SC_ADVISORY_INFO: c_int = 132;
838
839pub const _SC_BARRIERS: c_int = 133;
840
841pub const _SC_CLOCK_SELECTION: c_int = 137;
842
843pub const _SC_CPUTIME: c_int = 138;
844
845pub const _SC_THREAD_CPUTIME: c_int = 139;
846
847pub const _SC_MONOTONIC_CLOCK: c_int = 149;
848
849pub const _SC_READER_WRITER_LOCKS: c_int = 153;
850
851pub const _SC_SPIN_LOCKS: c_int = 154;
852
853pub const _SC_REGEXP: c_int = 155;
854
855pub const _SC_SHELL: c_int = 157;
856
857pub const _SC_SPAWN: c_int = 159;
858
859pub const _SC_SPORADIC_SERVER: c_int = 160;
860
861pub const _SC_THREAD_SPORADIC_SERVER: c_int = 161;
862
863pub const _SC_TIMEOUTS: c_int = 164;
864
865pub const _SC_TYPED_MEMORY_OBJECTS: c_int = 165;
866
867pub const _SC_2_PBS: c_int = 168;
868
869pub const _SC_2_PBS_ACCOUNTING: c_int = 169;
870
871pub const _SC_2_PBS_LOCATE: c_int = 170;
872
873pub const _SC_2_PBS_MESSAGE: c_int = 171;
874
875pub const _SC_2_PBS_TRACK: c_int = 172;
876
877pub const _SC_SYMLOOP_MAX: c_int = 173;
878
879pub const _SC_STREAMS: c_int = 174;
880
881pub const _SC_2_PBS_CHECKPOINT: c_int = 175;
882
883pub const _SC_V6_ILP32_OFF32: c_int = 176;
884
885pub const _SC_V6_ILP32_OFFBIG: c_int = 177;
886
887pub const _SC_V6_LP64_OFF64: c_int = 178;
888
889pub const _SC_V6_LPBIG_OFFBIG: c_int = 179;
890
891pub const _SC_HOST_NAME_MAX: c_int = 180;
892
893pub const _SC_TRACE: c_int = 181;
894
895pub const _SC_TRACE_EVENT_FILTER: c_int = 182;
896
897pub const _SC_TRACE_INHERIT: c_int = 183;
898
899pub const _SC_TRACE_LOG: c_int = 184;
900
901pub const _SC_IPV6: c_int = 235;
902
903pub const _SC_RAW_SOCKETS: c_int = 236;
904
905pub const _SC_V7_ILP32_OFF32: c_int = 237;
906
907pub const _SC_V7_ILP32_OFFBIG: c_int = 238;
908
909pub const _SC_V7_LP64_OFF64: c_int = 239;
910
911pub const _SC_V7_LPBIG_OFFBIG: c_int = 240;
912
913pub const _SC_SS_REPL_MAX: c_int = 241;
914
915pub const _SC_TRACE_EVENT_NAME_MAX: c_int = 242;
916
917pub const _SC_TRACE_NAME_MAX: c_int = 243;
918
919pub const _SC_TRACE_SYS_MAX: c_int = 244;
920
921pub const _SC_TRACE_USER_EVENT_MAX: c_int = 245;
922
923pub const _SC_XOPEN_STREAMS: c_int = 246;
924
925pub const _SC_THREAD_ROBUST_PRIO_INHERIT: c_int = 247;
926
927pub const _SC_THREAD_ROBUST_PRIO_PROTECT: c_int = 248;
928
929// limits.h
930pub const PTHREAD_KEYS_MAX: c_int = 128;
931
932pub const PTHREAD_STACK_MIN: c_int = 2048;
933
934pub const PTHREAD_DESTRUCTOR_ITERATIONS: c_int = 4;
935
936pub const SEM_VALUE_MAX: c_int = 0x7fffffff;
937
938pub const SEM_NSEMS_MAX: c_int = 256;
939
940pub const DELAYTIMER_MAX: c_int = 0x7fffffff;
941
942pub const MQ_PRIO_MAX: c_int = 32768;
943
944pub const LOGIN_NAME_MAX: c_int = 256;
945
946// time.h
947pub const CLOCK_REALTIME: clockid_t = 0;
948
949pub const CLOCK_MONOTONIC: clockid_t = 1;
950
951pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
952 size: [0; __SIZEOF_PTHREAD_MUTEX_T],
953};
954
955pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
956 size: [0; __SIZEOF_PTHREAD_COND_T],
957};
958
959pub const PTHREAD_MUTEX_NORMAL: c_int = 0;
960
961pub const PTHREAD_MUTEX_RECURSIVE: c_int = 1;
962
963pub const PTHREAD_MUTEX_ERRORCHECK: c_int = 2;
964
965pub const PTHREAD_MUTEX_DEFAULT: c_int = PTHREAD_MUTEX_NORMAL;
966
967pub const PTHREAD_MUTEX_STALLED: c_int = 0;
968
969pub const PTHREAD_MUTEX_ROBUST: c_int = 1;
970
971extern "C" {
972 // ---- ALLOC -----------------------------------------------------------------------------
973 pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void;
974
975 pub fn malloc(size: size_t) -> *mut c_void;
976
977 pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void;
978
979 pub fn aligned_alloc(align: size_t, len: size_t) -> *mut c_void;
980
981 pub fn free(p: *mut c_void);
982
983 pub fn posix_memalign(memptr: *mut *mut c_void, align: size_t, size: size_t) -> c_int;
984
985 pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void;
986
987 pub fn wmemchr(cx: *const wchar_t, c: wchar_t, n: size_t) -> *mut wchar_t;
988
989 pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int;
990
991 pub fn memcpy(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void;
992
993 pub fn memmove(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void;
994
995 pub fn memset(dest: *mut c_void, c: c_int, n: size_t) -> *mut c_void;
996
997 // ----- PTHREAD ---------------------------------------------------------------------------
998 pub fn pthread_self() -> pthread_t;
999
1000 pub fn pthread_join(native: pthread_t, value: *mut *mut c_void) -> c_int;
1001
1002 // detach or pthread_attr_setdetachstate must not be called!
1003 //pub fn pthread_detach(thread: pthread_t) -> c_int;
1004
1005 pub fn pthread_exit(value: *mut c_void) -> !;
1006
1007 pub fn pthread_attr_init(attr: *mut pthread_attr_t) -> c_int;
1008
1009 pub fn pthread_attr_destroy(attr: *mut pthread_attr_t) -> c_int;
1010
1011 pub fn pthread_attr_getstack(
1012 attr: *const pthread_attr_t,
1013 stackaddr: *mut *mut c_void,
1014 stacksize: *mut size_t,
1015 ) -> c_int;
1016
1017 pub fn pthread_attr_setstacksize(attr: *mut pthread_attr_t, stack_size: size_t) -> c_int;
1018
1019 pub fn pthread_attr_getstacksize(attr: *const pthread_attr_t, size: *mut size_t) -> c_int;
1020
1021 pub fn pthread_attr_settee(
1022 attr: *mut pthread_attr_t,
1023 ca: c_int,
1024 task_id: c_int,
1025 shadow: c_int,
1026 ) -> c_int;
1027
1028 // C-TA API do not include this interface, but TA can use.
1029 pub fn sched_yield() -> c_int;
1030
1031 pub fn pthread_key_create(
1032 key: *mut pthread_key_t,
1033 dtor: Option<unsafe extern "C" fn(*mut c_void)>,
1034 ) -> c_int;
1035
1036 pub fn pthread_key_delete(key: pthread_key_t) -> c_int;
1037
1038 pub fn pthread_getspecific(key: pthread_key_t) -> *mut c_void;
1039
1040 pub fn pthread_setspecific(key: pthread_key_t, value: *const c_void) -> c_int;
1041
1042 pub fn pthread_mutex_destroy(lock: *mut pthread_mutex_t) -> c_int;
1043
1044 pub fn pthread_mutex_init(
1045 lock: *mut pthread_mutex_t,
1046 attr: *const pthread_mutexattr_t,
1047 ) -> c_int;
1048
1049 pub fn pthread_mutex_lock(lock: *mut pthread_mutex_t) -> c_int;
1050
1051 pub fn pthread_mutex_trylock(lock: *mut pthread_mutex_t) -> c_int;
1052
1053 pub fn pthread_mutex_unlock(lock: *mut pthread_mutex_t) -> c_int;
1054
1055 pub fn pthread_mutexattr_destroy(attr: *mut pthread_mutexattr_t) -> c_int;
1056
1057 pub fn pthread_mutexattr_init(attr: *mut pthread_mutexattr_t) -> c_int;
1058
1059 pub fn pthread_mutexattr_settype(attr: *mut pthread_mutexattr_t, _type: c_int) -> c_int;
1060
1061 pub fn pthread_mutexattr_setpshared(attr: *mut pthread_mutexattr_t, pshared: c_int) -> c_int;
1062
1063 pub fn pthread_cond_broadcast(cond: *mut pthread_cond_t) -> c_int;
1064
1065 pub fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> c_int;
1066
1067 pub fn pthread_cond_init(cond: *mut pthread_cond_t, attr: *const pthread_condattr_t) -> c_int;
1068
1069 pub fn pthread_cond_signal(cond: *mut pthread_cond_t) -> c_int;
1070
1071 pub fn pthread_cond_wait(cond: *mut pthread_cond_t, lock: *mut pthread_mutex_t) -> c_int;
1072
1073 pub fn pthread_cond_timedwait(
1074 cond: *mut pthread_cond_t,
1075 lock: *mut pthread_mutex_t,
1076 abstime: *const timespec,
1077 ) -> c_int;
1078
1079 pub fn pthread_mutexattr_setrobust(attr: *mut pthread_mutexattr_t, robustness: c_int) -> c_int;
1080
1081 pub fn pthread_create(
1082 native: *mut pthread_t,
1083 attr: *const pthread_attr_t,
1084 f: extern "C" fn(*mut c_void) -> *mut c_void,
1085 value: *mut c_void,
1086 ) -> c_int;
1087
1088 pub fn pthread_spin_init(lock: *mut pthread_spinlock_t, pshared: c_int) -> c_int;
1089
1090 pub fn pthread_spin_destroy(lock: *mut pthread_spinlock_t) -> c_int;
1091
1092 pub fn pthread_spin_lock(lock: *mut pthread_spinlock_t) -> c_int;
1093
1094 pub fn pthread_spin_trylock(lock: *mut pthread_spinlock_t) -> c_int;
1095
1096 pub fn pthread_spin_unlock(lock: *mut pthread_spinlock_t) -> c_int;
1097
1098 pub fn pthread_setschedprio(native: pthread_t, priority: c_int) -> c_int;
1099
1100 pub fn pthread_once(pot: *mut pthread_once_t, f: Option<once_fn>) -> c_int;
1101
1102 pub fn pthread_equal(p1: pthread_t, p2: pthread_t) -> c_int;
1103
1104 pub fn pthread_mutexattr_setprotocol(a: *mut pthread_mutexattr_t, protocol: c_int) -> c_int;
1105
1106 pub fn pthread_attr_setstack(
1107 attr: *mut pthread_attr_t,
1108 stack: *mut c_void,
1109 size: size_t,
1110 ) -> c_int;
1111
1112 pub fn pthread_setaffinity_np(td: pthread_t, size: size_t, set: *const cpu_set_t) -> c_int;
1113
1114 pub fn pthread_getaffinity_np(td: pthread_t, size: size_t, set: *mut cpu_set_t) -> c_int;
1115
1116 // stdio.h
1117 pub fn printf(fmt: *const c_char, ...) -> c_int;
1118
1119 pub fn scanf(fmt: *const c_char, ...) -> c_int;
1120
1121 pub fn snprintf(s: *mut c_char, n: size_t, fmt: *const c_char, ...) -> c_int;
1122
1123 pub fn sprintf(s: *mut c_char, fmt: *const c_char, ...) -> c_int;
1124
1125 pub fn vsnprintf(s: *mut c_char, n: size_t, fmt: *const c_char, ap: va_list) -> c_int;
1126
1127 pub fn vsprintf(s: *mut c_char, fmt: *const c_char, ap: va_list) -> c_int;
1128
1129 // Not available.
1130 //pub fn pthread_setname_np(thread: pthread_t, name: *const c_char) -> c_int;
1131
1132 pub fn abort() -> !;
1133
1134 // Not available.
1135 //pub fn prctl(op: c_int, ...) -> c_int;
1136
1137 pub fn sched_getaffinity(pid: pid_t, cpusetsize: size_t, cpuset: *mut cpu_set_t) -> c_int;
1138
1139 pub fn sched_setaffinity(pid: pid_t, cpusetsize: size_t, cpuset: *const cpu_set_t) -> c_int;
1140
1141 // sysconf is currently only implemented as a stub.
1142 pub fn sysconf(name: c_int) -> c_long;
1143
1144 // mman.h
1145 pub fn mmap(
1146 addr: *mut c_void,
1147 len: size_t,
1148 prot: c_int,
1149 flags: c_int,
1150 fd: c_int,
1151 offset: off_t,
1152 ) -> *mut c_void;
1153 pub fn munmap(addr: *mut c_void, len: size_t) -> c_int;
1154
1155 // errno.h
1156 pub fn __errno_location() -> *mut c_int;
1157
1158 pub fn strerror(e: c_int) -> *mut c_char;
1159
1160 // time.h
1161 pub fn clock_gettime(clock_id: clockid_t, tp: *mut timespec) -> c_int;
1162
1163 // unistd
1164 pub fn getpid() -> pid_t;
1165
1166 // time
1167 pub fn gettimeofday(tv: *mut timeval, tz: *mut c_void) -> c_int;
1168
1169 pub fn strftime(
1170 restrict: *mut c_char,
1171 sz: size_t,
1172 _restrict: *const c_char,
1173 __restrict: *const tm,
1174 ) -> size_t;
1175
1176 pub fn time(t: *mut time_t) -> time_t;
1177
1178 // sem
1179 pub fn sem_close(sem: *mut sem_t) -> c_int;
1180
1181 pub fn sem_destroy(sem: *mut sem_t) -> c_int;
1182
1183 pub fn sem_getvalue(sem: *mut sem_t, valp: *mut c_int) -> c_int;
1184
1185 pub fn sem_init(sem: *mut sem_t, pshared: c_int, value: c_uint) -> c_int;
1186
1187 pub fn sem_open(name: *const c_char, flags: c_int, ...) -> *mut sem_t;
1188
1189 pub fn sem_post(sem: *mut sem_t) -> c_int;
1190
1191 pub fn sem_unlink(name: *const c_char) -> c_int;
1192
1193 pub fn sem_wait(sem: *mut sem_t) -> c_int;
1194
1195 // locale
1196 pub fn setlocale(cat: c_int, name: *const c_char) -> *mut c_char;
1197
1198 pub fn strcoll(l: *const c_char, r: *const c_char) -> c_int;
1199
1200 pub fn strxfrm(dest: *mut c_char, src: *const c_char, n: size_t) -> size_t;
1201
1202 pub fn strtod(s: *const c_char, p: *mut *mut c_char) -> c_double;
1203
1204 // multibyte
1205 pub fn mbrtowc(wc: *mut wchar_t, src: *const c_char, n: size_t, st: *mut mbstate_t) -> size_t;
1206
1207 pub fn wcrtomb(s: *mut c_char, wc: wchar_t, st: *mut mbstate_t) -> size_t;
1208
1209 pub fn wctob(c: wint_t) -> c_int;
1210
1211 // prng
1212 pub fn srandom(seed: c_uint);
1213
1214 pub fn initstate(seed: c_uint, state: *mut c_char, size: size_t) -> *mut c_char;
1215
1216 pub fn setstate(state: *mut c_char) -> *mut c_char;
1217
1218 pub fn random() -> c_long;
1219
1220 // string
1221 pub fn strchr(s: *const c_char, c: c_int) -> *mut c_char;
1222
1223 pub fn strlen(cs: *const c_char) -> size_t;
1224
1225 pub fn strcmp(l: *const c_char, r: *const c_char) -> c_int;
1226
1227 pub fn strcpy(dest: *mut c_char, src: *const c_char) -> *mut c_char;
1228
1229 pub fn strncmp(_l: *const c_char, r: *const c_char, n: size_t) -> c_int;
1230
1231 pub fn strncpy(dest: *mut c_char, src: *const c_char, n: size_t) -> *mut c_char;
1232
1233 pub fn strnlen(cs: *const c_char, n: size_t) -> size_t;
1234
1235 pub fn strrchr(s: *const c_char, c: c_int) -> *mut c_char;
1236
1237 pub fn strstr(h: *const c_char, n: *const c_char) -> *mut c_char;
1238
1239 pub fn wcschr(s: *const wchar_t, c: wchar_t) -> *mut wchar_t;
1240
1241 pub fn wcslen(s: *const wchar_t) -> size_t;
1242
1243 // ctype
1244 pub fn isalpha(c: c_int) -> c_int;
1245
1246 pub fn isascii(c: c_int) -> c_int;
1247
1248 pub fn isdigit(c: c_int) -> c_int;
1249
1250 pub fn islower(c: c_int) -> c_int;
1251
1252 pub fn isprint(c: c_int) -> c_int;
1253
1254 pub fn isspace(c: c_int) -> c_int;
1255
1256 pub fn iswctype(wc: wint_t, ttype: wctype_t) -> c_int;
1257
1258 pub fn iswdigit(wc: wint_t) -> c_int;
1259
1260 pub fn iswlower(wc: wint_t) -> c_int;
1261
1262 pub fn iswspace(wc: wint_t) -> c_int;
1263
1264 pub fn iswupper(wc: wint_t) -> c_int;
1265
1266 pub fn towupper(wc: wint_t) -> wint_t;
1267
1268 pub fn towlower(wc: wint_t) -> wint_t;
1269
1270 // cmath
1271 pub fn atan(x: c_double) -> c_double;
1272
1273 pub fn ceil(x: c_double) -> c_double;
1274
1275 pub fn ceilf(x: c_float) -> c_float;
1276
1277 pub fn exp(x: c_double) -> c_double;
1278
1279 pub fn fabs(x: c_double) -> c_double;
1280
1281 pub fn floor(x: c_double) -> c_double;
1282
1283 pub fn frexp(x: c_double, e: *mut c_int) -> c_double;
1284
1285 pub fn log(x: c_double) -> c_double;
1286
1287 pub fn log2(x: c_double) -> c_double;
1288
1289 pub fn pow(x: c_double, y: c_double) -> c_double;
1290
1291 pub fn roundf(x: c_float) -> c_float;
1292
1293 pub fn scalbn(x: c_double, n: c_int) -> c_double;
1294
1295 pub fn sqrt(x: c_double) -> c_double;
1296
1297 // stdlib
1298 pub fn abs(x: c_int) -> c_int;
1299
1300 pub fn atof(s: *const c_char) -> c_double;
1301
1302 pub fn atoi(s: *const c_char) -> c_int;
1303
1304 pub fn atol(s: *const c_char) -> c_long;
1305
1306 pub fn atoll(s: *const c_char) -> c_longlong;
1307
1308 pub fn bsearch(
1309 key: *const c_void,
1310 base: *const c_void,
1311 nel: size_t,
1312 width: size_t,
1313 cmp: cmpfunc,
1314 ) -> *mut c_void;
1315
1316 pub fn div(num: c_int, den: c_int) -> div_t;
1317
1318 pub fn ecvt(x: c_double, n: c_int, dp: *mut c_int, sign: *mut c_int) -> *mut c_char;
1319
1320 pub fn imaxabs(a: intmax_t) -> intmax_t;
1321
1322 pub fn llabs(a: c_longlong) -> c_longlong;
1323
1324 pub fn qsort(base: *mut c_void, nel: size_t, width: size_t, cmp: cmpfunc);
1325
1326 pub fn strtoul(s: *const c_char, p: *mut *mut c_char, base: c_int) -> c_ulong;
1327
1328 pub fn strtol(s: *const c_char, p: *mut *mut c_char, base: c_int) -> c_long;
1329
1330 pub fn wcstod(s: *const wchar_t, p: *mut *mut wchar_t) -> c_double;
1331}
1332
1333pub fn errno() -> c_int {
1334 unsafe { *__errno_location() }
1335}
1336
1337pub fn CPU_COUNT_S(size: usize, cpuset: &cpu_set_t) -> c_int {
1338 let mut s: u32 = 0;
1339 let size_of_mask = size_of_val(&cpuset.bits[0]);
1340
1341 for i in cpuset.bits[..(size / size_of_mask)].iter() {
1342 s += i.count_ones();
1343 }
1344 s as c_int
1345}
1346
1347pub fn CPU_COUNT(cpuset: &cpu_set_t) -> c_int {
1348 CPU_COUNT_S(size_of::<cpu_set_t>(), cpuset)
1349}