Skip to content
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

Run TLS destructors for wasm32-wasip1-threads #133472

Merged
merged 4 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions library/std/src/sys/thread_local/key/unix.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
use crate::mem;

// For WASI add a few symbols not in upstream `libc` just yet.
#[cfg(all(target_os = "wasi", target_env = "p1", target_feature = "atomics"))]
mod libc {
use crate::ffi;

#[allow(non_camel_case_types)]
pub type pthread_key_t = ffi::c_uint;

extern "C" {
pub fn pthread_key_create(
key: *mut pthread_key_t,
destructor: unsafe extern "C" fn(*mut ffi::c_void),
) -> ffi::c_int;
#[allow(dead_code)]
pub fn pthread_getspecific(key: pthread_key_t) -> *mut ffi::c_void;
pub fn pthread_setspecific(key: pthread_key_t, value: *const ffi::c_void) -> ffi::c_int;
pub fn pthread_key_delete(key: pthread_key_t) -> ffi::c_int;
}
}

pub type Key = libc::pthread_key_t;

#[inline]
Expand Down
5 changes: 4 additions & 1 deletion library/std/src/sys/thread_local/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ pub(crate) mod guard {
mod windows;
pub(crate) use windows::enable;
} else if #[cfg(any(
target_family = "wasm",
all(target_family = "wasm", not(
all(target_os = "wasi", target_env = "p1", target_feature = "atomics")
)),
target_os = "uefi",
target_os = "zkvm",
))] {
Expand Down Expand Up @@ -135,6 +137,7 @@ pub(crate) mod key {
target_family = "unix",
),
target_os = "teeos",
all(target_os = "wasi", target_env = "p1", target_feature = "atomics"),
))] {
mod racy;
mod unix;
Expand Down
Loading