1diff --git a/src/lib.rs b/src/lib.rs 2index 1b6f0c07..71139385 100644 3--- a/src/lib.rs 4+++ b/src/lib.rs 5@@ -141,6 +141,12 @@ cfg_if! { 6 7 mod teeos; 8 pub use teeos::*; 9+ } else if #[cfg(target_os = "trusty")] { 10+ mod fixed_width_ints; 11+ pub use fixed_width_ints::*; 12+ 13+ mod trusty; 14+ pub use trusty::*; 15 } else if #[cfg(all(target_env = "sgx", target_vendor = "fortanix"))] { 16 mod fixed_width_ints; 17 pub use fixed_width_ints::*; 18diff --git a/src/trusty.rs b/src/trusty.rs 19new file mode 100644 20index 00000000..5429380e 21--- /dev/null 22+++ b/src/trusty.rs 23@@ -0,0 +1,100 @@ 24+#[cfg(feature = "trusty_sys")] 25+extern crate trusty_sys; 26+ 27+pub use core::ffi::c_void; 28+ 29+#[cfg(feature = "trusty_sys")] 30+pub const PROT_READ: i32 = self::trusty_sys::MMAP_FLAG_PROT_READ as i32; 31+ 32+#[cfg(feature = "trusty_sys")] 33+pub const PROT_WRITE: i32 = self::trusty_sys::MMAP_FLAG_PROT_WRITE as i32; 34+ 35+pub type size_t = usize; 36+pub type ssize_t = isize; 37+ 38+pub type off_t = i64; 39+ 40+#[cfg(any(target_arch = "aarch64", target_arch = "arm"))] 41+pub type c_char = u8; 42+#[cfg(target_arch = "x86_64")] 43+pub type c_char = i8; 44+ 45+pub type c_schar = i8; 46+pub type c_uchar = u8; 47+pub type c_short = i16; 48+pub type c_ushort = u16; 49+pub type c_int = i32; 50+pub type c_uint = u32; 51+ 52+#[cfg(target_pointer_width = "32")] 53+pub type c_long = i32; 54+#[cfg(target_pointer_width = "64")] 55+pub type c_long = i64; 56+ 57+#[cfg(target_pointer_width = "32")] 58+pub type c_ulong = u32; 59+#[cfg(target_pointer_width = "64")] 60+pub type c_ulong = u64; 61+ 62+pub type c_longlong = i64; 63+pub type c_ulonglong = u64; 64+ 65+pub type c_uint8_t = u8; 66+pub type c_uint16_t = u16; 67+pub type c_uint32_t = u32; 68+pub type c_uint64_t = u64; 69+ 70+pub type c_int8_t = i8; 71+pub type c_int16_t = i16; 72+pub type c_int32_t = i32; 73+pub type c_int64_t = i64; 74+ 75+pub type time_t = c_long; 76+ 77+pub type clockid_t = c_int; 78+ 79+// Trusty only supports CLOCK_BOOTTIME 80+pub const CLOCK_BOOTTIME: clockid_t = 7; 81+pub struct timespec { 82+ pub tv_sec: time_t, 83+ pub tv_nsec: c_long, 84+} 85+ 86+pub const STDOUT_FILENO: ::c_int = 1; 87+pub const STDERR_FILENO: ::c_int = 2; 88+ 89+pub const AT_PAGESZ: ::c_ulong = 6; 90+ 91+pub const MAP_FAILED: *mut ::c_void = !0 as *mut ::c_void; 92+ 93+extern "C" { 94+ pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void; 95+ pub fn malloc(size: size_t) -> *mut c_void; 96+ pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void; 97+ pub fn free(p: *mut c_void); 98+ pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void; 99+ pub fn posix_memalign(memptr: *mut *mut ::c_void, align: ::size_t, size: ::size_t) -> ::c_int; 100+ pub fn write(fd: ::c_int, buf: *const ::c_void, count: ::size_t) -> ::ssize_t; 101+ pub fn writev(fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int) -> ::ssize_t; 102+ pub fn close(fd: ::c_int) -> ::c_int; 103+ pub fn strlen(cs: *const c_char) -> size_t; 104+ pub fn getauxval(type_: c_ulong) -> c_ulong; 105+ pub fn mmap( 106+ addr: *mut ::c_void, 107+ len: ::size_t, 108+ prot: ::c_int, 109+ flags: ::c_int, 110+ fd: ::c_int, 111+ offset: off_t, 112+ ) -> *mut ::c_void; 113+ pub fn munmap(addr: *mut ::c_void, len: ::size_t) -> ::c_int; 114+ pub fn clock_gettime(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int; 115+ pub fn nanosleep(rqtp: *const ::timespec, rmtp: *mut ::timespec) -> ::c_int; 116+} 117+ 118+s! { 119+ pub struct iovec { 120+ pub iov_base: *mut ::c_void, 121+ pub iov_len: ::size_t, 122+ } 123+} 124