From 37881fc8384040234dd88f29f95f99cbfcfc94de 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 +-- ipc-queue/src/fifo.rs | 2 +- 21 files changed, 131 insertions(+), 176 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 b83d89dd..0fdc796e 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 d05710c9..e12c9e0e 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", ] @@ -1572,7 +1617,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", @@ -1591,7 +1636,7 @@ dependencies = [ "openssl", "openssl-sys", "parking_lot 0.11.2", - "tokio 1.14.0", + "tokio 1.16.1", "tokio-openssl", "tower-layer", ] @@ -1619,7 +1664,7 @@ dependencies = [ "hex 0.4.3", "hyper 0.14.15", "pin-project 1.0.8", - "tokio 1.14.0", + "tokio 1.16.1", ] [[package]] @@ -1674,7 +1719,7 @@ dependencies = [ "futures-core", "inotify-sys", "libc", - "tokio 1.14.0", + "tokio 1.16.1", ] [[package]] @@ -2761,7 +2806,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", ] @@ -3493,7 +3538,7 @@ dependencies = [ "serde", "serde_json", "tar", - "tokio 1.14.0", + "tokio 1.16.1", "url 2.1.1", ] @@ -3773,11 +3818,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", @@ -3812,7 +3856,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", ] @@ -3847,7 +3891,7 @@ dependencies = [ "futures-util", "openssl", "openssl-sys", - "tokio 1.14.0", + "tokio 1.16.1", ] [[package]] @@ -3856,7 +3900,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", @@ -3899,9 +3943,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", @@ -3916,7 +3960,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 1e3d67c5..00000000 --- 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 b25386ff..dcdcebb9 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 c0cd25a0..1efbc98f 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 9011c63e..5fe7a2df 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 a8ede0de..c86df75f 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 234dbddb..ca307b17 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 377b0317..0002469e 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 3ffcb787..2ed43e01 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/ipc-queue/src/fifo.rs b/ipc-queue/src/fifo.rs index d834673a..321e3043 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};