diff --git a/build.rs b/build.rs index ea55185d77023..88f4c5149035f 100644 --- a/build.rs +++ b/build.rs @@ -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", diff --git a/libc-test/semver/trusty.txt b/libc-test/semver/trusty.txt new file mode 100644 index 0000000000000..0c79d05701095 --- /dev/null +++ b/libc-test/semver/trusty.txt @@ -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 diff --git a/src/lib.rs b/src/lib.rs index 764d8e4cd096a..893b46ff3ab28 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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::*; diff --git a/src/trusty.rs b/src/trusty.rs new file mode 100644 index 0000000000000..68b13f70b5b3f --- /dev/null +++ b/src/trusty.rs @@ -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; +} diff --git a/src/unix/haiku/mod.rs b/src/unix/haiku/mod.rs index 3a226e6696405..31f9f69d5b168 100644 --- a/src/unix/haiku/mod.rs +++ b/src/unix/haiku/mod.rs @@ -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")] diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 04baabae8bfbf..12e20a46ff1c4 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -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"))] diff --git a/src/unix/newlib/mod.rs b/src/unix/newlib/mod.rs index 78e18d8ceac72..9aee0e4ea0c3f 100644 --- a/src/unix/newlib/mod.rs +++ b/src/unix/newlib/mod.rs @@ -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; diff --git a/src/unix/nuttx/mod.rs b/src/unix/nuttx/mod.rs index e3a3c15b338cc..e9f6c651f1e86 100644 --- a/src/unix/nuttx/mod.rs +++ b/src/unix/nuttx/mod.rs @@ -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; }