Skip to content

Commit

Permalink
std: use queue-based RwLock on SGX
Browse files Browse the repository at this point in the history
  • Loading branch information
joboet committed Apr 11, 2024
1 parent 72fe8a0 commit a30a79c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 261 deletions.
46 changes: 46 additions & 0 deletions library/std/src/sys/pal/sgx/libunwind_integration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//! The functions in this module are needed by libunwind. These symbols are named
//! in pre-link args for the target specification, so keep that in sync.
#![cfg(not(test))]

use crate::sys::sync::RwLock;

// Verify that the byte pattern libunwind uses to initialize an RwLock is
// equivalent to the value of RwLock::new(). If the value changes,
// `src/UnwindRustSgx.h` in libunwind needs to be changed too.
const _: () = unsafe {
let bits_rust: usize = crate::mem::transmute(RwLock::new());
assert!(bits_rust == 0);
};

const EINVAL: i32 = 22;

#[no_mangle]
pub unsafe extern "C" fn __rust_rwlock_rdlock(p: *mut RwLock) -> i32 {
if p.is_null() {
return EINVAL;
}

// We cannot differentiate between reads an writes in unlock and therefore
// always use a write-lock. Unwinding isn't really in the hot path anyway.
unsafe { (*p).write() };
return 0;
}

#[no_mangle]
pub unsafe extern "C" fn __rust_rwlock_wrlock(p: *mut RwLock) -> i32 {
if p.is_null() {
return EINVAL;
}
unsafe { (*p).write() };
return 0;
}

#[no_mangle]
pub unsafe extern "C" fn __rust_rwlock_unlock(p: *mut RwLock) -> i32 {
if p.is_null() {
return EINVAL;
}
unsafe { (*p).write_unlock() };
return 0;
}
1 change: 1 addition & 0 deletions library/std/src/sys/pal/sgx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub mod fd;
pub mod fs;
#[path = "../unsupported/io.rs"]
pub mod io;
mod libunwind_integration;
pub mod net;
pub mod os;
#[path = "../unsupported/pipe.rs"]
Expand Down
21 changes: 0 additions & 21 deletions library/std/src/sys/pal/sgx/waitqueue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ impl<T> WaitVariable<T> {
WaitVariable { queue: WaitQueue::new(), lock: var }
}

pub fn queue_empty(&self) -> bool {
self.queue.is_empty()
}

pub fn lock_var(&self) -> &T {
&self.lock
}
Expand Down Expand Up @@ -98,19 +94,6 @@ impl Default for WaitQueue {
}
}

impl<'a, T> WaitGuard<'a, T> {
/// Returns which TCSes will be notified when this guard drops.
pub fn notified_tcs(&self) -> NotifiedTcs {
self.notified_tcs
}

/// Drop this `WaitGuard`, after dropping another `guard`.
pub fn drop_after<U>(self, guard: U) {
drop(guard);
drop(self);
}
}

impl<'a, T> Deref for WaitGuard<'a, T> {
type Target = SpinMutexGuard<'a, WaitVariable<T>>;

Expand Down Expand Up @@ -141,10 +124,6 @@ impl WaitQueue {
WaitQueue { inner: UnsafeList::new() }
}

pub fn is_empty(&self) -> bool {
self.inner.is_empty()
}

/// Adds the calling thread to the `WaitVariable`'s wait queue, then wait
/// until a wakeup event.
///
Expand Down
219 changes: 0 additions & 219 deletions library/std/src/sys/sync/rwlock/sgx.rs

This file was deleted.

21 changes: 0 additions & 21 deletions library/std/src/sys/sync/rwlock/sgx/tests.rs

This file was deleted.

0 comments on commit a30a79c

Please sign in to comment.