Skip to content

Commit a58f27e

Browse files
authored
Update to rustix 0.38.35 and the new futex API. (#130)
1 parent 15727b5 commit a58f27e

4 files changed

Lines changed: 20 additions & 15 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ include = ["src", "Cargo.toml", "COPYRIGHT", "LICENSE*", "/*.md"]
1515

1616
[dependencies]
1717
linux-raw-sys = { version = "0.4.9", default-features = false, features = ["general", "no_std", "elf"] }
18-
rustix = { version = "0.38.34", default-features = false }
18+
rustix = { version = "0.38.35", default-features = false }
1919
bitflags = { version = "2.4.0", default-features = false }
2020
log = { version = "0.4.14", default-features = false, optional = true }
2121
rustix-futex-sync = { version = "0.2.1", optional = true }

src/arch/x86_64.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ pub(super) unsafe fn relocation_load(ptr: usize) -> usize {
104104
/// Perform a single store operation, outside the Rust memory model.
105105
///
106106
/// This function conceptually casts `ptr` to a `*mut *mut c_void` and stores
107-
/// a `*mut c_void` value to it. However, it does this using `asm`, and `usize`
108-
/// types which don't carry provenance, as it's used by `relocate` to perform
109-
/// relocations which cannot be expressed in the Rust memory model.
107+
/// `value` casted to `*mut c_void` through it. However, it does this using
108+
/// `asm`, and `usize` types which don't carry provenance, as it's used by
109+
/// `relocate` to perform relocations which cannot be expressed in the Rust
110+
/// memory model.
110111
///
111112
/// # Safety
112113
///

src/relocate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ pub(super) unsafe fn relocate(envp: *mut *mut u8) {
284284
#[cfg(debug_assertions)]
285285
{
286286
// Check that the page size is a power of two.
287-
assert_eq!(auxv_page_size.count_ones(), 1);
287+
assert!(auxv_page_size.is_power_of_two());
288288

289289
// This code doesn't rely on the offset being page aligned, but it is
290290
// useful to check to make sure we computed it correctly.

src/thread/linux_raw.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use core::mem::{align_of, offset_of, size_of};
2020
use core::ptr::{copy_nonoverlapping, drop_in_place, null, null_mut, NonNull};
2121
use core::slice;
2222
use core::sync::atomic::Ordering::SeqCst;
23-
use core::sync::atomic::{AtomicI32, AtomicPtr, AtomicU8};
23+
use core::sync::atomic::{AtomicI32, AtomicPtr, AtomicU32, AtomicU8};
2424
use linux_raw_sys::elf::*;
2525
use rustix::io;
2626
use rustix::mm::{mmap_anonymous, mprotect, MapFlags, MprotectFlags, ProtFlags};
@@ -457,7 +457,7 @@ unsafe fn initialize_tls(
457457
)
458458
.fill(0);
459459

460-
let thread_id_ptr = (*metadata).thread.thread_id.as_ptr();
460+
let thread_id_ptr = (*metadata).thread.thread_id.as_ptr().cast::<i32>();
461461

462462
(newtls, thread_id_ptr)
463463
}
@@ -719,6 +719,13 @@ unsafe fn exit(return_value: Option<NonNull<c_void>>) -> ! {
719719
// no signals for the process are delivered to this thread.
720720
#[cfg(feature = "signal")]
721721
{
722+
#[cfg(any(target_arch = "arm", target_arch = "x86"))]
723+
let all = Sigset { sig: [!0, !0] };
724+
#[cfg(any(
725+
target_arch = "aarch64",
726+
target_arch = "riscv64",
727+
target_arch = "x86_64"
728+
))]
722729
let all = Sigset { sig: [!0] };
723730
sigprocmask(How::BLOCK, Some(&all)).ok();
724731
}
@@ -857,7 +864,7 @@ pub unsafe fn join(thread: Thread) -> Option<NonNull<c_void>> {
857864
/// `thread` must point to a valid thread record that has not already been
858865
/// detached or joined.
859866
unsafe fn wait_for_exit(thread: Thread) {
860-
use rustix::thread::{futex, FutexFlags, FutexOperation};
867+
use rustix::thread::futex;
861868

862869
// Check whether the thread has exited already; we set the
863870
// `CloneFlags::CHILD_CLEARTID` flag on the clone syscall, so we can test
@@ -869,14 +876,11 @@ unsafe fn wait_for_exit(thread: Thread) {
869876
// `FutexFlags::PRIVATE` because the wake comes from Linux
870877
// as arranged by the `CloneFlags::CHILD_CLEARTID` flag,
871878
// and Linux doesn't use the private flag for the wake.
872-
match futex(
873-
thread_id.as_ptr().cast::<u32>(),
874-
FutexOperation::Wait,
875-
FutexFlags::empty(),
879+
match futex::wait(
880+
AtomicU32::from_ptr(thread_id.as_ptr().cast()),
881+
futex::Flags::empty(),
876882
id_value.as_raw_nonzero().get() as u32,
877-
null(),
878-
null_mut(),
879-
0,
883+
None,
880884
) {
881885
Ok(_) => break,
882886
Err(io::Errno::INTR) => continue,

0 commit comments

Comments
 (0)