Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
- Optimize offsets calculations
- Replace WithAtomicId with Identified/WithId
- Better lifetime management
- Other minor nits
  • Loading branch information
mzohreva committed Sep 18, 2020
1 parent 3ac7ac2 commit e1e8150
Show file tree
Hide file tree
Showing 10 changed files with 564 additions and 510 deletions.
8 changes: 7 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 26 additions & 49 deletions enclave-runner/src/usercalls/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ impl<'future, 'ioinput: 'future, 'tcs: 'ioinput> Usercalls<'future> for Handler<
};
return (self, Ok(ret.to_sgx_result()));
}
}
.boxed_local()
}.boxed_local()
}

fn read_alloc(
Expand All @@ -63,8 +62,7 @@ impl<'future, 'ioinput: 'future, 'tcs: 'ioinput> Usercalls<'future> for Handler<
}
return (self, Ok(ret.to_sgx_result()));
}
}
.boxed_local()
}.boxed_local()
}

fn write(
Expand All @@ -82,8 +80,7 @@ impl<'future, 'ioinput: 'future, 'tcs: 'ioinput> Usercalls<'future> for Handler<
};
return (self, Ok(ret.to_sgx_result()));
}
}
.boxed_local()
}.boxed_local()
}

fn flush(
Expand All @@ -93,8 +90,7 @@ impl<'future, 'ioinput: 'future, 'tcs: 'ioinput> Usercalls<'future> for Handler<
async move {
let ret = Ok(self.0.flush(fd).await.to_sgx_result());
return (self, ret);
}
.boxed_local()
}.boxed_local()
}

fn close(
Expand All @@ -104,8 +100,7 @@ impl<'future, 'ioinput: 'future, 'tcs: 'ioinput> Usercalls<'future> for Handler<
async move {
let ret = Ok(self.0.close(fd).await);
return (self, ret);
}
.boxed_local()
}.boxed_local()
}

fn bind_stream(
Expand All @@ -124,8 +119,7 @@ impl<'future, 'ioinput: 'future, 'tcs: 'ioinput> Usercalls<'future> for Handler<
};
return (self, Ok(ret.to_sgx_result()));
}
}
.boxed_local()
}.boxed_local()
}

fn accept_stream(
Expand All @@ -146,8 +140,7 @@ impl<'future, 'ioinput: 'future, 'tcs: 'ioinput> Usercalls<'future> for Handler<
.to_sgx_result());
return (self, ret);
}
}
.boxed_local()
}.boxed_local()
}

fn connect_stream(
Expand All @@ -173,8 +166,7 @@ impl<'future, 'ioinput: 'future, 'tcs: 'ioinput> Usercalls<'future> for Handler<
};
return (self, Ok(ret.to_sgx_result()));
}
}
.boxed_local()
}.boxed_local()
}

fn launch_thread(
Expand All @@ -183,8 +175,7 @@ impl<'future, 'ioinput: 'future, 'tcs: 'ioinput> Usercalls<'future> for Handler<
async move {
let ret = Ok(self.0.launch_thread().to_sgx_result());
return (self, ret);
}
.boxed_local()
}.boxed_local()
}

fn exit(
Expand All @@ -194,8 +185,7 @@ impl<'future, 'ioinput: 'future, 'tcs: 'ioinput> Usercalls<'future> for Handler<
async move {
let ret = self.0.exit(panic);
return (self, ret);
}
.boxed_local()
}.boxed_local()
}

fn wait(
Expand All @@ -211,8 +201,7 @@ impl<'future, 'ioinput: 'future, 'tcs: 'ioinput> Usercalls<'future> for Handler<

let ret = Ok(self.0.wait(event_mask, timeout).await.to_sgx_result());
return (self, ret);
}
.boxed_local()
}.boxed_local()
}

fn send(
Expand All @@ -223,8 +212,7 @@ impl<'future, 'ioinput: 'future, 'tcs: 'ioinput> Usercalls<'future> for Handler<
async move {
let ret = Ok(self.0.send(event_set, tcs).to_sgx_result());
return (self, ret);
}
.boxed_local()
}.boxed_local()
}

fn insecure_time(
Expand All @@ -233,8 +221,7 @@ impl<'future, 'ioinput: 'future, 'tcs: 'ioinput> Usercalls<'future> for Handler<
async move {
let ret = Ok(self.0.insecure_time());
return (self, ret);
}
.boxed_local()
}.boxed_local()
}

fn alloc(
Expand All @@ -246,8 +233,7 @@ impl<'future, 'ioinput: 'future, 'tcs: 'ioinput> Usercalls<'future> for Handler<
async move {
let ret = Ok(self.0.alloc(size, alignment).to_sgx_result());
return (self, ret);
}
.boxed_local()
}.boxed_local()
}

fn free(
Expand All @@ -259,8 +245,7 @@ impl<'future, 'ioinput: 'future, 'tcs: 'ioinput> Usercalls<'future> for Handler<
async move {
let ret = Ok(self.0.free(ptr, size, alignment).unwrap());
return (self, ret);
}
.boxed_local()
}.boxed_local()
}

fn async_queues(
Expand All @@ -269,26 +254,18 @@ impl<'future, 'ioinput: 'future, 'tcs: 'ioinput> Usercalls<'future> for Handler<
return_queue: *mut FifoDescriptor<Return>,
) -> std::pin::Pin<Box<dyn Future<Output = (Self, UsercallResult<Result>)> + 'future>> {
async move {
let queues = (|| -> IoResult<_> {
unsafe {
let uq = usercall_queue.as_mut().ok_or(IoError::from(IoErrorKind::InvalidInput))?;
let rq = return_queue.as_mut().ok_or(IoError::from(IoErrorKind::InvalidInput))?;
Ok((uq, rq))
}
})();
let (uq, rq) = match queues {
Err(e) => {
let ret: IoResult<()> = Err(e);
return (self, Ok(ret.to_sgx_result()));
}
Ok((uq, rq)) => (uq, rq),
};
match self.0.async_queues(uq, rq).await {
Ok(()) => (self, Ok(Ok(()).to_sgx_result())),
Err(e) => (self, Err(e)),
unsafe {
let ret = match (usercall_queue.as_mut(), return_queue.as_mut()) {
(Some(usercall_queue), Some(return_queue)) => {
self.0.async_queues(usercall_queue, return_queue).await.map(Ok)
},
_ => {
Ok(Err(IoErrorKind::InvalidInput.into()))
},
};
return (self, ret.map(|v| v.to_sgx_result()));
}
}
.boxed_local()
}.boxed_local()
}
}

Expand Down
Loading

0 comments on commit e1e8150

Please sign in to comment.