Skip to content

Commit a30a79c

Browse files
committed
std: use queue-based RwLock on SGX
1 parent 72fe8a0 commit a30a79c

File tree

5 files changed

+47
-261
lines changed

5 files changed

+47
-261
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//! The functions in this module are needed by libunwind. These symbols are named
2+
//! in pre-link args for the target specification, so keep that in sync.
3+
4+
#![cfg(not(test))]
5+
6+
use crate::sys::sync::RwLock;
7+
8+
// Verify that the byte pattern libunwind uses to initialize an RwLock is
9+
// equivalent to the value of RwLock::new(). If the value changes,
10+
// `src/UnwindRustSgx.h` in libunwind needs to be changed too.
11+
const _: () = unsafe {
12+
let bits_rust: usize = crate::mem::transmute(RwLock::new());
13+
assert!(bits_rust == 0);
14+
};
15+
16+
const EINVAL: i32 = 22;
17+
18+
#[no_mangle]
19+
pub unsafe extern "C" fn __rust_rwlock_rdlock(p: *mut RwLock) -> i32 {
20+
if p.is_null() {
21+
return EINVAL;
22+
}
23+
24+
// We cannot differentiate between reads an writes in unlock and therefore
25+
// always use a write-lock. Unwinding isn't really in the hot path anyway.
26+
unsafe { (*p).write() };
27+
return 0;
28+
}
29+
30+
#[no_mangle]
31+
pub unsafe extern "C" fn __rust_rwlock_wrlock(p: *mut RwLock) -> i32 {
32+
if p.is_null() {
33+
return EINVAL;
34+
}
35+
unsafe { (*p).write() };
36+
return 0;
37+
}
38+
39+
#[no_mangle]
40+
pub unsafe extern "C" fn __rust_rwlock_unlock(p: *mut RwLock) -> i32 {
41+
if p.is_null() {
42+
return EINVAL;
43+
}
44+
unsafe { (*p).write_unlock() };
45+
return 0;
46+
}

library/std/src/sys/pal/sgx/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub mod fd;
1717
pub mod fs;
1818
#[path = "../unsupported/io.rs"]
1919
pub mod io;
20+
mod libunwind_integration;
2021
pub mod net;
2122
pub mod os;
2223
#[path = "../unsupported/pipe.rs"]

library/std/src/sys/pal/sgx/waitqueue/mod.rs

-21
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ impl<T> WaitVariable<T> {
5252
WaitVariable { queue: WaitQueue::new(), lock: var }
5353
}
5454

55-
pub fn queue_empty(&self) -> bool {
56-
self.queue.is_empty()
57-
}
58-
5955
pub fn lock_var(&self) -> &T {
6056
&self.lock
6157
}
@@ -98,19 +94,6 @@ impl Default for WaitQueue {
9894
}
9995
}
10096

101-
impl<'a, T> WaitGuard<'a, T> {
102-
/// Returns which TCSes will be notified when this guard drops.
103-
pub fn notified_tcs(&self) -> NotifiedTcs {
104-
self.notified_tcs
105-
}
106-
107-
/// Drop this `WaitGuard`, after dropping another `guard`.
108-
pub fn drop_after<U>(self, guard: U) {
109-
drop(guard);
110-
drop(self);
111-
}
112-
}
113-
11497
impl<'a, T> Deref for WaitGuard<'a, T> {
11598
type Target = SpinMutexGuard<'a, WaitVariable<T>>;
11699

@@ -141,10 +124,6 @@ impl WaitQueue {
141124
WaitQueue { inner: UnsafeList::new() }
142125
}
143126

144-
pub fn is_empty(&self) -> bool {
145-
self.inner.is_empty()
146-
}
147-
148127
/// Adds the calling thread to the `WaitVariable`'s wait queue, then wait
149128
/// until a wakeup event.
150129
///

library/std/src/sys/sync/rwlock/sgx.rs

-219
This file was deleted.

library/std/src/sys/sync/rwlock/sgx/tests.rs

-21
This file was deleted.

0 commit comments

Comments
 (0)