Skip to content

Commit

Permalink
Remove almost all hacks
Browse files Browse the repository at this point in the history
  • Loading branch information
mzohreva committed Aug 29, 2022
1 parent dd152bc commit 39895b5
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 269 deletions.
3 changes: 1 addition & 2 deletions intel-sgx/async-usercalls/src/batch_drop.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::hacks::Usercall;
use crate::provider_core::ProviderCore;
use ipc_queue::Identified;
use std::cell::RefCell;
use std::mem;
use std::os::fortanix_sgx::usercalls::alloc::{User, UserSafe};
use std::os::fortanix_sgx::usercalls::raw::UsercallNrs;
use std::os::fortanix_sgx::usercalls::raw::{Usercall, UsercallNrs};

pub trait BatchDroppable: private::BatchDroppable {}
impl<T: private::BatchDroppable> BatchDroppable for T {}
Expand Down
4 changes: 2 additions & 2 deletions intel-sgx/async-usercalls/src/callback.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::duplicated::{FromSgxResult, ReturnValue};
use crate::hacks::Return;
use fortanix_sgx_abi::{invoke_with_usercalls, Fd, Result};
use std::io;
use std::os::fortanix_sgx::usercalls::raw::{Return, ReturnValue};
use std::os::fortanix_sgx::usercalls::FromSgxResult;

