Skip to content

Commit

Permalink
Merge pull request #4011 from tgross35/backport-sorrel
Browse files Browse the repository at this point in the history
[0.2] Backports
  • Loading branch information
tgross35 authored Nov 6, 2024
2 parents 8fe0146 + 5b539ce commit f3d58c2
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::str;
// make sure to add it to this list as well.
const ALLOWED_CFGS: &'static [&'static str] = &[
"emscripten_new_stat_abi",
"espidf_time64",
"espidf_time32",
"freebsd10",
"freebsd11",
"freebsd12",
Expand Down
49 changes: 49 additions & 0 deletions libc-test/semver/trusty.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
AT_PAGESZ
CLOCK_REALTIME
MAP_FAILED
PROT_READ
PROT_WRITE
STDERR_FILENO
STDOUT_FILENO
calloc
clockid_t
clock_gettime
close
c_char
c_int
c_int16_t
c_int32_t
c_int64_t
c_int8_t
c_long
c_longlong
c_schar
c_short
c_uchar
c_uint
c_uint16_t
c_uint32_t
c_uint64_t
c_uint8_t
c_ulong
c_ulonglong
c_ushort
c_void
free
getauxval
iovec
malloc
memalign
mmap
munmap
nanosleep
off_t
posix_memalign
realloc
size_t
ssize_t
strlen
timespec
time_t
write
writev
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ cfg_if! {

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

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

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

pub type off_t = i64;

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 c_float = f32;
pub type c_double = f64;

pub type time_t = c_long;

pub type clockid_t = c_int;

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

pub struct timespec {
pub tv_sec: time_t,
pub tv_nsec: c_long,
}
}

pub const PROT_READ: i32 = 1;
pub const PROT_WRITE: i32 = 2;

// Trusty only supports `CLOCK_BOOTTIME`.
pub const CLOCK_BOOTTIME: clockid_t = 7;

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

pub const AT_PAGESZ: ::c_ulong = 6;

pub const MAP_FAILED: *mut ::c_void = !0 as *mut ::c_void;

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 close(fd: ::c_int) -> ::c_int;
pub fn strlen(cs: *const c_char) -> size_t;
pub fn getauxval(type_: c_ulong) -> c_ulong;
pub fn mmap(
addr: *mut ::c_void,
len: ::size_t,
prot: ::c_int,
flags: ::c_int,
fd: ::c_int,
offset: off_t,
) -> *mut ::c_void;
pub fn munmap(addr: *mut ::c_void, len: ::size_t) -> ::c_int;
pub fn clock_gettime(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int;
pub fn nanosleep(rqtp: *const ::timespec, rmtp: *mut ::timespec) -> ::c_int;
}
2 changes: 2 additions & 0 deletions src/unix/haiku/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2093,6 +2093,8 @@ extern "C" {
length: ::size_t,
locale: ::locale_t,
) -> ::c_int;

pub fn getentropy(buf: *mut ::c_void, buflen: ::size_t) -> ::c_int;
}

#[link(name = "bsd")]
Expand Down
4 changes: 2 additions & 2 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ cfg_if! {
link(name = "c", cfg(not(target_feature = "crt-static"))))]
extern {}
} else if #[cfg(target_os = "emscripten")] {
#[link(name = "c")]
extern {}
// Don't pass -lc to Emscripten, it breaks. See:
// https://github.com/emscripten-core/emscripten/issues/22758
} else if #[cfg(all(target_os = "android", feature = "rustc-dep-of-std"))] {
#[link(name = "c", kind = "static", modifiers = "-bundle",
cfg(target_feature = "crt-static"))]
Expand Down
2 changes: 1 addition & 1 deletion src/unix/newlib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ cfg_if! {
pub type useconds_t = u32;

cfg_if! {
if #[cfg(any(target_os = "horizon", all(target_os = "espidf", espidf_time64)))] {
if #[cfg(any(target_os = "horizon", all(target_os = "espidf", not(espidf_time32))))] {
pub type time_t = ::c_longlong;
} else {
pub type time_t = i32;
Expand Down
2 changes: 2 additions & 0 deletions src/unix/nuttx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,5 +551,7 @@ extern "C" {
pub fn futimens(fd: i32, times: *const timespec) -> i32;
pub fn pthread_condattr_setclock(attr: *mut pthread_condattr_t, clock_id: clockid_t) -> i32;
pub fn pthread_set_name_np(thread: pthread_t, name: *const c_char) -> i32;
pub fn pthread_setname_np(thread: pthread_t, name: *const c_char) -> i32;
pub fn pthread_getname_np(thread: pthread_t, name: *mut c_char, len: usize) -> i32;
pub fn getrandom(buf: *mut c_void, buflen: usize, flags: u32) -> isize;
}

0 comments on commit f3d58c2

Please sign in to comment.