Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build sgx_tstd as drop-in std replacement #1

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sgx_tstd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description = "Rust SGX SDK provides the ability to write Intel SGX applications
edition = "2018"

[lib]
name = "sgx_tstd"
name = "std"
crate-type = ["rlib"]

[features]
Expand All @@ -31,6 +31,7 @@ sgx_tprotected_fs = { path = "../sgx_tprotected_fs" }
sgx_backtrace_sys = { path = "../sgx_backtrace_sys" }
sgx_demangle = { path = "../sgx_demangle" }
sgx_unwind = { path = "../sgx_unwind" }
panic_unwind = { path = "../sgx_panic_unwind" }

[dependencies.hashbrown]
package = "hashbrown_tstd"
Expand Down
17 changes: 17 additions & 0 deletions sgx_tstd/build_sysroot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

set -e

SYSROOT_PATH="${1:-$(realpath ../../sysroot)}"
export CARGO_BUILD_TARGET="${CARGO_BUILD_TARGET:-$(rustc -vV | sed -n 's|host: ||p')}"
RUSTUP_TOOLCHAIN="${RUSTUP_TOOLCHAIN:-$(rustup show active-toolchain | cut -d' ' -f1)}"

cargo clean --target "$CARGO_BUILD_TARGET"
cargo build --release -Z build-std=core,alloc --features net,untrusted_time,untrusted_fs,thread,backtrace

mkdir -p "$SYSROOT_PATH/lib/rustlib/$CARGO_BUILD_TARGET"
rm -Rf "$SYSROOT_PATH/lib/rustlib/$CARGO_BUILD_TARGET/lib"
cp -R "$PWD/target/$CARGO_BUILD_TARGET/release/deps" "$SYSROOT_PATH/lib/rustlib/$CARGO_BUILD_TARGET/lib"

echo "Here's your environment:"
echo RUSTFLAGS=\"--sysroot $SYSROOT_PATH\" CARGO_BUILD_TARGET=\"$CARGO_BUILD_TARGET\" RUSTUP_TOOLCHAIN=\"$RUSTUP_TOOLCHAIN\"
2 changes: 2 additions & 0 deletions sgx_tstd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ pub use alloc_crate::str;
pub use alloc_crate::string;
pub use alloc_crate::vec;
pub use core::any;
pub use core::arch;
pub use core::array;
pub use core::cell;
pub use core::char;
Expand Down Expand Up @@ -240,6 +241,7 @@ pub mod num;
pub mod os;
pub mod panic;
pub mod path;
pub mod process;
pub mod sync;
pub mod time;
pub mod enclave;
Expand Down
28 changes: 28 additions & 0 deletions sgx_tstd/src/process.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use crate::os::unix::io::{IntoRawFd, RawFd};

pub struct ChildStdin;
pub struct ChildStdout;
pub struct ChildStderr;

impl IntoRawFd for ChildStdin {
fn into_raw_fd(self) -> RawFd {
unimplemented!()
}
}

impl IntoRawFd for ChildStdout {
fn into_raw_fd(self) -> RawFd {
unimplemented!()
}
}

impl IntoRawFd for ChildStderr {
fn into_raw_fd(self) -> RawFd {
unimplemented!()
}
}

#[cold]
pub fn abort() -> ! {
crate::sys::abort_internal();
}
5 changes: 5 additions & 0 deletions sgx_tstd/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ pub use self::poison::{LockResult, PoisonError, TryLockError, TryLockResult};
pub use self::rwlock::{SgxRwLock, SgxRwLockReadGuard, SgxRwLockWriteGuard, SgxThreadRwLock};
pub use self::spinlock::{SgxSpinlock, SgxSpinlockGuard, SgxThreadSpinlock};

pub use {
SgxCondvar as Condvar, SgxMutex as Mutex, SgxMutexGuard as MutexGuard, SgxRwLock as RwLock,
SgxRwLockReadGuard as RwLockReadGuard,
};

#[cfg(feature = "thread")]
pub mod mpsc;

Expand Down
6 changes: 6 additions & 0 deletions sgx_tstd/src/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ impl Builder {
self
}

pub fn stack_size(self, _size: usize) -> Builder {
self
}

/// Spawns a new thread by taking ownership of the `Builder`, and returns an
/// [`io::Result`] to its [`JoinHandle`].
///
Expand Down Expand Up @@ -879,6 +883,8 @@ pub struct SgxThread {
inner: Arc<Inner>,
}

pub use SgxThread as Thread;

impl SgxThread {
// Used only internally to construct a thread object without spawning
// Panics if the name contains nuls.
Expand Down