Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oak_tests: add safety sections to doc comments #446

Merged
merged 2 commits into from
Jan 9, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions sdk/rust/oak_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ extern "C" {

/// Test implementation of channel wait functionality, which always indicates
/// that all provided channels are ready for reading.
///
/// # Safety
///
/// The linear memory range [buf, buf+count*SPACE_BYTES_PER_HANDLE) should be
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/should/must/?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

/// valid.
#[no_mangle]
pub unsafe extern "C" fn wait_on_channels(buf: *mut u8, count: u32) -> u32 {
let name = node_name();
Expand Down Expand Up @@ -139,6 +144,11 @@ pub unsafe extern "C" fn wait_on_channels(buf: *mut u8, count: u32) -> u32 {
}

/// Test-only implementation of channel write functionality.
///
/// # Safety
///
/// The linear memory ranges [buf, buf+size) and [handle_buf, handle_buf+handle_count*8) should be
/// valid.
#[no_mangle]
pub unsafe extern "C" fn channel_write(
handle: u64,
Expand Down Expand Up @@ -187,6 +197,11 @@ pub unsafe extern "C" fn channel_write(

/// Test implementation of channel read functionality, which reads a message
/// from the test channel.
///
/// # Safety
///
/// The linear memory ranges [buf, buf+size) and [handle_buf, handle_buf+handle_count*8) should be
/// valid, as should the raw pointers actual_size and actual_handle_count.
#[no_mangle]
pub unsafe extern "C" fn channel_read(
handle: u64,
Expand Down Expand Up @@ -240,6 +255,10 @@ pub unsafe extern "C" fn channel_read(
}

/// Test version of channel creation.
///
/// # Safety
///
/// The raw pointers to linear memory should be valid.
#[no_mangle]
pub unsafe extern "C" fn channel_create(write: *mut u64, read: *mut u64) -> u32 {
let name = node_name();
Expand Down Expand Up @@ -272,6 +291,10 @@ pub extern "C" fn channel_close(handle: u64) -> u32 {
}

/// Test implementation of dynamic Node creation.
///
/// # Safety
///
/// The linear memory range [buf, buf+len) should be valid.
#[no_mangle]
pub unsafe fn node_create(buf: *const u8, len: usize, handle: u64) -> u32 {
let name = node_name();
Expand Down Expand Up @@ -312,6 +335,10 @@ pub unsafe fn node_create(buf: *const u8, len: usize, handle: u64) -> u32 {
}

/// Test version of random data generation.
///
/// # Safety
///
/// The linear memory range [buf, buf+size) should be valid.
#[no_mangle]
pub unsafe extern "C" fn random_get(buf: *mut u8, size: usize) -> u32 {
let name = node_name();
Expand Down