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