Skip to content

Commit 75f152d

Browse files
committed
Merge pull request #3942 from randomPoison/trusty-patch
Add Trusty OS support (backport <#3942>) (cherry picked from commit 94c7cae)
1 parent 3c40c36 commit 75f152d

File tree

3 files changed

+156
-0
lines changed

3 files changed

+156
-0
lines changed

libc-test/semver/trusty.txt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
AT_PAGESZ
2+
CLOCK_REALTIME
3+
MAP_FAILED
4+
PROT_READ
5+
PROT_WRITE
6+
STDERR_FILENO
7+
STDOUT_FILENO
8+
calloc
9+
clockid_t
10+
clock_gettime
11+
close
12+
c_char
13+
c_int
14+
c_int16_t
15+
c_int32_t
16+
c_int64_t
17+
c_int8_t
18+
c_long
19+
c_longlong
20+
c_schar
21+
c_short
22+
c_uchar
23+
c_uint
24+
c_uint16_t
25+
c_uint32_t
26+
c_uint64_t
27+
c_uint8_t
28+
c_ulong
29+
c_ulonglong
30+
c_ushort
31+
c_void
32+
free
33+
getauxval
34+
iovec
35+
malloc
36+
memalign
37+
mmap
38+
munmap
39+
nanosleep
40+
off_t
41+
posix_memalign
42+
realloc
43+
size_t
44+
ssize_t
45+
strlen
46+
timespec
47+
time_t
48+
write
49+
writev

src/lib.rs

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

146146
mod teeos;
147147
pub use teeos::*;
148+
} else if #[cfg(target_os = "trusty")] {
149+
mod fixed_width_ints;
150+
pub use fixed_width_ints::*;
151+
152+
mod trusty;
153+
pub use trusty::*;
148154
} else if #[cfg(all(target_env = "sgx", target_vendor = "fortanix"))] {
149155
mod fixed_width_ints;
150156
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+
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

Comments
 (0)