Skip to content

Commit

Permalink
Fix remaining safety comments, turn on warning
Browse files Browse the repository at this point in the history
  • Loading branch information
cbiffle committed Apr 26, 2024
1 parent 52d2074 commit 997eb9e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions os/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ pub unsafe fn run_tasks_with_preemption_and_idle(
// be wrong.
let futures_ptr: *mut [Pin<*mut dyn Future<Output = Infallible>>] = futures_ptr as _;
// Stash the task future array in a known location.
//
// Safety: this is written by code but never read back, so the fact that
// it's a static mut has no effect on code other than the warning.
unsafe {
TASK_FUTURES = Some(futures_ptr);
}
Expand Down
1 change: 1 addition & 0 deletions os/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
unsafe_op_in_unsafe_fn,
unused_qualifications,
)]
#![warn(clippy::undocumented_unsafe_blocks)]

/// Internal assert macro that doesn't stringify its expression or generate any
/// fancy messages. This means failures must be diagnosed by file:line only, so,
Expand Down
10 changes: 10 additions & 0 deletions os/src/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,18 @@ impl<T> Mutex<T> {
}
}

/// Grabs a reference to the contents of the mutex.
///
/// Used internally by Deref.
///
/// # Safety
///
/// For this to be sound, you must ensure that there are no aliasing `&mut`
/// references to the contents.
unsafe fn contents(&self) -> &T {
let ptr = self.value.get();
// Safety: as long as our contract is upheld, this won't produce a
// reference aliasing a `&mut` so we should be fine.
unsafe { &*ptr }
}
}
Expand Down
4 changes: 2 additions & 2 deletions os/src/spsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ pub struct Queue<'s, T> {
pushed: Notify,
}

/// This type is easily sharable across threads, because there are no useful
/// operations that can be performed using only a shared reference.
/// Safety: This type is easily sharable across threads, because there are no
/// useful operations that can be performed using only a shared reference.
unsafe impl<T> Sync for Queue<'_, T> where T: Send {}

impl<'s, T> Queue<'s, T> {
Expand Down

0 comments on commit 997eb9e

Please sign in to comment.