Skip to content

Commit 646d9a5

Browse files
committed
Add patch for Trusty support
Test: make Bug: 193278128 Change-Id: I85d7f9ae04ebe0f3277d8a7bbd322655a0dfbaf6
1 parent 0f64956 commit 646d9a5

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed

patches/trusty.patch

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
From dc028fa4f316bec221c9b59d02a1c2648bb1cbbd Mon Sep 17 00:00:00 2001
2+
From: David LeGare <legare@google.com>
3+
Date: Mon, 23 May 2022 17:58:51 +0000
4+
Subject: [PATCH] Add support for the Trusty OS
5+
6+
---
7+
src/lib.rs | 6 ++++++
8+
src/trusty.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++
9+
2 files changed, 52 insertions(+)
10+
create mode 100644 src/trusty.rs
11+
12+
diff --git a/src/lib.rs b/src/lib.rs
13+
index d87d0d8e1..2eeb88c83 100644
14+
--- a/src/lib.rs
15+
+++ b/src/lib.rs
16+
@@ -141,6 +141,12 @@ cfg_if! {
17+
18+
mod hermit;
19+
pub use hermit::*;
20+
+ } else if #[cfg(target_os = "trusty")] {
21+
+ mod fixed_width_ints;
22+
+ pub use fixed_width_ints::*;
23+
+
24+
+ mod trusty;
25+
+ pub use trusty::*;
26+
} else if #[cfg(all(target_env = "sgx", target_vendor = "fortanix"))] {
27+
mod fixed_width_ints;
28+
pub use fixed_width_ints::*;
29+
diff --git a/src/trusty.rs b/src/trusty.rs
30+
new file mode 100644
31+
index 000000000..2b7d57285
32+
--- /dev/null
33+
+++ b/src/trusty.rs
34+
@@ -0,0 +1,46 @@
35+
+pub use core::ffi::c_void;
36+
+
37+
+pub type size_t = usize;
38+
+
39+
+#[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
40+
+pub type c_char = u8;
41+
+#[cfg(target_arch = "x86_64")]
42+
+pub type c_char = i8;
43+
+
44+
+pub type c_schar = i8;
45+
+pub type c_uchar = u8;
46+
+pub type c_short = i16;
47+
+pub type c_ushort = u16;
48+
+pub type c_int = i32;
49+
+pub type c_uint = u32;
50+
+
51+
+#[cfg(target_pointer_width = "32")]
52+
+pub type c_long = i32;
53+
+#[cfg(target_pointer_width = "64")]
54+
+pub type c_long = i64;
55+
+
56+
+#[cfg(target_pointer_width = "32")]
57+
+pub type c_ulong = u32;
58+
+#[cfg(target_pointer_width = "64")]
59+
+pub type c_ulong = u64;
60+
+
61+
+pub type c_longlong = i64;
62+
+pub type c_ulonglong = u64;
63+
+
64+
+pub type c_uint8_t = u8;
65+
+pub type c_uint16_t = u16;
66+
+pub type c_uint32_t = u32;
67+
+pub type c_uint64_t = u64;
68+
+
69+
+pub type c_int8_t = i8;
70+
+pub type c_int16_t = i16;
71+
+pub type c_int32_t = i32;
72+
+pub type c_int64_t = i64;
73+
+
74+
+extern "C" {
75+
+ pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void;
76+
+ pub fn malloc(size: size_t) -> *mut c_void;
77+
+ pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void;
78+
+ pub fn free(p: *mut c_void);
79+
+ pub fn posix_memalign(memptr: *mut *mut ::c_void, align: ::size_t, size: ::size_t) -> ::c_int;
80+
+}
81+
--
82+
2.36.1.124.g0e6072fb45-goog
83+

src/lib.rs

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

145145
mod hermit;
146146
pub use hermit::*;
147+
} else if #[cfg(target_os = "trusty")] {
148+
mod fixed_width_ints;
149+
pub use fixed_width_ints::*;
150+
151+
mod trusty;
152+
pub use trusty::*;
147153
} else if #[cfg(all(target_env = "sgx", target_vendor = "fortanix"))] {
148154
mod fixed_width_ints;
149155
pub use fixed_width_ints::*;

src/trusty.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
pub use core::ffi::c_void;
2+
3+
pub type size_t = usize;
4+
5+
#[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
6+
pub type c_char = u8;
7+
#[cfg(target_arch = "x86_64")]
8+
pub type c_char = i8;
9+
10+
pub type c_schar = i8;
11+
pub type c_uchar = u8;
12+
pub type c_short = i16;
13+
pub type c_ushort = u16;
14+
pub type c_int = i32;
15+
pub type c_uint = u32;
16+
17+
#[cfg(target_pointer_width = "32")]
18+
pub type c_long = i32;
19+
#[cfg(target_pointer_width = "64")]
20+
pub type c_long = i64;
21+
22+
#[cfg(target_pointer_width = "32")]
23+
pub type c_ulong = u32;
24+
#[cfg(target_pointer_width = "64")]
25+
pub type c_ulong = u64;
26+
27+
pub type c_longlong = i64;
28+
pub type c_ulonglong = u64;
29+
30+
pub type c_uint8_t = u8;
31+
pub type c_uint16_t = u16;
32+
pub type c_uint32_t = u32;
33+
pub type c_uint64_t = u64;
34+
35+
pub type c_int8_t = i8;
36+
pub type c_int16_t = i16;
37+
pub type c_int32_t = i32;
38+
pub type c_int64_t = i64;
39+
40+
extern "C" {
41+
pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void;
42+
pub fn malloc(size: size_t) -> *mut c_void;
43+
pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void;
44+
pub fn free(p: *mut c_void);
45+
pub fn posix_memalign(memptr: *mut *mut ::c_void, align: ::size_t, size: ::size_t) -> ::c_int;
46+
}

0 commit comments

Comments
 (0)