From f0f6beb18dcf6c1212086e507b4ecc57dbc5c797 Mon Sep 17 00:00:00 2001 From: Mohsen Zohrevandi Date: Thu, 28 Jul 2022 11:50:18 -0700 Subject: [PATCH] Post rebase fixes - Move async-usercalls to intel-sgx directory - Remove hacks/unsafe_typecasts.rs - Fix some typos in docs - Use marker trait for MakeSend to avoid warnings about issue #93367 - Update crossbeam and crossbeam-channel dependencies - Use nightly Rust in CI - Use SGX target for generating docs when crate has `feature(sgx_platform)` --- .travis.yml | 2 +- Cargo.lock | 110 ++++++++++++------ async-usercalls/src/hacks/unsafe_typecasts.rs | 95 --------------- doc/generate-api-docs.sh | 3 + .../async-usercalls}/Cargo.toml | 4 +- .../async-usercalls}/src/batch_drop.rs | 0 .../async-usercalls}/src/callback.rs | 0 .../async-usercalls}/src/duplicated.rs | 0 .../src/hacks/async_queues.rs | 0 .../async-usercalls}/src/hacks/mod.rs | 20 ++-- .../async-usercalls}/src/io_bufs.rs | 4 +- .../async-usercalls}/src/lib.rs | 0 .../async-usercalls}/src/provider_api.rs | 49 ++++---- .../async-usercalls}/src/provider_core.rs | 0 .../async-usercalls}/src/queues.rs | 0 .../async-usercalls}/src/raw.rs | 0 .../async-usercalls}/src/test_support.rs | 0 .../async-usercalls}/test.sh | 0 intel-sgx/enclave-runner/Cargo.toml | 2 +- intel-sgx/enclave-runner/src/usercalls/mod.rs | 16 +-- intel-sgx/fortanix-sgx-abi/src/lib.rs | 18 +-- ipc-queue/src/fifo.rs | 2 +- 22 files changed, 140 insertions(+), 185 deletions(-) delete mode 100644 async-usercalls/src/hacks/unsafe_typecasts.rs rename {async-usercalls => intel-sgx/async-usercalls}/Cargo.toml (89%) rename {async-usercalls => intel-sgx/async-usercalls}/src/batch_drop.rs (100%) rename {async-usercalls => intel-sgx/async-usercalls}/src/callback.rs (100%) rename {async-usercalls => intel-sgx/async-usercalls}/src/duplicated.rs (100%) rename {async-usercalls => intel-sgx/async-usercalls}/src/hacks/async_queues.rs (100%) rename {async-usercalls => intel-sgx/async-usercalls}/src/hacks/mod.rs (71%) rename {async-usercalls => intel-sgx/async-usercalls}/src/io_bufs.rs (98%) rename {async-usercalls => intel-sgx/async-usercalls}/src/lib.rs (100%) rename {async-usercalls => intel-sgx/async-usercalls}/src/provider_api.rs (80%) rename {async-usercalls => intel-sgx/async-usercalls}/src/provider_core.rs (100%) rename {async-usercalls => intel-sgx/async-usercalls}/src/queues.rs (100%) rename {async-usercalls => intel-sgx/async-usercalls}/src/raw.rs (100%) rename {async-usercalls => intel-sgx/async-usercalls}/src/test_support.rs (100%) rename {async-usercalls => intel-sgx/async-usercalls}/test.sh (100%) diff --git a/.travis.yml b/.travis.yml index b83d89ddb..0fdc796e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,7 @@ matrix: - clang-11 - musl-tools rust: - - stable + - nightly env: - RUST_BACKTRACE=1 - CFLAGS_x86_64_fortanix_unknown_sgx="-isystem/usr/include/x86_64-linux-gnu -mlvi-hardening -mllvm -x86-experimental-lvi-inline-asm-hardening" diff --git a/Cargo.lock b/Cargo.lock index 7525fa781..ba881af96 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -68,7 +68,7 @@ dependencies = [ "fnv", "fortanix-sgx-abi", "ipc-queue", - "lazy_static 1.4.0", + "lazy_static", ] [[package]] @@ -523,26 +523,26 @@ dependencies = [ [[package]] name = "crossbeam" -version = "0.7.3" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69323bff1fb41c635347b8ead484a5ca6c3f11914d784170b158d8449ab07f8e" +checksum = "2801af0d36612ae591caa9568261fddce32ce6e08a7275ea334a06a4ad021a2c" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "crossbeam-channel", - "crossbeam-deque", - "crossbeam-epoch", - "crossbeam-queue", - "crossbeam-utils", + "crossbeam-deque 0.8.2", + "crossbeam-epoch 0.9.10", + "crossbeam-queue 0.3.6", + "crossbeam-utils 0.8.11", ] [[package]] name = "crossbeam-channel" -version = "0.4.4" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b153fe7cbef478c567df0f972e02e6d736db11affe43dfc9c56a9374d1adfb87" +checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" dependencies = [ - "crossbeam-utils", - "maybe-uninit", + "cfg-if 1.0.0", + "crossbeam-utils 0.8.11", ] [[package]] @@ -551,11 +551,22 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285" dependencies = [ - "crossbeam-epoch", - "crossbeam-utils", + "crossbeam-epoch 0.8.2", + "crossbeam-utils 0.7.2", "maybe-uninit", ] +[[package]] +name = "crossbeam-deque" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-epoch 0.9.10", + "crossbeam-utils 0.8.11", +] + [[package]] name = "crossbeam-epoch" version = "0.8.2" @@ -564,13 +575,27 @@ checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" dependencies = [ "autocfg 1.0.1", "cfg-if 0.1.10", - "crossbeam-utils", + "crossbeam-utils 0.7.2", "lazy_static", "maybe-uninit", "memoffset 0.5.6", "scopeguard", ] +[[package]] +name = "crossbeam-epoch" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "045ebe27666471bb549370b4b0b3e51b07f56325befa4284db65fc89c02511b1" +dependencies = [ + "autocfg 1.0.1", + "cfg-if 1.0.0", + "crossbeam-utils 0.8.11", + "memoffset 0.6.4", + "once_cell", + "scopeguard", +] + [[package]] name = "crossbeam-queue" version = "0.2.3" @@ -578,10 +603,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570" dependencies = [ "cfg-if 0.1.10", - "crossbeam-utils", + "crossbeam-utils 0.7.2", "maybe-uninit", ] +[[package]] +name = "crossbeam-queue" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd42583b04998a5363558e5f9291ee5a5ff6b49944332103f251e7479a82aa7" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-utils 0.8.11", +] + [[package]] name = "crossbeam-utils" version = "0.7.2" @@ -593,6 +628,16 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "crossbeam-utils" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" +dependencies = [ + "cfg-if 1.0.0", + "once_cell", +] + [[package]] name = "crypto-hash" version = "0.3.4" @@ -923,7 +968,7 @@ dependencies = [ "sha2 0.9.8", "shiplift", "tempfile", - "tokio 1.14.0", + "tokio 1.16.1", "url 2.1.1", ] @@ -1566,7 +1611,7 @@ dependencies = [ "itoa 0.4.6", "pin-project-lite 0.2.7", "socket2", - "tokio 1.14.0", + "tokio 1.16.1", "tower-service", "tracing", "want 0.3.0", @@ -1585,7 +1630,7 @@ dependencies = [ "openssl", "openssl-sys", "parking_lot 0.11.2", - "tokio 1.14.0", + "tokio 1.16.1", "tokio-openssl", "tower-layer", ] @@ -1613,7 +1658,7 @@ dependencies = [ "hex 0.4.3", "hyper 0.14.15", "pin-project 1.0.8", - "tokio 1.14.0", + "tokio 1.16.1", ] [[package]] @@ -1668,7 +1713,7 @@ dependencies = [ "futures-core", "inotify-sys", "libc", - "tokio 1.14.0", + "tokio 1.16.1", ] [[package]] @@ -2755,7 +2800,7 @@ version = "2.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6653d384a260fedff0a466e894e05c5b8d75e261a14e9f93e81e43ef86cad23" dependencies = [ - "log 0.4.14", + "log 0.3.9", "which 4.0.2", ] @@ -3487,7 +3532,7 @@ dependencies = [ "serde", "serde_json", "tar", - "tokio 1.14.0", + "tokio 1.16.1", "url 2.1.1", ] @@ -3767,11 +3812,10 @@ dependencies = [ [[package]] name = "tokio" -version = "1.14.0" +version = "1.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70e992e41e0d2fb9f755b37446f20900f64446ef54874f40a60c78f021ac6144" +checksum = "0c27a64b625de6d309e8c57716ba93021dccf1b3b5c97edd6d3dd2d2135afc0a" dependencies = [ - "autocfg 1.0.1", "libc", "mio 0.7.14", "num_cpus", @@ -3806,7 +3850,7 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb2d1b8f4548dbf5e1f7818512e9c406860678f29c300cdf0ebac72d1a3a1671" dependencies = [ - "crossbeam-utils", + "crossbeam-utils 0.7.2", "futures 0.1.30", ] @@ -3841,7 +3885,7 @@ dependencies = [ "futures-util", "openssl", "openssl-sys", - "tokio 1.14.0", + "tokio 1.16.1", ] [[package]] @@ -3850,7 +3894,7 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09bc590ec4ba8ba87652da2068d150dcada2cfa2e07faae270a5e0409aa51351" dependencies = [ - "crossbeam-utils", + "crossbeam-utils 0.7.2", "futures 0.1.30", "lazy_static", "log 0.4.14", @@ -3893,9 +3937,9 @@ version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df720b6581784c118f0eb4310796b12b1d242a7eb95f716a8367855325c25f89" dependencies = [ - "crossbeam-deque", - "crossbeam-queue", - "crossbeam-utils", + "crossbeam-deque 0.7.3", + "crossbeam-queue 0.2.3", + "crossbeam-utils 0.7.2", "futures 0.1.30", "lazy_static", "log 0.4.14", @@ -3910,7 +3954,7 @@ version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93044f2d313c95ff1cb7809ce9a7a05735b012288a888b62d4434fd58c94f296" dependencies = [ - "crossbeam-utils", + "crossbeam-utils 0.7.2", "futures 0.1.30", "slab", "tokio-executor", diff --git a/async-usercalls/src/hacks/unsafe_typecasts.rs b/async-usercalls/src/hacks/unsafe_typecasts.rs deleted file mode 100644 index 1e3d67c5e..000000000 --- a/async-usercalls/src/hacks/unsafe_typecasts.rs +++ /dev/null @@ -1,95 +0,0 @@ -//! The incredibly unsafe code in this module allows us to create -//! `std::net::TcpStream` and `std::net::TcpListener` types from their raw -//! components in SGX. -//! -//! This is obviously very unsafe and not maintainable and is only intended as -//! an iterim solution until we add similar functionality as extension traits -//! in `std::os::fortanix_sgx`. -use fortanix_sgx_abi::Fd; - -mod sgx { - use fortanix_sgx_abi::Fd; - use std::sync::Arc; - - #[derive(Debug)] - pub struct FileDesc { - fd: Fd, - } - - #[derive(Debug, Clone)] - pub struct Socket { - inner: Arc, - local_addr: Option, - } - - #[derive(Clone)] - pub struct TcpStream { - inner: Socket, - peer_addr: Option, - } - - impl TcpStream { - pub fn new(fd: Fd, local_addr: Option, peer_addr: Option) -> TcpStream { - TcpStream { - inner: Socket { - inner: Arc::new(FileDesc { fd }), - local_addr, - }, - peer_addr, - } - } - } - - #[derive(Clone)] - pub struct TcpListener { - inner: Socket, - } - - impl TcpListener { - pub fn new(fd: Fd, local_addr: Option) -> TcpListener { - TcpListener { - inner: Socket { - inner: Arc::new(FileDesc { fd }), - local_addr, - }, - } - } - } -} - -struct TcpStream(self::sgx::TcpStream); -struct TcpListener(self::sgx::TcpListener); - -pub unsafe fn new_std_stream(fd: Fd, local_addr: Option, peer_addr: Option) -> std::net::TcpStream { - let stream = TcpStream(sgx::TcpStream::new(fd, local_addr, peer_addr)); - std::mem::transmute(stream) -} - -pub unsafe fn new_std_listener(fd: Fd, local_addr: Option) -> std::net::TcpListener { - let listener = TcpListener(sgx::TcpListener::new(fd, local_addr)); - std::mem::transmute(listener) -} - -#[cfg(test)] -mod tests { - use super::*; - use std::mem; - use std::os::fortanix_sgx::io::AsRawFd; - - #[test] - fn sanity_check() { - let fd = 42; - let local = "1.2.3.4:1234"; - let peer = "5.6.7.8:443"; - let stream = unsafe { new_std_stream(fd, Some(local.to_owned()), Some(peer.to_owned())) }; - assert_eq!(stream.as_raw_fd(), fd); - assert_eq!(stream.local_addr().unwrap().to_string(), local); - assert_eq!(stream.peer_addr().unwrap().to_string(), peer); - mem::forget(stream); // not a real stream... - - let listener = unsafe { new_std_listener(fd, Some(local.to_owned())) }; - assert_eq!(listener.as_raw_fd(), fd); - assert_eq!(listener.local_addr().unwrap().to_string(), local); - mem::forget(listener); // not a real listener... - } -} diff --git a/doc/generate-api-docs.sh b/doc/generate-api-docs.sh index b25386ffc..dcdcebb94 100755 --- a/doc/generate-api-docs.sh +++ b/doc/generate-api-docs.sh @@ -58,6 +58,9 @@ for LIB in $LIBS_SORTED; do if FEATURES="$(cargo read-manifest|jq -r '.metadata.docs.rs.features | join(",")' 2> /dev/null)"; then ARGS="--features $FEATURES" fi + if grep -q 'feature(sgx_platform)' ./src/lib.rs; then + ARGS="$ARGS --target x86_64-fortanix-unknown-sgx" + fi cargo doc --no-deps --lib $ARGS popd fi diff --git a/async-usercalls/Cargo.toml b/intel-sgx/async-usercalls/Cargo.toml similarity index 89% rename from async-usercalls/Cargo.toml rename to intel-sgx/async-usercalls/Cargo.toml index c0cd25a06..1efbc98fc 100644 --- a/async-usercalls/Cargo.toml +++ b/intel-sgx/async-usercalls/Cargo.toml @@ -17,12 +17,12 @@ categories = ["asynchronous"] [dependencies] # Project dependencies -ipc-queue = { version = "0.1", path = "../ipc-queue" } +ipc-queue = { version = "0.2", path = "../../ipc-queue" } fortanix-sgx-abi = { version = "0.4", path = "../fortanix-sgx-abi" } # External dependencies lazy_static = "1.4.0" # MIT/Apache-2.0 -crossbeam-channel = "0.4" # MIT/Apache-2.0 +crossbeam-channel = "0.5" # MIT/Apache-2.0 fnv = "1.0" # MIT/Apache-2.0 # For cargo test --target x86_64-fortanix-unknown-sgx diff --git a/async-usercalls/src/batch_drop.rs b/intel-sgx/async-usercalls/src/batch_drop.rs similarity index 100% rename from async-usercalls/src/batch_drop.rs rename to intel-sgx/async-usercalls/src/batch_drop.rs diff --git a/async-usercalls/src/callback.rs b/intel-sgx/async-usercalls/src/callback.rs similarity index 100% rename from async-usercalls/src/callback.rs rename to intel-sgx/async-usercalls/src/callback.rs diff --git a/async-usercalls/src/duplicated.rs b/intel-sgx/async-usercalls/src/duplicated.rs similarity index 100% rename from async-usercalls/src/duplicated.rs rename to intel-sgx/async-usercalls/src/duplicated.rs diff --git a/async-usercalls/src/hacks/async_queues.rs b/intel-sgx/async-usercalls/src/hacks/async_queues.rs similarity index 100% rename from async-usercalls/src/hacks/async_queues.rs rename to intel-sgx/async-usercalls/src/hacks/async_queues.rs diff --git a/async-usercalls/src/hacks/mod.rs b/intel-sgx/async-usercalls/src/hacks/mod.rs similarity index 71% rename from async-usercalls/src/hacks/mod.rs rename to intel-sgx/async-usercalls/src/hacks/mod.rs index 9011c63e8..5fe7a2df9 100644 --- a/async-usercalls/src/hacks/mod.rs +++ b/intel-sgx/async-usercalls/src/hacks/mod.rs @@ -3,10 +3,8 @@ use std::os::fortanix_sgx::usercalls::alloc::{User, UserSafeSized}; use std::os::fortanix_sgx::usercalls::raw::ByteBuffer; mod async_queues; -mod unsafe_typecasts; pub use self::async_queues::{alloc_descriptor, async_queues, to_enclave}; -pub use self::unsafe_typecasts::{new_std_listener, new_std_stream}; #[repr(C)] #[derive(Copy, Clone, Default)] @@ -26,10 +24,12 @@ pub struct Cancel; unsafe impl UserSafeSized for Cancel {} +pub(crate) trait MakeSendMarker {} + // Interim solution until we mark the target types appropriately -pub(crate) struct MakeSend(T); +pub(crate) struct MakeSend(T); -impl MakeSend { +impl MakeSend { pub fn new(t: T) -> Self { Self(t) } @@ -40,7 +40,7 @@ impl MakeSend { } } -impl Deref for MakeSend { +impl Deref for MakeSend { type Target = T; fn deref(&self) -> &Self::Target { @@ -48,12 +48,14 @@ impl Deref for MakeSend { } } -impl DerefMut for MakeSend { +impl DerefMut for MakeSend { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } } -unsafe impl Send for MakeSend {} -unsafe impl Send for MakeSend> {} -unsafe impl Send for MakeSend> {} +unsafe impl Send for MakeSend {} + +impl MakeSendMarker for ByteBuffer {} +impl MakeSendMarker for User {} +impl MakeSendMarker for User<[u8]> {} diff --git a/async-usercalls/src/io_bufs.rs b/intel-sgx/async-usercalls/src/io_bufs.rs similarity index 98% rename from async-usercalls/src/io_bufs.rs rename to intel-sgx/async-usercalls/src/io_bufs.rs index a8ede0de9..c86df75f4 100644 --- a/async-usercalls/src/io_bufs.rs +++ b/intel-sgx/async-usercalls/src/io_bufs.rs @@ -166,9 +166,9 @@ impl WriteBuffer { assert!(n <= buf.len()); const PANIC_MESSAGE: &'static str = "`buf` not produced by self.consumable_chunk()"; let buf = buf.into_shared().expect(PANIC_MESSAGE); - assert!(Arc::ptr_eq(&self.userbuf, &buf), PANIC_MESSAGE); + assert!(Arc::ptr_eq(&self.userbuf, &buf), "{}", PANIC_MESSAGE); drop(buf); - assert!(Arc::strong_count(&self.userbuf) == 1, PANIC_MESSAGE); + assert!(Arc::strong_count(&self.userbuf) == 1, "{}", PANIC_MESSAGE); self.advance_read(n); } diff --git a/async-usercalls/src/lib.rs b/intel-sgx/async-usercalls/src/lib.rs similarity index 100% rename from async-usercalls/src/lib.rs rename to intel-sgx/async-usercalls/src/lib.rs diff --git a/async-usercalls/src/provider_api.rs b/intel-sgx/async-usercalls/src/provider_api.rs similarity index 80% rename from async-usercalls/src/provider_api.rs rename to intel-sgx/async-usercalls/src/provider_api.rs index 234dbddb6..ca307b173 100644 --- a/async-usercalls/src/provider_api.rs +++ b/intel-sgx/async-usercalls/src/provider_api.rs @@ -1,5 +1,5 @@ use crate::batch_drop; -use crate::hacks::{new_std_listener, new_std_stream, MakeSend}; +use crate::hacks::MakeSend; use crate::io_bufs::UserBuf; use crate::raw::RawApi; use crate::{AsyncUsercallProvider, CancelHandle}; @@ -7,6 +7,7 @@ use fortanix_sgx_abi::Fd; use std::io; use std::mem::{self, ManuallyDrop}; use std::net::{TcpListener, TcpStream}; +use std::os::fortanix_sgx::io::{FromRawFd, TcpListenerMetadata, TcpStreamMetadata}; use std::os::fortanix_sgx::usercalls::alloc::{User, UserRef, UserSafe}; use std::os::fortanix_sgx::usercalls::raw::ByteBuffer; use std::time::{Duration, SystemTime, UNIX_EPOCH}; @@ -93,18 +94,18 @@ impl AsyncUsercallProvider { F: FnOnce(io::Result) + Send + 'static, { let mut addr_buf = ManuallyDrop::new(MakeSend::new(User::<[u8]>::uninitialized(addr.len()))); - let mut local_addr = ManuallyDrop::new(MakeSend::new(User::::uninitialized())); + let mut local_addr_buf = ManuallyDrop::new(MakeSend::new(User::::uninitialized())); addr_buf[0..addr.len()].copy_from_enclave(addr.as_bytes()); let addr_buf_ptr = addr_buf.as_raw_mut_ptr() as *mut u8; - let local_addr_ptr = local_addr.as_raw_mut_ptr(); + let local_addr_ptr = local_addr_buf.as_raw_mut_ptr(); let cb = move |res: io::Result| { let _addr_buf = ManuallyDrop::into_inner(addr_buf); - let local_addr = ManuallyDrop::into_inner(local_addr); + let local_addr_buf = ManuallyDrop::into_inner(local_addr_buf); - let local = string_from_bytebuffer(&local_addr, "bind_stream", "local_addr"); - let res = res.map(|fd| unsafe { new_std_listener(fd, Some(local)) }); + let local_addr = Some(string_from_bytebuffer(&local_addr_buf, "bind_stream", "local_addr")); + let res = res.map(|fd| unsafe { TcpListener::from_raw_fd(fd, TcpListenerMetadata { local_addr }) }); callback(res); }; unsafe { self.raw_bind_stream(addr_buf_ptr, addr.len(), local_addr_ptr, Some(cb.into())) } @@ -120,19 +121,19 @@ impl AsyncUsercallProvider { where F: FnOnce(io::Result) + Send + 'static, { - let mut local_addr = ManuallyDrop::new(MakeSend::new(User::::uninitialized())); - let mut peer_addr = ManuallyDrop::new(MakeSend::new(User::::uninitialized())); + let mut local_addr_buf = ManuallyDrop::new(MakeSend::new(User::::uninitialized())); + let mut peer_addr_buf = ManuallyDrop::new(MakeSend::new(User::::uninitialized())); - let local_addr_ptr = local_addr.as_raw_mut_ptr(); - let peer_addr_ptr = peer_addr.as_raw_mut_ptr(); + let local_addr_ptr = local_addr_buf.as_raw_mut_ptr(); + let peer_addr_ptr = peer_addr_buf.as_raw_mut_ptr(); let cb = move |res: io::Result| { - let local_addr = ManuallyDrop::into_inner(local_addr); - let peer_addr = ManuallyDrop::into_inner(peer_addr); + let local_addr_buf = ManuallyDrop::into_inner(local_addr_buf); + let peer_addr_buf = ManuallyDrop::into_inner(peer_addr_buf); - let local = string_from_bytebuffer(&*local_addr, "accept_stream", "local_addr"); - let peer = string_from_bytebuffer(&*peer_addr, "accept_stream", "peer_addr"); - let res = res.map(|fd| unsafe { new_std_stream(fd, Some(local), Some(peer)) }); + let local_addr = Some(string_from_bytebuffer(&*local_addr_buf, "accept_stream", "local_addr")); + let peer_addr = Some(string_from_bytebuffer(&*peer_addr_buf, "accept_stream", "peer_addr")); + let res = res.map(|fd| unsafe { TcpStream::from_raw_fd(fd, TcpStreamMetadata { local_addr, peer_addr }) }); callback(res); }; unsafe { self.raw_accept_stream(fd, local_addr_ptr, peer_addr_ptr, Some(cb.into())) } @@ -149,22 +150,22 @@ impl AsyncUsercallProvider { F: FnOnce(io::Result) + Send + 'static, { let mut addr_buf = ManuallyDrop::new(MakeSend::new(User::<[u8]>::uninitialized(addr.len()))); - let mut local_addr = ManuallyDrop::new(MakeSend::new(User::::uninitialized())); - let mut peer_addr = ManuallyDrop::new(MakeSend::new(User::::uninitialized())); + let mut local_addr_buf = ManuallyDrop::new(MakeSend::new(User::::uninitialized())); + let mut peer_addr_buf = ManuallyDrop::new(MakeSend::new(User::::uninitialized())); addr_buf[0..addr.len()].copy_from_enclave(addr.as_bytes()); let addr_buf_ptr = addr_buf.as_raw_mut_ptr() as *mut u8; - let local_addr_ptr = local_addr.as_raw_mut_ptr(); - let peer_addr_ptr = peer_addr.as_raw_mut_ptr(); + let local_addr_ptr = local_addr_buf.as_raw_mut_ptr(); + let peer_addr_ptr = peer_addr_buf.as_raw_mut_ptr(); let cb = move |res: io::Result| { let _addr_buf = ManuallyDrop::into_inner(addr_buf); - let local_addr = ManuallyDrop::into_inner(local_addr); - let peer_addr = ManuallyDrop::into_inner(peer_addr); + let local_addr_buf = ManuallyDrop::into_inner(local_addr_buf); + let peer_addr_buf = ManuallyDrop::into_inner(peer_addr_buf); - let local = string_from_bytebuffer(&local_addr, "connect_stream", "local_addr"); - let peer = string_from_bytebuffer(&peer_addr, "connect_stream", "peer_addr"); - let res = res.map(|fd| unsafe { new_std_stream(fd, Some(local), Some(peer)) }); + let local_addr = Some(string_from_bytebuffer(&local_addr_buf, "connect_stream", "local_addr")); + let peer_addr = Some(string_from_bytebuffer(&peer_addr_buf, "connect_stream", "peer_addr")); + let res = res.map(|fd| unsafe { TcpStream::from_raw_fd(fd, TcpStreamMetadata { local_addr, peer_addr }) }); callback(res); }; unsafe { self.raw_connect_stream(addr_buf_ptr, addr.len(), local_addr_ptr, peer_addr_ptr, Some(cb.into())) } diff --git a/async-usercalls/src/provider_core.rs b/intel-sgx/async-usercalls/src/provider_core.rs similarity index 100% rename from async-usercalls/src/provider_core.rs rename to intel-sgx/async-usercalls/src/provider_core.rs diff --git a/async-usercalls/src/queues.rs b/intel-sgx/async-usercalls/src/queues.rs similarity index 100% rename from async-usercalls/src/queues.rs rename to intel-sgx/async-usercalls/src/queues.rs diff --git a/async-usercalls/src/raw.rs b/intel-sgx/async-usercalls/src/raw.rs similarity index 100% rename from async-usercalls/src/raw.rs rename to intel-sgx/async-usercalls/src/raw.rs diff --git a/async-usercalls/src/test_support.rs b/intel-sgx/async-usercalls/src/test_support.rs similarity index 100% rename from async-usercalls/src/test_support.rs rename to intel-sgx/async-usercalls/src/test_support.rs diff --git a/async-usercalls/test.sh b/intel-sgx/async-usercalls/test.sh similarity index 100% rename from async-usercalls/test.sh rename to intel-sgx/async-usercalls/test.sh diff --git a/intel-sgx/enclave-runner/Cargo.toml b/intel-sgx/enclave-runner/Cargo.toml index 1b7bbb4ef..94e0ecd21 100644 --- a/intel-sgx/enclave-runner/Cargo.toml +++ b/intel-sgx/enclave-runner/Cargo.toml @@ -33,7 +33,7 @@ lazy_static = "1.2.0" # MIT/Apache-2.0 libc = "0.2.48" # MIT/Apache-2.0 nix = "0.13.0" # MIT openssl = { version = "0.10", optional = true } # Apache-2.0 -crossbeam = "0.7.1" # MIT/Apache-2.0 +crossbeam = "0.8.0" # MIT/Apache-2.0 num_cpus = "1.10.0" # MIT/Apache-2.0 tokio = { version = "0.2", features = ["full"] } # MIT futures = { version = "0.3", features = ["compat", "io-compat"] } # MIT/Apache-2.0 diff --git a/intel-sgx/enclave-runner/src/usercalls/mod.rs b/intel-sgx/enclave-runner/src/usercalls/mod.rs index 3ffcb7875..2ed43e013 100644 --- a/intel-sgx/enclave-runner/src/usercalls/mod.rs +++ b/intel-sgx/enclave-runner/src/usercalls/mod.rs @@ -501,7 +501,7 @@ struct StoppedTcs { struct IOHandlerInput<'tcs> { tcs: Option<&'tcs mut RunningTcs>, enclave: Arc, - work_sender: &'tcs crossbeam::crossbeam_channel::Sender, + work_sender: &'tcs crossbeam::channel::Sender, } struct PendingEvents { @@ -773,7 +773,7 @@ impl EnclaveState { async fn handle_usercall( enclave: Arc, - work_sender: crossbeam::crossbeam_channel::Sender, + work_sender: crossbeam::channel::Sender, tx_return_channel: tokio::sync::mpsc::UnboundedSender<(EnclaveResult, ReturnSource)>, mut handle_data: UsercallHandleData, ) { @@ -865,7 +865,7 @@ impl EnclaveState { enclave: Arc, io_queue_receive: tokio::sync::mpsc::UnboundedReceiver, io_queue_send: tokio::sync::mpsc::UnboundedSender, - work_sender: crossbeam::crossbeam_channel::Sender, + work_sender: crossbeam::channel::Sender, ) -> EnclaveResult { let (tx_return_channel, mut rx_return_channel) = tokio::sync::mpsc::unbounded_channel(); let enclave_clone = enclave.clone(); @@ -1054,7 +1054,7 @@ impl EnclaveState { ) -> EnclaveResult { fn create_worker_threads( num_of_worker_threads: usize, - work_receiver: crossbeam::crossbeam_channel::Receiver, + work_receiver: crossbeam::channel::Receiver, io_queue_send: tokio::sync::mpsc::UnboundedSender, ) -> Vec> { let mut thread_handles = vec![]; @@ -1073,7 +1073,7 @@ impl EnclaveState { let (io_queue_send, io_queue_receive) = tokio::sync::mpsc::unbounded_channel(); - let (work_sender, work_receiver) = crossbeam::crossbeam_channel::unbounded(); + let (work_sender, work_receiver) = crossbeam::channel::unbounded(); work_sender .send(start_work) .expect("Work sender couldn't send data to receiver"); @@ -1147,7 +1147,7 @@ impl EnclaveState { rt.block_on(async move { enclave.abort_all_threads(); //clear the threads_queue - while enclave.threads_queue.pop().is_ok() {} + while enclave.threads_queue.pop().is_some() {} let cmd = enclave.kind.as_command().unwrap(); let mut cmddata = cmd.panic_reason.lock().await; @@ -1537,8 +1537,8 @@ impl<'tcs> IOHandlerInput<'tcs> { .as_command() .ok_or(IoErrorKind::InvalidInput)?; let new_tcs = match self.enclave.threads_queue.pop() { - Ok(tcs) => tcs, - Err(_) => { + Some(tcs) => tcs, + None => { return Err(IoErrorKind::WouldBlock.into()); } }; diff --git a/intel-sgx/fortanix-sgx-abi/src/lib.rs b/intel-sgx/fortanix-sgx-abi/src/lib.rs index aeda9f231..3511ae34b 100644 --- a/intel-sgx/fortanix-sgx-abi/src/lib.rs +++ b/intel-sgx/fortanix-sgx-abi/src/lib.rs @@ -15,7 +15,7 @@ //! The Fortanix SGX ABI (compiler target `x86_64-fortanix-unknown-sgx`) is an //! interface for Intel SGX enclaves. It is a small yet functional interface //! suitable for writing larger enclaves. In contrast to other enclave -//! interfaces, this interface is primarly designed for running entire +//! interfaces, this interface is primarily designed for running entire //! applications in an enclave. //! //! The Fortanix SGX ABI specification consists of two parts: @@ -225,7 +225,7 @@ pub enum Error { UserRangeEnd = 0x7fff_ffff, } -/// A value indicating that the operation was succesful. +/// A value indicating that the operation was successful. #[cfg_attr(feature = "rustc-dep-of-std", unstable(feature = "sgx_platform", issue = "56975"))] pub const RESULT_SUCCESS: Result = 0; @@ -304,7 +304,7 @@ impl Usercalls { /// Read up to `len` bytes from stream `fd`. /// /// `buf` must point to a buffer in userspace with a size of at least - /// `len`. On a succesful return, the number of bytes written is returned. + /// `len`. On a successful return, the number of bytes written is returned. /// The enclave must check that the returned length is no more than `len`. /// If `len` is `0`, this call should block until the stream is ready for /// reading. If `len` is `0` or end of stream is reached, `0` may be @@ -333,7 +333,7 @@ impl Usercalls { /// Write up to `len` bytes to stream `fd`. /// /// `buf` must point to a buffer in userspace with a size of at least - /// `len`. On a succesful return, the number of bytes written is returned. + /// `len`. On a successful return, the number of bytes written is returned. /// The enclave must check that the returned length is no more than `len`. /// If `len` is `0`, this call should block until the stream is ready for /// writing. If `len` is `0` or the stream is closed, `0` may be returned. @@ -489,7 +489,7 @@ impl Usercalls { /// this with the number of entries into [`thread_entry`]. If no free TCSes /// are immediately available, this may return an error. /// - /// This function will never be succesful in [libraries]. See the + /// This function will never be successful in [libraries]. See the /// [`library`] documentation on how to use threads with libraries. /// /// [`thread_entry`]: entry/executable/fn.thread_entry.html @@ -581,7 +581,7 @@ impl Usercalls { /// Request user memory. /// /// Request an allocation in user memory of size `size` and with alignment - /// `align`. If succesful, a pointer to this memory will be returned. The + /// `align`. If successful, a pointer to this memory will be returned. The /// enclave must check the pointer is correctly aligned and that the entire /// range of memory pointed to is outside the enclave. /// @@ -720,7 +720,7 @@ pub mod async { } } - /// Cancel a usercall peviously sent to userspace. + /// Cancel a usercall previously sent to userspace. #[repr(C)] #[derive(Copy, Clone, Default)] #[cfg_attr(feature = "rustc-dep-of-std", unstable(feature = "sgx_platform", issue = "56975"))] @@ -750,7 +750,7 @@ pub mod async { /// 1. Load the current offsets. /// 2. If the queue is full, wait, then go to step 1. /// 3. Add 1 to the write offset and do an atomic compare-and-swap (CAS) - /// with the current offsets. If the CAS was not succesful, go to step + /// with the current offsets. If the CAS was not successful, go to step /// 1\. /// 4. Write the data, then the `id`. /// 5. If the queue was empty in step 1, signal the reader to wake up. @@ -812,7 +812,7 @@ pub mod async { /// correct size and alignment. /// On return, userspace will have filled these structures with /// information about the queues. A single set of queues will be - /// allocated per enclave. Once this usercall has returned succesfully, + /// allocated per enclave. Once this usercall has returned successfully, /// calling this usercall again is equivalent to calling `exit(true)`. /// /// May fail if the platform does not support asynchronous usercalls. diff --git a/ipc-queue/src/fifo.rs b/ipc-queue/src/fifo.rs index d834673ab..321e30430 100644 --- a/ipc-queue/src/fifo.rs +++ b/ipc-queue/src/fifo.rs @@ -9,7 +9,7 @@ use std::marker::PhantomData; use std::mem; #[cfg(not(target_env = "sgx"))] use { - std::sync::atomic::{AtomicU32, AtomicU64}, + std::sync::atomic::AtomicU64, std::sync::Arc, }; use std::sync::atomic::{AtomicUsize, Ordering, Ordering::SeqCst};