-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f361413
commit dcd0c58
Showing
15 changed files
with
282 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Trusty OS target for AArch64. | ||
|
||
use super::{PanicStrategy, RelroLevel, Target, TargetOptions}; | ||
|
||
pub fn target() -> Target { | ||
Target { | ||
llvm_target: "aarch64-unknown-linux-musl".into(), | ||
pointer_width: 64, | ||
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(), | ||
arch: "aarch64".into(), | ||
options: TargetOptions { | ||
features: "+neon,+fp-armv8".into(), | ||
executables: true, | ||
max_atomic_width: Some(128), | ||
panic_strategy: PanicStrategy::Abort, | ||
os: "trusty".into(), | ||
position_independent_executables: true, | ||
crt_static_default: true, | ||
crt_static_respected: true, | ||
dynamic_linking: false, | ||
env: "musl".into(), | ||
relro_level: RelroLevel::Full, | ||
mcount: "\u{1}_mcount".into(), | ||
..Default::default() | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use crate::spec::{Target, TargetOptions}; | ||
|
||
use super::{crt_objects::LinkSelfContainedDefault, PanicStrategy, RelroLevel}; | ||
|
||
pub fn target() -> Target { | ||
Target { | ||
// It's important we use "gnueabi" and not "musleabi" here. LLVM uses it | ||
// to determine the calling convention and float ABI, and it doesn't | ||
// support the "musleabi" value. | ||
llvm_target: "armv7-unknown-linux-gnueabi".into(), | ||
pointer_width: 32, | ||
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), | ||
arch: "arm".into(), | ||
options: TargetOptions { | ||
abi: "eabi".into(), | ||
features: "+v7,+thumb2,+soft-float,-neon".into(), | ||
max_atomic_width: Some(64), | ||
mcount: "\u{1}mcount".into(), | ||
os: "trusty".into(), | ||
env: "musl".into(), | ||
link_self_contained: LinkSelfContainedDefault::Musl, | ||
dynamic_linking: false, | ||
executables: true, | ||
relro_level: RelroLevel::Full, | ||
panic_strategy: PanicStrategy::Abort, | ||
position_independent_executables: true, | ||
|
||
..Default::default() | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//! System bindings for the Trusty OS. | ||
#[path = "../unix/alloc.rs"] | ||
pub mod alloc; | ||
#[path = "../unsupported/args.rs"] | ||
pub mod args; | ||
#[path = "../unix/cmath.rs"] | ||
pub mod cmath; | ||
#[path = "../unsupported/common.rs"] | ||
#[deny(unsafe_op_in_unsafe_fn)] | ||
mod common; | ||
#[path = "../unsupported/env.rs"] | ||
pub mod env; | ||
#[path = "../unsupported/fs.rs"] | ||
pub mod fs; | ||
#[path = "../unsupported/io.rs"] | ||
pub mod io; | ||
#[path = "../unsupported/locks/mod.rs"] | ||
pub mod locks; | ||
#[path = "../unsupported/net.rs"] | ||
pub mod net; | ||
#[path = "../unsupported/os.rs"] | ||
pub mod os; | ||
#[path = "../unix/os_str.rs"] | ||
pub mod os_str; | ||
#[path = "../unix/path.rs"] | ||
pub mod path; | ||
#[path = "../unsupported/pipe.rs"] | ||
pub mod pipe; | ||
#[path = "../unsupported/process.rs"] | ||
pub mod process; | ||
pub mod stdio; | ||
#[path = "../unsupported/thread.rs"] | ||
pub mod thread; | ||
#[cfg(target_thread_local)] | ||
#[path = "../unsupported/thread_local_dtor.rs"] | ||
pub mod thread_local_dtor; | ||
pub mod thread_local_key; | ||
#[path = "../unsupported/time.rs"] | ||
pub mod time; | ||
|
||
pub use common::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use crate::io; | ||
|
||
pub struct Stdin; | ||
pub struct Stdout; | ||
pub struct Stderr; | ||
|
||
impl Stdin { | ||
pub const fn new() -> Stdin { | ||
Stdin | ||
} | ||
} | ||
|
||
impl io::Read for Stdin { | ||
fn read(&mut self, _buf: &mut [u8]) -> io::Result<usize> { | ||
Ok(0) | ||
} | ||
} | ||
|
||
impl Stdout { | ||
pub const fn new() -> Stdout { | ||
Stdout | ||
} | ||
} | ||
|
||
impl io::Write for Stdout { | ||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> { | ||
_write(libc::STDOUT_FILENO, buf) | ||
} | ||
|
||
fn flush(&mut self) -> io::Result<()> { | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl Stderr { | ||
pub const fn new() -> Stderr { | ||
Stderr | ||
} | ||
} | ||
|
||
impl io::Write for Stderr { | ||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> { | ||
_write(libc::STDERR_FILENO, buf) | ||
} | ||
|
||
fn flush(&mut self) -> io::Result<()> { | ||
Ok(()) | ||
} | ||
} | ||
|
||
pub const STDIN_BUF_SIZE: usize = 0; | ||
|
||
pub fn is_ebadf(_err: &io::Error) -> bool { | ||
true | ||
} | ||
|
||
pub fn panic_output() -> Option<impl io::Write> { | ||
Some(Stderr) | ||
} | ||
|
||
fn _write(fd: i32, message: &[u8]) -> io::Result<usize> { | ||
let mut iov = libc::iovec { iov_base: message.as_ptr() as *mut _, iov_len: message.len() }; | ||
loop { | ||
// SAFETY: syscall, safe arguments. | ||
let ret = unsafe { libc::writev(fd, &iov, 1) }; | ||
if ret < 0 { | ||
return Err(io::Error::last_os_error()); | ||
} | ||
let ret = ret as usize; | ||
if ret > iov.iov_len { | ||
return Err(io::Error::last_os_error()); | ||
} | ||
if ret == iov.iov_len { | ||
return Ok(message.len()); | ||
} | ||
// SAFETY: ret has been checked to be less than the length of | ||
// the buffer | ||
iov.iov_base = unsafe { iov.iov_base.add(ret) }; | ||
iov.iov_len -= ret; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use crate::ptr; | ||
|
||
pub type Key = usize; | ||
type Dtor = unsafe extern "C" fn(*mut u8); | ||
|
||
static mut STORAGE: crate::vec::Vec<(*mut u8, Option<Dtor>)> = Vec::new(); | ||
|
||
#[inline] | ||
pub unsafe fn create(dtor: Option<Dtor>) -> Key { | ||
let key = STORAGE.len(); | ||
STORAGE.push((ptr::null_mut(), dtor)); | ||
key | ||
} | ||
|
||
#[inline] | ||
pub unsafe fn set(key: Key, value: *mut u8) { | ||
STORAGE[key].0 = value; | ||
} | ||
|
||
#[inline] | ||
pub unsafe fn get(key: Key) -> *mut u8 { | ||
STORAGE[key].0 | ||
} | ||
|
||
#[inline] | ||
pub unsafe fn destroy(_key: Key) {} | ||
|
||
#[inline] | ||
pub fn requires_synchronized_create() -> bool { | ||
false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# `aarch64-unknown-trusty` and `armv7-unknown-trusty` | ||
|
||
**Tier: 3** | ||
|
||
[Trusty] is a secure Operating System that provides a Trusted Execution | ||
Environment (TEE) for Android. | ||
|
||
## Target maintainers | ||
|
||
- David LeGare, `dgl@immunant.com`, https://github.com/randomPoison | ||
|
||
## Requirements | ||
|
||
This target is cross-compiled. It has no special requirements for the host. | ||
|
||
It fully supports alloc with the default allocator, and partially supports std. | ||
Notably, most I/O functionality is not supported, e.g. filesystem support and | ||
networking support are not present and any APIs that rely on them will panic at | ||
runtime. | ||
|
||
Trusty uses the ELF file format. | ||
|
||
## Building the target | ||
|
||
The targets can be built by enabling them for a `rustc` build, for example: | ||
|
||
```toml | ||
[build] | ||
build-stage = 1 | ||
target = ["aarch64-unknown-trusty", "armv7-unknown-trusty"] | ||
``` | ||
|
||
## Building Rust programs | ||
|
||
There is currently no supported way to build a Trusty app with Cargo. You can | ||
follow the [Trusty build instructions] to build the Trusty kernel along with any | ||
Rust apps that are setup in the project. | ||
|
||
## Testing | ||
|
||
See the [Trusty build instructions] for information on how to build Rust code | ||
within the main Trusty project. The main project also includes infrastructure | ||
for testing Rust applications within a QEMU emulator. | ||
|
||
## Cross-compilation toolchains and C code | ||
|
||
See the [Trusty build instructions] for information on how C code is built | ||
within Trusty. | ||
|
||
[Trusty]: https://source.android.com/docs/security/features/trusty | ||
[Trusty build instructions]: https://source.android.com/docs/security/features/trusty/download-and-build |