Skip to content

Commit f3d58c2

Browse files
authored
Merge pull request rust-lang#4011 from tgross35/backport-sorrel
[0.2] Backports
2 parents 8fe0146 + 5b539ce commit f3d58c2

File tree

8 files changed

+164
-4
lines changed

8 files changed

+164
-4
lines changed

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::str;
77
// make sure to add it to this list as well.
88
const ALLOWED_CFGS: &'static [&'static str] = &[
99
"emscripten_new_stat_abi",
10-
"espidf_time64",
10+
"espidf_time32",
1111
"freebsd10",
1212
"freebsd11",
1313
"freebsd12",

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+
}

src/unix/haiku/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,6 +2093,8 @@ extern "C" {
20932093
length: ::size_t,
20942094
locale: ::locale_t,
20952095
) -> ::c_int;
2096+
2097+
pub fn getentropy(buf: *mut ::c_void, buflen: ::size_t) -> ::c_int;
20962098
}
20972099

20982100
#[link(name = "bsd")]

src/unix/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,8 @@ cfg_if! {
382382
link(name = "c", cfg(not(target_feature = "crt-static"))))]
383383
extern {}
384384
} else if #[cfg(target_os = "emscripten")] {
385-
#[link(name = "c")]
386-
extern {}
385+
// Don't pass -lc to Emscripten, it breaks. See:
386+
// https://github.com/emscripten-core/emscripten/issues/22758
387387
} else if #[cfg(all(target_os = "android", feature = "rustc-dep-of-std"))] {
388388
#[link(name = "c", kind = "static", modifiers = "-bundle",
389389
cfg(target_feature = "crt-static"))]

src/unix/newlib/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ cfg_if! {
5252
pub type useconds_t = u32;
5353

5454
cfg_if! {
55-
if #[cfg(any(target_os = "horizon", all(target_os = "espidf", espidf_time64)))] {
55+
if #[cfg(any(target_os = "horizon", all(target_os = "espidf", not(espidf_time32))))] {
5656
pub type time_t = ::c_longlong;
5757
} else {
5858
pub type time_t = i32;

src/unix/nuttx/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,5 +551,7 @@ extern "C" {
551551
pub fn futimens(fd: i32, times: *const timespec) -> i32;
552552
pub fn pthread_condattr_setclock(attr: *mut pthread_condattr_t, clock_id: clockid_t) -> i32;
553553
pub fn pthread_set_name_np(thread: pthread_t, name: *const c_char) -> i32;
554+
pub fn pthread_setname_np(thread: pthread_t, name: *const c_char) -> i32;
555+
pub fn pthread_getname_np(thread: pthread_t, name: *mut c_char, len: usize) -> i32;
554556
pub fn getrandom(buf: *mut c_void, buflen: usize, flags: u32) -> isize;
555557
}

0 commit comments

Comments
 (0)