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