Skip to content

Commit dcd0c58

Browse files
committed
Add Trusty OS as tier 3 target
1 parent f361413 commit dcd0c58

File tree

15 files changed

+282
-1
lines changed

15 files changed

+282
-1
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,7 @@ rustc-std-workspace-core = { path = 'library/rustc-std-workspace-core' }
115115
rustc-std-workspace-alloc = { path = 'library/rustc-std-workspace-alloc' }
116116
rustc-std-workspace-std = { path = 'library/rustc-std-workspace-std' }
117117

118+
libc = { git = "https://github.com/randomPoison/libc.git", rev = "7ccd2753aa1e26301c73bdb6f9e2df8085ac39e6" }
119+
118120
[patch."https://github.com/rust-lang/rust-clippy"]
119121
clippy_lints = { path = "src/tools/clippy/clippy_lints" }
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Trusty OS target for AArch64.
2+
3+
use super::{PanicStrategy, RelroLevel, Target, TargetOptions};
4+
5+
pub fn target() -> Target {
6+
Target {
7+
llvm_target: "aarch64-unknown-linux-musl".into(),
8+
pointer_width: 64,
9+
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(),
10+
arch: "aarch64".into(),
11+
options: TargetOptions {
12+
features: "+neon,+fp-armv8".into(),
13+
executables: true,
14+
max_atomic_width: Some(128),
15+
panic_strategy: PanicStrategy::Abort,
16+
os: "trusty".into(),
17+
position_independent_executables: true,
18+
crt_static_default: true,
19+
crt_static_respected: true,
20+
dynamic_linking: false,
21+
env: "musl".into(),
22+
relro_level: RelroLevel::Full,
23+
mcount: "\u{1}_mcount".into(),
24+
..Default::default()
25+
},
26+
}
27+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use crate::spec::{Target, TargetOptions};
2+
3+
use super::{crt_objects::LinkSelfContainedDefault, PanicStrategy, RelroLevel};
4+
5+
pub fn target() -> Target {
6+
Target {
7+
// It's important we use "gnueabi" and not "musleabi" here. LLVM uses it
8+
// to determine the calling convention and float ABI, and it doesn't
9+
// support the "musleabi" value.
10+
llvm_target: "armv7-unknown-linux-gnueabi".into(),
11+
pointer_width: 32,
12+
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(),
13+
arch: "arm".into(),
14+
options: TargetOptions {
15+
abi: "eabi".into(),
16+
features: "+v7,+thumb2,+soft-float,-neon".into(),
17+
max_atomic_width: Some(64),
18+
mcount: "\u{1}mcount".into(),
19+
os: "trusty".into(),
20+
env: "musl".into(),
21+
link_self_contained: LinkSelfContainedDefault::Musl,
22+
dynamic_linking: false,
23+
executables: true,
24+
relro_level: RelroLevel::Full,
25+
panic_strategy: PanicStrategy::Abort,
26+
position_independent_executables: true,
27+
28+
..Default::default()
29+
},
30+
}
31+
}

compiler/rustc_target/src/spec/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,9 @@ supported_targets! {
11901190
("aarch64-unknown-hermit", aarch64_unknown_hermit),
11911191
("x86_64-unknown-hermit", x86_64_unknown_hermit),
11921192

1193+
("armv7-unknown-trusty", armv7_unknown_trusty),
1194+
("aarch64-unknown-trusty", aarch64_unknown_trusty),
1195+
11931196
("riscv32i-unknown-none-elf", riscv32i_unknown_none_elf),
11941197
("riscv32im-unknown-none-elf", riscv32im_unknown_none_elf),
11951198
("riscv32imc-unknown-none-elf", riscv32imc_unknown_none_elf),

library/core/src/ffi/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ mod c_char_definition {
144144
)
145145
),
146146
all(target_os = "fuchsia", target_arch = "aarch64"),
147+
all(
148+
target_os = "trusty",
149+
any(target_arch = "aarch64", target_arch = "arm")
150+
),
147151
target_os = "horizon"
148152
))] {
149153
pub type c_char = u8;

library/std/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ fn main() {
2121
|| target.contains("fuchsia")
2222
|| (target.contains("sgx") && target.contains("fortanix"))
2323
|| target.contains("hermit")
24+
|| target.contains("trusty")
2425
|| target.contains("l4re")
2526
|| target.contains("redox")
2627
|| target.contains("haiku")

library/std/src/sys/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ cfg_if::cfg_if! {
3737
} else if #[cfg(target_os = "hermit")] {
3838
mod hermit;
3939
pub use self::hermit::*;
40+
} else if #[cfg(target_os = "trusty")] {
41+
mod trusty;
42+
pub use self::trusty::*;
4043
} else if #[cfg(target_os = "wasi")] {
4144
mod wasi;
4245
pub use self::wasi::*;

