Skip to content

Commit 4916b63

Browse files
committed
libs: Simplify implementations of thread parking and guard::enable
Fixes #226.
1 parent 7e12cec commit 4916b63

File tree

3 files changed

+33
-92
lines changed

3 files changed

+33
-92
lines changed

libs/Patches.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,17 @@ into the main commit for that patch, and then the *Update* line can be removed.
238238
This feature was using an `AtomicPtr<()>` with a cast from function
239239
pointer to `*mut ()` that we don't support in its initializer.
240240

241+
* Simplify implementations of thread parking and `guard::enable` (last applied: January 22, 2025)
242+
243+
The real implementations of these parts of the code use low-level,
244+
OS-specific primitives (e.g., system calls) that Crucible cannot support. We
245+
uniformly replace these parts of the code with simpler implementations:
246+
247+
* We use the `unsupported` configuration for thread parking, where all
248+
parking-related functions are treated as no-ops.
249+
* We use the Wasm configuration for the internal `guard::enable` function,
250+
which simply leaks everything.
251+
241252
# Notes
242253

243254
This section contains more detailed notes about why certain patches are written
Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,10 @@
1-
cfg_select! {
2-
any(
3-
all(target_os = "windows", not(target_vendor = "win7")),
4-
target_os = "linux",
5-
target_os = "android",
6-
all(target_arch = "wasm32", target_feature = "atomics"),
7-
target_os = "freebsd",
8-
target_os = "openbsd",
9-
target_os = "dragonfly",
10-
target_os = "fuchsia",
11-
target_os = "hermit",
12-
) => {
13-
mod futex;
14-
pub use futex::Parker;
15-
}
16-
any(
17-
target_os = "netbsd",
18-
all(target_vendor = "fortanix", target_env = "sgx"),
19-
target_os = "solid_asp3",
20-
) => {
21-
mod id;
22-
pub use id::Parker;
23-
}
24-
target_vendor = "win7" => {
25-
mod windows7;
26-
pub use windows7::Parker;
27-
}
28-
all(target_vendor = "apple", not(miri)) => {
29-
// Doesn't work in Miri, see <https://github.com/rust-lang/miri/issues/2589>.
30-
mod darwin;
31-
pub use darwin::Parker;
32-
}
33-
target_os = "xous" => {
34-
mod xous;
35-
pub use xous::Parker;
36-
}
37-
target_family = "unix" => {
38-
mod pthread;
39-
pub use pthread::Parker;
40-
}
41-
_ => {
42-
mod unsupported;
43-
pub use unsupported::Parker;
44-
}
45-
}
1+
// For crucible-mir's benefit, we always use unsupported::Parker, which
2+
// implements all thread-parking functions as no-ops. This is arguably too
3+
// simplistic, as this skips calling operations that could trigger a context
4+
// switch in concurrent programs. Although crux-mir does have some support for
5+
// modeling this sort of concurrency, it has since bitrotted. (See #238.) If
6+
// this concurrency support is revived, then we will need to revisit the
7+
// approach here.
8+
9+
mod unsupported;
10+
pub use unsupported::Parker;

libs/std/src/sys/thread_local/mod.rs

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -82,53 +82,18 @@ pub(crate) mod destructors {
8282
/// and the [runtime cleanup](crate::rt::thread_cleanup) function. Calling `enable`
8383
/// should ensure that these functions are called at the right times.
8484
pub(crate) mod guard {
85-
cfg_select! {
86-
all(target_thread_local, target_vendor = "apple") => {
87-
mod apple;
88-
pub(crate) use apple::enable;
89-
}
90-
target_os = "windows" => {
91-
mod windows;
92-
pub(crate) use windows::enable;
93-
}
94-
any(
95-
all(target_family = "wasm", not(
96-
all(target_os = "wasi", target_env = "p1", target_feature = "atomics")
97-
)),
98-
target_os = "uefi",
99-
target_os = "zkvm",
100-
target_os = "trusty",
101-
) => {
102-
pub(crate) fn enable() {
103-
// FIXME: Right now there is no concept of "thread exit" on
104-
// wasm, but this is likely going to show up at some point in
105-
// the form of an exported symbol that the wasm runtime is going
106-
// to be expected to call. For now we just leak everything, but
107-
// if such a function starts to exist it will probably need to
108-
// iterate the destructor list with these functions:
109-
#[cfg(all(target_family = "wasm", target_feature = "atomics"))]
110-
#[allow(unused)]
111-
use super::destructors::run;
112-
#[allow(unused)]
113-
use crate::rt::thread_cleanup;
114-
}
115-
}
116-
any(
117-
target_os = "hermit",
118-
target_os = "xous",
119-
) => {
120-
// `std` is the only runtime, so it just calls the destructor functions
121-
// itself when the time comes.
122-
pub(crate) fn enable() {}
123-
}
124-
target_os = "solid_asp3" => {
125-
mod solid;
126-
pub(crate) use solid::enable;
127-
}
128-
_ => {
129-
mod key;
130-
pub(crate) use key::enable;
131-
}
85+
pub(crate) fn enable() {
86+
// FIXME: Right now there is no concept of "thread exit" on
87+
// wasm, but this is likely going to show up at some point in
88+
// the form of an exported symbol that the wasm runtime is going
89+
// to be expected to call. For now we just leak everything, but
90+
// if such a function starts to exist it will probably need to
91+
// iterate the destructor list with these functions:
92+
#[cfg(all(target_family = "wasm", target_feature = "atomics"))]
93+
#[allow(unused)]
94+
use super::destructors::run;
95+
#[allow(unused)]
96+
use crate::rt::thread_cleanup;
13297
}
13398
}
13499

0 commit comments

Comments
 (0)