|
| 1 | +pub use core::ffi::c_void; |
| 2 | + |
| 3 | +pub type size_t = usize; |
| 4 | +pub type ssize_t = isize; |
| 5 | + |
| 6 | +pub type off_t = i64; |
| 7 | + |
| 8 | +cfg_if! { |
| 9 | + if #[cfg(any(target_arch = "aarch64", target_arch = "arm"))] { |
| 10 | + pub type c_char = u8; |
| 11 | + } else if #[cfg(target_arch = "x86_64")] { |
| 12 | + pub type c_char = i8; |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +pub type c_schar = i8; |
| 17 | +pub type c_uchar = u8; |
| 18 | +pub type c_short = i16; |
| 19 | +pub type c_ushort = u16; |
| 20 | +pub type c_int = i32; |
| 21 | +pub type c_uint = u32; |
| 22 | + |
| 23 | +cfg_if! { |
| 24 | + if #[cfg(target_pointer_width = "32")] { |
| 25 | + pub type c_long = i32; |
| 26 | + pub type c_ulong = u32; |
| 27 | + } else if #[cfg(target_pointer_width = "64")] { |
| 28 | + pub type c_long = i64; |
| 29 | + pub type c_ulong = u64; |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +pub type c_longlong = i64; |
| 34 | +pub type c_ulonglong = u64; |
| 35 | + |
| 36 | +pub type c_uint8_t = u8; |
| 37 | +pub type c_uint16_t = u16; |
| 38 | +pub type c_uint32_t = u32; |
| 39 | +pub type c_uint64_t = u64; |
| 40 | + |
| 41 | +pub type c_int8_t = i8; |
| 42 | +pub type c_int16_t = i16; |
| 43 | +pub type c_int32_t = i32; |
| 44 | +pub type c_int64_t = i64; |
| 45 | + |
| 46 | +pub type c_float = f32; |
| 47 | +pub type c_double = f64; |
| 48 | + |
| 49 | +pub type time_t = c_long; |
| 50 | + |
| 51 | +pub type clockid_t = c_int; |
| 52 | + |
| 53 | +s! { |
| 54 | + pub struct iovec { |
| 55 | + pub iov_base: *mut ::c_void, |
| 56 | + pub iov_len: ::size_t, |
| 57 | + } |
| 58 | + |
| 59 | + pub struct timespec { |
| 60 | + pub tv_sec: time_t, |
| 61 | + pub tv_nsec: c_long, |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +pub const PROT_READ: i32 = 1; |
| 66 | +pub const PROT_WRITE: i32 = 2; |
| 67 | + |
| 68 | +// Trusty only supports `CLOCK_BOOTTIME`. |
| 69 | +pub const CLOCK_BOOTTIME: clockid_t = 7; |
| 70 | + |
| 71 | +pub const STDOUT_FILENO: ::c_int = 1; |
| 72 | +pub const STDERR_FILENO: ::c_int = 2; |
| 73 | + |
| 74 | +pub const AT_PAGESZ: ::c_ulong = 6; |
| 75 | + |
| 76 | +pub const MAP_FAILED: *mut ::c_void = !0 as *mut ::c_void; |
| 77 | + |
| 78 | +extern "C" { |
| 79 | + pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void; |
| 80 | + pub fn malloc(size: size_t) -> *mut c_void; |
| 81 | + pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void; |
| 82 | + pub fn free(p: *mut c_void); |
| 83 | + pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void; |
| 84 | + pub fn posix_memalign(memptr: *mut *mut ::c_void, align: ::size_t, size: ::size_t) -> ::c_int; |
| 85 | + pub fn write(fd: ::c_int, buf: *const ::c_void, count: ::size_t) -> ::ssize_t; |
| 86 | + pub fn writev(fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int) -> ::ssize_t; |
| 87 | + pub fn close(fd: ::c_int) -> ::c_int; |
| 88 | + pub fn strlen(cs: *const c_char) -> size_t; |
| 89 | + pub fn getauxval(type_: c_ulong) -> c_ulong; |
| 90 | + pub fn mmap( |
| 91 | + addr: *mut ::c_void, |
| 92 | + len: ::size_t, |
| 93 | + prot: ::c_int, |
| 94 | + flags: ::c_int, |
| 95 | + fd: ::c_int, |
| 96 | + offset: off_t, |
| 97 | + ) -> *mut ::c_void; |
| 98 | + pub fn munmap(addr: *mut ::c_void, len: ::size_t) -> ::c_int; |
| 99 | + pub fn clock_gettime(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int; |
| 100 | + pub fn nanosleep(rqtp: *const ::timespec, rmtp: *mut ::timespec) -> ::c_int; |
| 101 | +} |
0 commit comments