Skip to content

Commit 6596829

Browse files
committed
Add support for Trusty OS targets
1 parent a6386af commit 6596829

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ cfg_if! {
110110

111111
mod teeos;
112112
pub use teeos::*;
113+
} else if #[cfg(target_os = "trusty")] {
114+
mod fixed_width_ints;
115+
pub use fixed_width_ints::*;
116+
117+
mod trusty;
118+
pub use trusty::*;
113119
} else if #[cfg(all(target_env = "sgx", target_vendor = "fortanix"))] {
114120
mod fixed_width_ints;
115121
pub use fixed_width_ints::*;

src/trusty.rs

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

0 commit comments

Comments
 (0)