pub struct CbFn<T>(Box<dyn FnOnce(T) + Send + 'static>);

Expand Down
168 changes: 0 additions & 168 deletions intel-sgx/async-usercalls/src/duplicated.rs

This file was deleted.

52 changes: 0 additions & 52 deletions intel-sgx/async-usercalls/src/hacks/async_queues.rs

This file was deleted.

7 changes: 3 additions & 4 deletions intel-sgx/async-usercalls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,27 @@
use crossbeam_channel as mpmc;
use ipc_queue::Identified;
use std::collections::HashMap;
use std::os::fortanix_sgx::usercalls::raw::{Cancel, Return, Usercall};
use std::sync::Mutex;
use std::time::Duration;

mod batch_drop;
mod callback;
mod duplicated;
mod hacks;
mod io_bufs;
mod provider_api;
mod provider_core;
mod queues;
mod raw;
#[cfg(test)]
mod test_support;
mod utils;

pub use self::batch_drop::batch_drop;
pub use self::callback::CbFn;
pub use self::io_bufs::{ReadBuffer, UserBuf, WriteBuffer};
pub use self::raw::RawApi;

use self::callback::*;
use self::hacks::{Cancel, Return, Usercall};
use self::provider_core::ProviderCore;
use self::queues::*;

Expand Down Expand Up @@ -235,8 +234,8 @@ impl CallbackHandler {
#[cfg(test)]
mod tests {
use super::*;
use crate::hacks::MakeSend;
use crate::test_support::*;
use crate::utils::MakeSend;
use crossbeam_channel as mpmc;
use std::io;
use std::net::{TcpListener, TcpStream};
Expand Down
2 changes: 1 addition & 1 deletion intel-sgx/async-usercalls/src/provider_api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::batch_drop;
use crate::hacks::MakeSend;
use crate::io_bufs::UserBuf;
use crate::raw::RawApi;
use crate::utils::MakeSend;
use crate::{AsyncUsercallProvider, CancelHandle};
use fortanix_sgx_abi::Fd;
use std::io;
Expand Down
2 changes: 1 addition & 1 deletion intel-sgx/async-usercalls/src/provider_core.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::hacks::{Cancel, Return, Usercall};
use crate::queues::*;
use crate::CancelHandle;
use crossbeam_channel as mpmc;
use ipc_queue::Identified;
use std::os::fortanix_sgx::usercalls::raw::{Cancel, Return, Usercall};
use std::sync::atomic::{AtomicU32, Ordering};

pub(crate) struct ProviderCore {
Expand Down
28 changes: 15 additions & 13 deletions intel-sgx/async-usercalls/src/queues.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::hacks::{alloc_descriptor, async_queues, to_enclave, Cancel, Return, Usercall};
use crate::provider_core::ProviderId;
use crossbeam_channel as mpmc;
use fortanix_sgx_abi::{EV_CANCELQ_NOT_FULL, EV_RETURNQ_NOT_EMPTY, EV_USERCALLQ_NOT_FULL};
use ipc_queue::{self, Identified, QueueEvent, RecvError, SynchronizationError, Synchronizer};
use lazy_static::lazy_static;
use std::os::fortanix_sgx::usercalls::raw;
use std::os::fortanix_sgx::usercalls::alloc::User;
use std::os::fortanix_sgx::usercalls::raw::{
self, async_queues, Cancel, FifoDescriptor, Return, Usercall,
};
use std::sync::{Arc, Mutex};
use std::{io, iter, thread};

Expand Down Expand Up @@ -54,24 +56,24 @@ lazy_static! {
}

fn init_async_queues() -> io::Result<(Sender<Usercall>, Sender<Cancel>, Receiver<Return>)> {
// FIXME: this is just a hack. Replace these with `User::<FifoDescriptor<T>>::uninitialized().into_raw()`
let usercall_q = unsafe { alloc_descriptor::<Usercall>() };
let cancel_q = unsafe { alloc_descriptor::<Cancel>() };
let return_q = unsafe { alloc_descriptor::<Return>() };
let usercall_q = User::<FifoDescriptor<Usercall>>::uninitialized().into_raw();
let cancel_q = User::<FifoDescriptor<Cancel>>::uninitialized().into_raw();
let return_q = User::<FifoDescriptor<Return>>::uninitialized().into_raw();

let r = unsafe { async_queues(usercall_q, return_q, cancel_q) };
if r != 0 {
return Err(io::Error::from_raw_os_error(r));
}

// FIXME: this is another hack, replace with `unsafe { User::<FifoDescriptor<T>>::from_raw(q) }.to_enclave()`
let usercall_queue = unsafe { to_enclave(usercall_q) };
let cancel_queue = unsafe { to_enclave(cancel_q) };
let return_queue = unsafe { to_enclave(return_q) };
let usercall_queue = unsafe { User::<FifoDescriptor<Usercall>>::from_raw(usercall_q) }.to_enclave();
let cancel_queue = unsafe { User::<FifoDescriptor<Cancel>>::from_raw(cancel_q) }.to_enclave();
let return_queue = unsafe { User::<FifoDescriptor<Return>>::from_raw(return_q) }.to_enclave();

let utx = unsafe { Sender::from_descriptor(usercall_queue, QueueSynchronizer { queue: Queue::Usercall }) };
let ctx = unsafe { Sender::from_descriptor(cancel_queue, QueueSynchronizer { queue: Queue::Cancel }) };
let rx = unsafe { Receiver::from_descriptor(return_queue, QueueSynchronizer { queue: Queue::Return }) };
// FIXME: once `WithId` is exported from `std::os::fortanix_sgx::usercalls::raw`, we can remove
// `transmute` calls here and use FifoDescriptor/WithId from std everywhere including in ipc-queue.
let utx = unsafe { Sender::from_descriptor(std::mem::transmute(usercall_queue), QueueSynchronizer { queue: Queue::Usercall }) };
let ctx = unsafe { Sender::from_descriptor(std::mem::transmute(cancel_queue), QueueSynchronizer { queue: Queue::Cancel }) };
let rx = unsafe { Receiver::from_descriptor(std::mem::transmute(return_queue), QueueSynchronizer { queue: Queue::Return }) };
Ok((utx, ctx, rx))
}

Expand Down
3 changes: 1 addition & 2 deletions intel-sgx/async-usercalls/src/raw.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::callback::*;
use crate::hacks::Usercall;
use crate::{AsyncUsercallProvider, CancelHandle};
use fortanix_sgx_abi::Fd;
use std::io;
use std::os::fortanix_sgx::usercalls::raw::ByteBuffer;
use std::os::fortanix_sgx::usercalls::raw::UsercallNrs;
use std::os::fortanix_sgx::usercalls::raw::{Usercall, UsercallNrs};

pub trait RawApi {
unsafe fn raw_read(
Expand Down
Loading

0 comments on commit 39895b5

Please sign in to comment.