Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Trusty platform support #2987

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ cfg_if! {

mod hermit;
pub use hermit::*;
} else if #[cfg(target_os = "trusty")] {
mod fixed_width_ints;
pub use fixed_width_ints::*;

mod trusty;
pub use trusty::*;
Comment on lines +142 to +147
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could move the module under linux_like or somewhere else similar to that. I'm not familiar with Trusty but is it completely different from Linux-like OS (i.e. exposing linux-like items on Trusty is harmful)?

} else if #[cfg(all(target_env = "sgx", target_vendor = "fortanix"))] {
mod fixed_width_ints;
pub use fixed_width_ints::*;
Expand Down
66 changes: 66 additions & 0 deletions src/trusty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
pub use core::ffi::c_void;

pub type size_t = usize;
pub type ssize_t = isize;

cfg_if! {
if #[cfg(any(target_arch = "aarch64", target_arch = "arm"))] {
pub type c_char = u8;
} else if #[cfg(target_arch = "x86_64")] {
pub type c_char = i8;
}
}

pub type c_schar = i8;
pub type c_uchar = u8;
pub type c_short = i16;
pub type c_ushort = u16;
pub type c_int = i32;
pub type c_uint = u32;

cfg_if! {
if #[cfg(target_pointer_width = "32")] {
pub type c_long = i32;
pub type c_ulong = u32;
} else if #[cfg(target_pointer_width = "64")] {
pub type c_long = i64;
pub type c_ulong = u64;
}
}

pub type c_longlong = i64;
pub type c_ulonglong = u64;

pub type c_uint8_t = u8;
pub type c_uint16_t = u16;
pub type c_uint32_t = u32;
pub type c_uint64_t = u64;

pub type c_int8_t = i8;
pub type c_int16_t = i16;
pub type c_int32_t = i32;
pub type c_int64_t = i64;

pub type time_t = c_long;

s! {
pub struct iovec {
pub iov_base: *mut ::c_void,
pub iov_len: ::size_t,
}
}

pub const STDOUT_FILENO: ::c_int = 1;
pub const STDERR_FILENO: ::c_int = 2;

extern "C" {
pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void;
pub fn malloc(size: size_t) -> *mut c_void;
pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void;
pub fn free(p: *mut c_void);
pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void;
pub fn posix_memalign(memptr: *mut *mut ::c_void, align: ::size_t, size: ::size_t) -> ::c_int;
pub fn write(fd: ::c_int, buf: *const ::c_void, count: ::size_t) -> ::ssize_t;
pub fn writev(fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int) -> ::ssize_t;
pub fn strlen(cs: *const c_char) -> size_t;
}