#sgx #async #usercall

nightly async-usercalls

SGX enclaves中的异步usercalls接口。这是一个SGX专属的crate,你应该使用x86_64-fortanix-unknown-sgx目标来编译它

1个不稳定版本

0.5.0 2024年4月16日

#855 in 异步

MPL-2.0 许可证

165KB
3K SLoC

此crate提供在SGX enclaves中执行异步usercalls的接口。异步usercalls背后的动机和ABI文档可以在这里找到。这里提供的API相当底层,并不适用于通用用途。这些API可以用来实现mio抽象,进而允许我们在SGX enclaves中使用tokio

主要接口通过AsyncUsercallProvider提供,它与CallbackHandler协同工作

use async_usercalls::AsyncUsercallProvider;
use std::{io::Result, net::TcpStream, sync::mpsc, time::Duration};

let (provider, callback_handler) = AsyncUsercallProvider::new();
let (tx, rx) = mpsc::sync_channel(1);
// The closure is called when userspace sends back the result of the
// usercall.
let cancel_handle = provider.connect_stream("www.example.com:80", move |res| {
    tx.send(res).unwrap();
});
// We can cancel the connect usercall using `cancel_handle.cancel()`, but
// note that we may still get a successful result.
// We need to poll `callback_handler` to make progress.
loop {
    let n = callback_handler.poll(Some(Duration::from_millis(100)));
    if n > 0 {
        break; // at least 1 callback function was executed!
    }
}
let connect_result: Result<TcpStream> = rx.recv().unwrap();

依赖项

~375KB