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

SGX port tokio 1.34.0 #2

Closed
wants to merge 5 commits into from
Closed
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
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
resolver = "2"
members = [
"enclave-runner",
"tokio",
"tokio-macros",
"tokio-test",
Expand All @@ -14,3 +15,10 @@ members = [
"tests-build",
"tests-integration",
]

[patch.crates-io]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update patches before trying to upstream. Needs this and this PR

mio = { git = "https://github.com/fortanix/mio", branch = "raoul/sgx-port-0.8.9" }
enclave-runner = { git = "https://github.com/fortanix/rust-sgx", branch = "master" }
sgxs = { git = "https://github.com/fortanix/rust-sgx", branch = "master" }
sgx-isa = { git = "https://github.com/fortanix/rust-sgx", branch = "master" }
sgxs-loaders = { git = "https://github.com/fortanix/rust-sgx", branch = "master" }
7 changes: 6 additions & 1 deletion benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ edition = "2021"
test-util = ["tokio/test-util"]

[dependencies]
tokio = { version = "1.5.0", path = "../tokio", features = ["full"] }
criterion = "0.5.1"
rand = "0.8"
rand_chacha = "0.3"

[target.'cfg(target_env = "sgx")'.dependencies]
tokio = { version = "1.5.0", path = "../tokio", features = ["full-sgx"] }

[target.'cfg(not(target_env = "sgx"))'.dependencies]
tokio = { version = "1.5.0", path = "../tokio", features = ["full"] }

[dev-dependencies]
tokio-util = { version = "0.7.0", path = "../tokio-util", features = ["full"] }
tokio-stream = { path = "../tokio-stream" }
Expand Down
23 changes: 23 additions & 0 deletions ct.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash -ex
repo_root=$(readlink -f $(dirname ${BASH_SOURCE[0]}))
cd ${repo_root}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Part of the "local CI" commit. May be removed before upstreaming


source ${repo_root}/ct_env.sh

cargo test

pushd tokio
cargo test --target x86_64-fortanix-unknown-sgx --features "full-sgx"
popd

pushd tokio-macros
cargo test --target x86_64-fortanix-unknown-sgx
popd

pushd tokio-stream
cargo test --target x86_64-fortanix-unknown-sgx
popd

pushd stress-test
cargo test --target x86_64-fortanix-unknown-sgx
popd
10 changes: 10 additions & 0 deletions ct_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash -ex
repo_root=$(readlink -f $(dirname ${BASH_SOURCE[0]}))
cd ${repo_root}

# Unfortunately, the `ftxsgx-runner-cargo` application doesn't enable us to point to a runner within the same workspace. We use a hack here by pointing to `enclave-runner` and making sure such an executable exists when running CI
pushd enclave-runner
cargo build
popd

export PATH=${repo_root}/target/debug/:${PATH}
10 changes: 10 additions & 0 deletions enclave-runner/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "enclave-runner"
version = "0.1.0"
edition = "2018"

[dependencies]
aesm-client = { version = "0.2", features = ["sgxs"] }
clap = "2.0"
enclave-runner = "0.5"
sgxs-loaders = "0.3.0"
51 changes: 51 additions & 0 deletions enclave-runner/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use aesm_client::AesmClient;
use clap::{App, Arg};
use enclave_runner::EnclaveBuilder;

#[cfg(windows)]
use sgxs_loaders::enclaveapi::Sgx as IsgxDevice;
#[cfg(unix)]
use sgxs_loaders::isgx::Device as IsgxDevice;

fn main() {
let args = App::new("runner")
.arg(Arg::with_name("file").required(true))
.arg(
Arg::with_name("enclave-args")
.long_help(
"Arguments passed to the enclave. \
Note that this is not an appropriate channel for passing \
secrets or security configurations to the enclave.",
)
.multiple(true),
)
.get_matches();

let file = args.value_of("file").unwrap();

let mut device = IsgxDevice::new()
.expect("failed to open SGX device")
.einittoken_provider(AesmClient::new())
.build();

let mut enclave_builder = EnclaveBuilder::new(file.as_ref());
if let Err(_) = enclave_builder.coresident_signature() {
enclave_builder.dummy_signature();
}

if let Some(enclave_args) = args.values_of("enclave-args") {
enclave_builder.args(enclave_args);
}

let enclave = enclave_builder
.build(&mut device)
.expect("failed to load SGX enclave");

match enclave.run() {
Err(e) => {
eprintln!("Error while executing SGX enclave.\n{}", e);
std::process::exit(-1)
}
Ok(()) => {}
}
}
6 changes: 6 additions & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ rand = "0.8.3"
[target.'cfg(windows)'.dev-dependencies.windows-sys]
version = "0.48"

[target.'cfg(not(target_env = "sgx"))'.dev-dependencies]
tokio = { version = "1.0.0", path = "../tokio",features = ["full", "tracing"] }

[target.'cfg(target_env = "sgx")'.dev-dependencies]
tokio = { version = "1.0.0", path = "../tokio",features = ["full-sgx", "tracing"] }

[[example]]
name = "chat"
path = "chat.rs"
Expand Down
5 changes: 5 additions & 0 deletions stress-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

[target.'cfg(not(target_env = "sgx"))'.dependencies]
tokio = { path = "../tokio/", features = ["full"] }

[target.'cfg(target_env = "sgx")'.dependencies]
tokio = { path = "../tokio/", features = ["full-sgx"] }

[dev-dependencies]
rand = "0.8"
6 changes: 2 additions & 4 deletions stress-test/examples/simple_echo_tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{thread::sleep, time::Duration};

use tokio::{
io::{AsyncReadExt, AsyncWriteExt},
net::{TcpListener, TcpSocket},
net::{TcpListener, TcpStream},
runtime::Builder,
sync::oneshot,
};
Expand All @@ -30,9 +30,7 @@ fn main() {
let (tx, mut rx) = oneshot::channel();

rt2.spawn(async {
let addr = TCP_ENDPOINT.parse().unwrap();
let socket = TcpSocket::new_v4().unwrap();
let mut stream = socket.connect(addr).await.unwrap();
let mut stream = TcpStream::connect(TCP_ENDPOINT).await.unwrap();

let mut buff = [0; MSG_SIZE];
for _ in 0..NUM_MSGS {
Expand Down
5 changes: 5 additions & 0 deletions tokio-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ quote = "1"
syn = { version = "2.0", features = ["full"] }

[dev-dependencies]

[target.'cfg(not(target_env = "sgx"))'.dev-dependencies]
tokio = { version = "1.0.0", path = "../tokio", features = ["full"] }

[target.'cfg(target_env = "sgx")'.dev-dependencies]
tokio = { version = "1.0.0", path = "../tokio", features = ["full-sgx"] }

[package.metadata.docs.rs]
all-features = true
4 changes: 4 additions & 0 deletions tokio-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ use proc_macro::TokenStream;
/// ### Configure the runtime to start with time paused
///
/// ```rust
/// # #[cfg(not(feature = "test-util"))]
/// # fn main(){}
/// # #[cfg(feature = "test-util")]
/// #[tokio::main(flavor = "current_thread", start_paused = true)]
/// async fn main() {
/// println!("Hello world");
Expand All @@ -162,6 +165,7 @@ use proc_macro::TokenStream;
///
/// ```rust
/// fn main() {
/// # #[cfg(feature = "test-util")]
/// tokio::runtime::Builder::new_current_thread()
/// .enable_all()
/// .start_paused(true)
Expand Down
10 changes: 9 additions & 1 deletion tokio-stream/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,17 @@ tokio = { version = "1.15.0", path = "../tokio", features = ["sync"] }
tokio-util = { version = "0.7.0", path = "../tokio-util", optional = true }

[dev-dependencies]
tokio = { version = "1.2.0", path = "../tokio", features = ["full", "test-util"] }
async-stream = "0.3"
parking_lot = "0.12.0"
tokio-test = { path = "../tokio-test" }
futures = { version = "0.3", default-features = false }

[target.'cfg(not(target_env = "sgx"))'.dev-dependencies]
tokio = { version = "1.2.0", path = "../tokio", features = ["full", "test-util"] }

[target.'cfg(target_env = "sgx")'.dev-dependencies]
tokio = { version = "1.2.0", path = "../tokio", features = ["full-sgx", "test-util"] }

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
Expand All @@ -56,3 +61,6 @@ rustdoc-args = ["--cfg", "docsrs"]
# This should allow `docsrs` to be read across projects, so that `tokio-stream`
# can pick up stubbed types exported by `tokio`.
rustc-args = ["--cfg", "docsrs"]

[package.metadata.fortanix-sgx]
runner = "enclave-runner"
7 changes: 6 additions & 1 deletion tokio-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ bytes = "1.0.0"
futures-core = "0.3.0"

[dev-dependencies]
tokio = { version = "1.2.0", path = "../tokio", features = ["full"] }
futures-util = "0.3.0"

[target.'cfg(not(target_env = "sgx"))'.dev-dependencies]
tokio = { version = "1.2.0", path = "../tokio", features = ["full"] }

[target.'cfg(target_env = "sgx")'.dev-dependencies]
tokio = { version = "1.2.0", path = "../tokio", features = ["full-sgx"] }

[package.metadata.docs.rs]
all-features = true
7 changes: 6 additions & 1 deletion tokio-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ tracing = { version = "0.1.25", default-features = false, features = ["std"], op
hashbrown = { version = "0.14.0", optional = true }

[dev-dependencies]
tokio = { version = "1.0.0", path = "../tokio", features = ["full"] }
tokio-test = { version = "0.4.0", path = "../tokio-test" }
tokio-stream = { version = "0.1", path = "../tokio-stream" }

Expand All @@ -58,6 +57,12 @@ futures-test = "0.3.5"
parking_lot = "0.12.0"
tempfile = "3.1.0"

[target.'cfg(not(target_env = "sgx"))'.dev-dependencies]
tokio = { version = "1.0.0", path = "../tokio", features = ["full"] }

[target.'cfg(target_env = "sgx")'.dev-dependencies]
tokio = { version = "1.0.0", path = "../tokio", features = ["full-sgx"] }

[package.metadata.docs.rs]
all-features = true
# enable unstable features in the documentation
Expand Down
2 changes: 1 addition & 1 deletion tokio-util/tests/compat.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![cfg(all(feature = "compat"))]
#![cfg(not(target_os = "wasi"))] // WASI does not support all fs operations
#![cfg(not(any(target_os = "wasi", target_env = "sgx")))] // WASI and SGX do not support all fs operations
#![warn(rust_2018_idioms)]

use futures_io::SeekFrom;
Expand Down
2 changes: 1 addition & 1 deletion tokio-util/tests/time_delay_queue.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(clippy::disallowed_names)]
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
#![cfg(any(feature = "full", feature = "full-sgx"))]

use futures::StreamExt;
use tokio::time::{self, sleep, sleep_until, Duration, Instant};
Expand Down
23 changes: 21 additions & 2 deletions tokio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ full = [
"time",
]

# everything possible in SGX
full-sgx = [
"io-util",
"io-std",
"macros",
"net",
"rt",
"rt-multi-thread",
"sync",
"time",
]

fs = []
io-util = ["bytes"]
# stdin, stdout, stderr
Expand Down Expand Up @@ -99,7 +111,7 @@ mio = { version = "0.8.9", optional = true, default-features = false }
num_cpus = { version = "1.8.0", optional = true }
parking_lot = { version = "0.12.0", optional = true }

[target.'cfg(not(target_family = "wasm"))'.dependencies]
[target.'cfg(not(any(target_family = "wasm", target_env = "sgx")))'.dependencies]
socket2 = { version = "0.5.5", optional = true, features = [ "all" ] }

# Currently unstable. The API exposed by these features may be broken at any time.
Expand Down Expand Up @@ -138,7 +150,7 @@ futures = { version = "0.3.0", features = ["async-await"] }
mockall = "0.11.1"
async-stream = "0.3"

[target.'cfg(not(target_family = "wasm"))'.dev-dependencies]
[target.'cfg(not(any(target_family = "wasm", target_env = "sgx")))'.dev-dependencies]
socket2 = "0.5.5"
tempfile = "3.1.0"

Expand All @@ -164,3 +176,10 @@ rustc-args = ["--cfg", "tokio_unstable", "--cfg", "tokio_taskdump"]

[package.metadata.playground]
features = ["full", "test-util"]

# set number of threads so tests can run properly
[package.metadata.fortanix-sgx]
threads = 100
heap-size = 0x4000000
stack-size = 0x40000
runner = "enclave-runner"
1 change: 1 addition & 0 deletions tokio/src/io/poll_evented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ impl<E: Source> PollEvented<E> {

/// Deregisters the inner io from the registration and returns a Result containing the inner io.
#[cfg(any(feature = "net", feature = "process"))]
#[cfg(not(target_env = "sgx"))]
pub(crate) fn into_inner(mut self) -> io::Result<E> {
let mut inner = self.io.take().unwrap(); // As io shouldn't ever be None, just unwrap here.
self.registration.deregister(&mut inner)?;
Expand Down
1 change: 1 addition & 0 deletions tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
no_crate_inject,
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
))]
#![cfg_attr(target_env = "sgx", feature(sgx_platform))]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, allow(unused_attributes))]
#![cfg_attr(loom, allow(dead_code, unreachable_pub))]
Expand Down
Loading
Loading