Skip to content
This repository has been archived by the owner on May 9, 2022. It is now read-only.

Commit

Permalink
docs(exec_enclave): add docs to sample function unsafe code
Browse files Browse the repository at this point in the history
Co-authored-by: Pi Delport <[email protected]>
  • Loading branch information
longtomjr and PiDelport committed Jun 17, 2021
1 parent 7b17e08 commit 30068b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rtc_exec_enclave/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ pub fn request_execution(token: Token, _params: ()) -> Result<Box<[u8]>, ()> {
let data = get_data(&token);

// as_ptr() does not take ownership, so the data will be dropped at the end of this function
// Safety:
// As long as `data` is valid, this should be safe.
// Memory will be cleaned up when `data` goes out of scope, which will be after the unsafe function call.
let result = unsafe { exec_module.call(data.as_ptr(), data.len()) };

match result {
Expand Down
4 changes: 4 additions & 0 deletions rtc_exec_enclave/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ pub(crate) type CallReturnValue = Box<[u8]>;
pub(crate) type ExecResult = core::result::Result<CallReturnValue, ()>;

pub(crate) trait ExecModule {
/// Calls the entry function of a module with the provided dataset and return the result
///
/// # Safety
/// The caller must ensure that `dataset_ptr` is a valid pointer to a `u8` slice of `dataset_len`
unsafe fn call(&self, dataset_ptr: *const u8, dataset_len: usize) -> ExecResult;
}

0 comments on commit 30068b8

Please sign in to comment.