8000 Rollup of 10 pull requests by matthiaskrgr · Pull Request #105525 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Rollup of 10 pull requests #105525

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

Merged
merged 29 commits into from
Dec 10, 2022
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9678cec
std: rewrite SGX thread parker
joboet Jun 22, 2022
633d46d
std: reimplement SGX thread joining to use `Parker`
joboet Jun 22, 2022
a40d300
std: clarify semantics of SGX parker
joboet Sep 5, 2022
ac67262
Set `download-ci-llvm = "if-available"` by default when `channel = "d…
jyn514 Nov 17, 2022
7700595
Implement masking in FileType comparison on Unix
krtab Nov 25, 2022
6259028
Add test for regression for FileType equality
krtab Nov 30, 2022
4198d29
Implement masking in FileType hashing on Unix
krtab Dec 6, 2022
b45b948
Compute generator sizes with -Zprint_type_sizes
compiler-errors Nov 5, 2022
b0dcadf
Move closure/generator type info methods to TyCtxt
compiler-errors Dec 7, 2022
57b7226
Properly print generator interior type sizes
compiler-errors Dec 7, 2022
7d23e29
Pull out logic into distinct functions
compiler-errors Dec 7, 2022
ecf8127
Fix Async Generator ABI
Swatinem Nov 29, 2022
65698ae
Add LLVM KCFI support to the Rust compiler
rcvalle Nov 22, 2022
e1741ba
Add documentation for LLVM KCFI support
rcvalle Dec 1, 2022
24cd863
Replace hand-made masking by call to masked() method in FileType
krtab Dec 9, 2022
84a4635
Don't warn about unused parens when they are used by yeet expr
WaffleLapkin Dec 9, 2022
b9da55a
Introduce `Span::is_visible`
estebank Dec 9, 2022
ac90c9b
Update cargo
weihanglo Dec 10, 2022
f069e71
Correct wrong note for short circuiting operators
est31 Dec 10, 2022
ae8794c
8000 Rollup merge of #98391 - joboet:sgx_parker, r=m-ou-se
matthiaskrgr Dec 10, 2022
0f5d3ba
Rollup merge of #104019 - compiler-errors:print-generator-sizes, r=we…
matthiaskrgr Dec 10, 2022
1ce18d2
Rollup merge of #104512 - jyn514:download-ci-llvm-default, r=Mark-Sim…
matthiaskrgr Dec 10, 2022
eb1159c
Rollup merge of #104901 - krtab:filetype_compare, r=the8472
matthiaskrgr Dec 10, 2022
020d7af
Rollup merge of #105082 - Swatinem:async-abi, r=compiler-errors
matthiaskrgr Dec 10, 2022
947fe7e
Rollup merge of #105109 - rcvalle:rust-kcfi, r=bjorn3
matthiaskrgr Dec 10, 2022
9e87dd9
Rollup merge of #105505 - WaffleLapkin:yeet_unused_parens_lint, r=fee…
matthiaskrgr Dec 10, 2022
cf84006
Rollup merge of #105514 - estebank:is_visible, r=oli-obk
matthiaskrgr Dec 10, 2022
6d7e3df
Rollup merge of #105516 - weihanglo:update-cargo, r=weihanglo
matthiaskrgr Dec 10, 2022
f6c2add
Rollup merge of #105522 - est31:remove_or_and_note, r=scottmcm
matthiaskrgr Dec 10, 2022
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
Prev Previous commit
Next Next commit
std: clarify semantics of SGX parker
  • Loading branch information
joboet committed Sep 5, 2022
commit a40d300100a5e48cb66f5261738496dbacf11f99
44 changes: 29 additions & 15 deletions library/std/src/sys/sgx/thread_parker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ use crate::sync::atomic::Ordering::{Acquire, Relaxed, Release};
use crate::time::Duration;
use fortanix_sgx_abi::{EV_UNPARK, WAIT_INDEFINITE};

const EMPTY: *mut u8 = ptr::invalid_mut(0);
/// The TCS structure must be page-aligned, so this cannot be a valid pointer
const NOTIFIED: *mut u8 = ptr::invalid_mut(1);
// The TCS structure must be page-aligned (this is checked by EENTER), so these cannot
// be valid pointers
const EMPTY: *mut u8 = ptr::invalid_mut(1);
const NOTIFIED: *mut u8 = ptr::invalid_mut(2);

pub struct Parker {
/// The park state. One of EMPTY, NOTIFIED or a TCS address.
/// A state change to NOTIFIED must be done with release ordering
/// and be observed with acquire ordering so that operations after
/// `thread::park` returns will not occur before the unpark message
/// was sent.
state: AtomicPtr<u8>,
}

Expand All @@ -30,23 +36,28 @@ impl Parker {

// This implementation doesn't require `unsafe` and `Pin`, but other implementations do.
pub unsafe fn park(self: Pin<&Self>) {
let tcs = thread::current().as_ptr();

if self.state.load(Acquire) != NOTIFIED {
if self.state.compare_exchange(EMPTY, tcs, Acquire, Acquire).is_ok() {
// Loop to guard against spurious wakeups.
loop {
let mut prev = EMPTY;
loop {
// Guard against changing TCS addresses by always setting the state to
// the current value.
let tcs = thread::current().as_ptr();
if self.state.compare_exchange(prev, tcs, Relaxed, Acquire).is_ok() {
let event = usercalls::wait(EV_UNPARK, WAIT_INDEFINITE).unwrap();
assert!(event & EV_UNPARK == EV_UNPARK);
if self.state.load(Acquire) == NOTIFIED {
break;
}
prev = tcs;
} else {
// The state was definitely changed by another thread at this point.
// The only time this occurs is when the state is changed to NOTIFIED.
// We observed this change with acquire ordering, so we can simply
// change the state to EMPTY with a relaxed store.
break;
}
}
}

// At this point, the token was definately read with acquire ordering,
// so this can be a store.
// so this can be a relaxed store.
self.state.store(EMPTY, Relaxed);
}

Expand All @@ -56,7 +67,7 @@ impl Parker {
let tcs = thread::current().as_ptr();

if self.state.load(Acquire) != NOTIFIED {
if self.state.compare_exchange(EMPTY, tcs, Acquire, Acquire).is_ok() {
if self.state.compare_exchange(EMPTY, tcs, Relaxed, Acquire).is_ok() {
match usercalls::wait(EV_UNPARK, timeout) {
Ok(event) => assert!(event & EV_UNPARK == EV_UNPARK),
Err(e) => {
Expand Down Expand Up @@ -85,8 +96,11 @@ impl Parker {
if !matches!(state, EMPTY | NOTIFIED) {
// There is a thread waiting, wake it up.
let tcs = NonNull::new(state).unwrap();
// This will fail if the thread has already terminated by the time the signal is send,
// but that is OK.
// This will fail if the thread has already terminated or its TCS is destroyed
// by the time the signal is sent, but that is fine. If another thread receives
// the same TCS, it will receive this notification as a spurious wakeup, but
// all users of `wait` should and (internally) do guard against those where
// necessary.
let _ = usercalls::send(EV_UNPARK, Some(tcs));
}
}
Expand Down
0