fortanix / rust-sgx

The Fortanix Rust Enclave Development Platform
https://edp.fortanix.com
Mozilla Public License 2.0
444 stars 99 forks source link

Support specifying number of worker threads in runner #483

Open raoulstrackx opened 1 year ago

raoulstrackx commented 1 year ago

ftxsgx-runner-cargo supports specifying the number of threads that need to be available in the enclave. Unfortunately that is not sufficient; The enclave-runner library always spawns n worker threads where n are the number of logical cores available. On very constraint VMs, this may only be one. As a result, enclaves with an infinite loop may never return control back to the enclave and the enclave hangs, even when there are multiple threads running in the enclave.

Example (with package.metadata.fortanix-sgx.threads=5 in Cargo.toml):

fn main() {
    let _h = thread::spawn(move || {
        loop {};
    });

    thread::sleep(Duration::from_secs(1));
}
raoulstrackx commented 1 year ago

This is similar to #165 with the exception that the main thread may not even issue the exit usercall.