library/std/src/sys/trusty/mod.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//! System bindings for the Trusty OS.
2+
3+
#[path = "../unix/alloc.rs"]
4+
pub mod alloc;
5+
#[path = "../unsupported/args.rs"]
6+
pub mod args;
7+
#[path = "../unix/cmath.rs"]
8+
pub mod cmath;
9+
#[path = "../unsupported/common.rs"]
10+
#[deny(unsafe_op_in_unsafe_fn)]
11+
mod common;
12+
#[path = "../unsupported/env.rs"]
13+
pub mod env;
14+
#[path = "../unsupported/fs.rs"]
15+
pub mod fs;
16+
#[path = "../unsupported/io.rs"]
17+
pub mod io;
18+
#[path = "../unsupported/locks/mod.rs"]
19+
pub mod locks;
20+
#[path = "../unsupported/net.rs"]
21+
pub mod net;
22+
#[path = "../unsupported/os.rs"]
23+
pub mod os;
24+
#[path = "../unix/os_str.rs"]
25+
pub mod os_str;
26+
#[path = "../unix/path.rs"]
27+
pub mod path;
28+
#[path = "../unsupported/pipe.rs"]
29+
pub mod pipe;
30+
#[path = "../unsupported/process.rs"]
31+
pub mod process;
32+
pub mod stdio;
33+
#[path = "../unsupported/thread.rs"]
34+
pub mod thread;
35+
#[cfg(target_thread_local)]
36+
#[path = "../unsupported/thread_local_dtor.rs"]
37+
pub mod thread_local_dtor;
38+
pub mod thread_local_key;
39+
#[path = "../unsupported/time.rs"]
40+
pub mod time;
41+
42+
pub use common::*;

library/std/src/sys/trusty/stdio.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
use crate::io;
2+
3+
pub struct Stdin;
4+
pub struct Stdout;
5+
pub struct Stderr;
6+
7+
impl Stdin {
8+
pub const fn new() -> Stdin {
9+
Stdin
10+
}
11+
}
12+
13+
impl io::Read for Stdin {
14+
fn read(&mut self, _buf: &mut [u8]) -> io::Result<usize> {
15+
Ok(0)
16+
}
17+
}
18+
19+
impl Stdout {
20+
pub const fn new() -> Stdout {
21+
Stdout
22+
}
23+
}
24+
25+
impl io::Write for Stdout {
26+
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
27+
_write(libc::STDOUT_FILENO, buf)
28+
}
29+
30+
fn flush(&mut self) -> io::Result<()> {
31+
Ok(())
32+
}
33+
}
34+
35+
impl Stderr {
36+
pub const fn new() -> Stderr {
37+
Stderr
38+
}
39+
}
40+
41+
impl io::Write for Stderr {
42+
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
43+
_write(libc::STDERR_FILENO, buf)
44+
}
45+
46+
fn flush(&mut self) -> io::Result<()> {
47+
Ok(())
48+
}
49+
}
50+
51+
pub const STDIN_BUF_SIZE: usize = 0;
52+
53+
pub fn is_ebadf(_err: &io::Error) -> bool {
54+
true
55+
}
56+
57+
pub fn panic_output() -> Option<impl io::Write> {
58+
Some(Stderr)
59+
}
60+
61+
fn _write(fd: i32, message: &[u8]) -> io::Result<usize> {
62+
let mut iov = libc::iovec { iov_base: message.as_ptr() as *mut _, iov_len: message.len() };
63+
loop {
64+
// SAFETY: syscall, safe arguments.
65+
let ret = unsafe { libc::writev(fd, &iov, 1) };
66+
if ret < 0 {
67+
return Err(io::Error::last_os_error());
68+
}
69+
let ret = ret as usize;
70+
if ret > iov.iov_len {
71+
return Err(io::Error::last_os_error());
72+
}
73+
if ret == iov.iov_len {
74+
return Ok(message.len());
75+
}
76+
// SAFETY: ret has been checked to be less than the length of
77+
// the buffer
78+
iov.iov_base = unsafe { iov.iov_base.add(ret) };
79+
iov.iov_len -= ret;
80+
}
81+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use crate::ptr;
2+
3+
pub type Key = usize;
4+
type Dtor = unsafe extern "C" fn(*mut u8);
5+
6+
static mut STORAGE: crate::vec::Vec<(*mut u8, Option<Dtor>)> = Vec::new();
7+
8+
#[inline]
9+
pub unsafe fn create(dtor: Option<Dtor>) -> Key {
10+
let key = STORAGE.len();
11+
STORAGE.push((ptr::null_mut(), dtor));
12+
key
13+
}
14+
15+
#[inline]
16+
pub unsafe fn set(key: Key, value: *mut u8) {
17+
STORAGE[key].0 = value;
18+
}
19+
20+
#[inline]
21+
pub unsafe fn get(key: Key) -> *mut u8 {
22+
STORAGE[key].0
23+
}
24+
25+
#[inline]
26+
pub unsafe fn destroy(_key: Key) {}
27+
28+
#[inline]
29+
pub fn requires_synchronized_create() -> bool {
30+
false
31+
}

0 commit comments

Comments
 (0)