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

Commit 30068b8

Browse files
longtomjrPiDelport
andcommitted
docs(exec_enclave): add docs to sample function unsafe code
Co-authored-by: Pi Delport <[email protected]>
1 parent 7b17e08 commit 30068b8

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

rtc_exec_enclave/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ pub fn request_execution(token: Token, _params: ()) -> Result<Box<[u8]>, ()> {
3131
let data = get_data(&token);
3232

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

3639
match result {

rtc_exec_enclave/src/types.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@ pub(crate) type CallReturnValue = Box<[u8]>;
55
pub(crate) type ExecResult = core::result::Result<CallReturnValue, ()>;
66

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

0 commit comments

Comments
 (0)