summaryrefslogtreecommitdiffstats
path: root/library/std/src/sys/sgx
diff options
context:
space:
mode:
Diffstat (limited to 'library/std/src/sys/sgx')
-rw-r--r--library/std/src/sys/sgx/abi/entry.S10
-rw-r--r--library/std/src/sys/sgx/fd.rs1
-rw-r--r--library/std/src/sys/sgx/net.rs3
-rw-r--r--library/std/src/sys/sgx/waitqueue/mod.rs16
4 files changed, 24 insertions, 6 deletions
diff --git a/library/std/src/sys/sgx/abi/entry.S b/library/std/src/sys/sgx/abi/entry.S
index f61bcf06f..8a063b65d 100644
--- a/library/std/src/sys/sgx/abi/entry.S
+++ b/library/std/src/sys/sgx/abi/entry.S
@@ -26,7 +26,7 @@ IMAGE_BASE:
.Lxsave_clear:
.org .+24
.Lxsave_mxcsr:
- .short 0x1f80
+ .short 0x1fbf
/* We can store a bunch of data in the gap between MXCSR and the XSAVE header */
@@ -58,7 +58,7 @@ IMAGE_BASE:
globvar DEBUG 1
/* The base address (relative to enclave start) of the enclave text section */
globvar TEXT_BASE 8
- /* The size in bytes of enclacve text section */
+ /* The size in bytes of enclave text section */
globvar TEXT_SIZE 8
/* The base address (relative to enclave start) of the enclave .eh_frame_hdr section */
globvar EH_FRM_HDR_OFFSET 8
@@ -66,7 +66,7 @@ IMAGE_BASE:
globvar EH_FRM_HDR_LEN 8
/* The base address (relative to enclave start) of the enclave .eh_frame section */
globvar EH_FRM_OFFSET 8
- /* The size in bytes of enclacve .eh_frame section */
+ /* The size in bytes of enclave .eh_frame section */
globvar EH_FRM_LEN 8
.org .Lxsave_clear+512
@@ -178,6 +178,7 @@ sgx_entry:
mov $-1, %rax
mov $-1, %rdx
xrstor .Lxsave_clear(%rip)
+ lfence
mov %r10, %rdx
/* check if returning from usercall */
@@ -311,6 +312,9 @@ usercall:
movq $0,%gs:tcsls_last_rsp
/* restore callee-saved state, cf. "save" above */
mov %r11,%rsp
+ /* MCDT mitigation requires an lfence after ldmxcsr _before_ any of the affected */
+ /* vector instructions is used. We omit the lfence here as one is required before */
+ /* the jmp instruction anyway. */
ldmxcsr (%rsp)
fldcw 4(%rsp)
add $8, %rsp
diff --git a/library/std/src/sys/sgx/fd.rs b/library/std/src/sys/sgx/fd.rs
index 0c02a1076..b3686d0e2 100644
--- a/library/std/src/sys/sgx/fd.rs
+++ b/library/std/src/sys/sgx/fd.rs
@@ -62,6 +62,7 @@ impl FileDesc {
}
impl AsInner<Fd> for FileDesc {
+ #[inline]
fn as_inner(&self) -> &Fd {
&self.fd
}
diff --git a/library/std/src/sys/sgx/net.rs b/library/std/src/sys/sgx/net.rs
index 923be5eb9..03620a08f 100644
--- a/library/std/src/sys/sgx/net.rs
+++ b/library/std/src/sys/sgx/net.rs
@@ -24,6 +24,7 @@ impl Socket {
}
impl AsInner<FileDesc> for Socket {
+ #[inline]
fn as_inner(&self) -> &FileDesc {
&self.inner
}
@@ -220,6 +221,7 @@ impl TcpStream {
}
impl AsInner<Socket> for TcpStream {
+ #[inline]
fn as_inner(&self) -> &Socket {
&self.inner
}
@@ -304,6 +306,7 @@ impl TcpListener {
}
impl AsInner<Socket> for TcpListener {
+ #[inline]
fn as_inner(&self) -> &Socket {
&self.inner
}
diff --git a/library/std/src/sys/sgx/waitqueue/mod.rs b/library/std/src/sys/sgx/waitqueue/mod.rs
index 61bb11d9a..5e1d859ee 100644
--- a/library/std/src/sys/sgx/waitqueue/mod.rs
+++ b/library/std/src/sys/sgx/waitqueue/mod.rs
@@ -202,12 +202,18 @@ impl WaitQueue {
pub fn notify_one<T>(
mut guard: SpinMutexGuard<'_, WaitVariable<T>>,
) -> Result<WaitGuard<'_, T>, SpinMutexGuard<'_, WaitVariable<T>>> {
+ // SAFETY: lifetime of the pop() return value is limited to the map
+ // closure (The closure return value is 'static). The underlying
+ // stack frame won't be freed until after the WaitGuard created below
+ // is dropped.
unsafe {
- if let Some(entry) = guard.queue.inner.pop() {
+ let tcs = guard.queue.inner.pop().map(|entry| -> Tcs {
let mut entry_guard = entry.lock();
- let tcs = entry_guard.tcs;
entry_guard.wake = true;
- drop(entry);
+ entry_guard.tcs
+ });
+
+ if let Some(tcs) = tcs {
Ok(WaitGuard { mutex_guard: Some(guard), notified_tcs: NotifiedTcs::Single(tcs) })
} else {
Err(guard)
@@ -223,6 +229,9 @@ impl WaitQueue {
pub fn notify_all<T>(
mut guard: SpinMutexGuard<'_, WaitVariable<T>>,
) -> Result<WaitGuard<'_, T>, SpinMutexGuard<'_, WaitVariable<T>>> {
+ // SAFETY: lifetime of the pop() return values are limited to the
+ // while loop body. The underlying stack frames won't be freed until
+ // after the WaitGuard created below is dropped.
unsafe {
let mut count = 0;
while let Some(entry) = guard.queue.inner.pop() {
@@ -230,6 +239,7 @@ impl WaitQueue {
let mut entry_guard = entry.lock();
entry_guard.wake = true;
}
+
if let Some(count) = NonZeroUsize::new(count) {
Ok(WaitGuard { mutex_guard: Some(guard), notified_tcs: NotifiedTcs::All { count } })
} else {