Skip to content
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
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-12-19"
channel = "nightly-2024-02-26"
components = ["rustc", "cargo", "rust-std", "rust-src", "rustfmt"]
6 changes: 3 additions & 3 deletions src/arch/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use linux_raw_sys::general::{__NR_rt_sigreturn, __NR_sigreturn};
#[cfg(all(feature = "origin-thread", feature = "thread"))]
use {
core::ffi::c_void,
core::ptr::invalid_mut,
core::ptr::without_provenance_mut,
linux_raw_sys::general::{__NR_clone, __NR_exit, __NR_munmap},
rustix::thread::RawPid,
};
Expand Down Expand Up @@ -219,8 +219,8 @@ pub(super) unsafe fn clone(
entry = sym super::thread::entry,
inout("eax") &[
newtls.cast::<c_void>().cast_mut(),
invalid_mut(__NR_clone as usize),
invalid_mut(num_args)
without_provenance_mut(__NR_clone as usize),
without_provenance_mut(num_args)
] => r0,
in("ebx") flags,
in("ecx") child_stack,
Expand Down
4 changes: 2 additions & 2 deletions src/thread/libc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use alloc::boxed::Box;
use core::ffi::c_void;
use core::mem::{size_of, transmute, zeroed};
use core::ptr::{from_exposed_addr_mut, invalid_mut, null_mut, NonNull};
use core::ptr::{from_exposed_addr_mut, null_mut, without_provenance_mut, NonNull};
use core::slice;
use rustix::io;

Expand Down Expand Up @@ -134,7 +134,7 @@ pub unsafe fn create(
thread_arg_ptr.cast::<Option<NonNull<c_void>>>(),
args.len() + 2,
);
thread_args[0] = NonNull::new(invalid_mut(args.len()));
thread_args[0] = NonNull::new(without_provenance_mut(args.len()));
thread_args[1] = NonNull::new(fn_ as _);
thread_args[2..].copy_from_slice(args);

Expand Down
30 changes: 15 additions & 15 deletions test-crates/origin-start/src/bin/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extern crate compiler_builtins;
use alloc::boxed::Box;
use atomic_dbg::dbg;
use core::arch::asm;
use core::ptr::{addr_of_mut, invalid_mut};
use core::ptr::{addr_of_mut, without_provenance_mut};
use origin::{program, thread};

#[panic_handler]
Expand All @@ -37,25 +37,25 @@ unsafe fn origin_main(_argc: usize, _argv: *mut *mut u8, _envp: *mut *mut u8) ->
check_eq(TEST_DATA.0);

// Mutate one of the TLS fields.
THREAD_LOCAL[1] = invalid_mut(77);
THREAD_LOCAL[1] = without_provenance_mut(77);

// Assert that the mutation happened properly.
check_eq([TEST_DATA.0[0], invalid_mut(77), TEST_DATA.0[2]]);
check_eq([TEST_DATA.0[0], without_provenance_mut(77), TEST_DATA.0[2]]);

program::at_exit(Box::new(|| {
// This is the last thing to run. Assert that we see the value stored
// by the `at_thread_exit` callback.
check_eq([TEST_DATA.0[0], invalid_mut(79), TEST_DATA.0[2]]);
check_eq([TEST_DATA.0[0], without_provenance_mut(79), TEST_DATA.0[2]]);

// Mutate one of the TLS fields.
THREAD_LOCAL[1] = invalid_mut(80);
THREAD_LOCAL[1] = without_provenance_mut(80);
}));
thread::at_exit(Box::new(|| {
// Assert that we see the value stored at the end of `main`.
check_eq([TEST_DATA.0[0], invalid_mut(78), TEST_DATA.0[2]]);
check_eq([TEST_DATA.0[0], without_provenance_mut(78), TEST_DATA.0[2]]);

// Mutate one of the TLS fields.
THREAD_LOCAL[1] = invalid_mut(79);
THREAD_LOCAL[1] = without_provenance_mut(79);
}));

let thread = thread::create(
Expand All @@ -64,14 +64,14 @@ unsafe fn origin_main(_argc: usize, _argv: *mut *mut u8, _envp: *mut *mut u8) ->
check_eq(TEST_DATA.0);

// Mutate one of the TLS fields.
THREAD_LOCAL[1] = invalid_mut(175);
THREAD_LOCAL[1] = without_provenance_mut(175);

// Assert that the mutation happened properly.
check_eq([TEST_DATA.0[0], invalid_mut(175), TEST_DATA.0[2]]);
check_eq([TEST_DATA.0[0], without_provenance_mut(175), TEST_DATA.0[2]]);

thread::at_exit(Box::new(|| {
// Assert that we still see the value stored in the thread.
check_eq([TEST_DATA.0[0], invalid_mut(175), TEST_DATA.0[2]]);
check_eq([TEST_DATA.0[0], without_provenance_mut(175), TEST_DATA.0[2]]);
}));

None
Expand All @@ -85,13 +85,13 @@ unsafe fn origin_main(_argc: usize, _argv: *mut *mut u8, _envp: *mut *mut u8) ->
thread::join(thread);

// Assert that the main thread's TLS is still in place.
check_eq([TEST_DATA.0[0], invalid_mut(77), TEST_DATA.0[2]]);
check_eq([TEST_DATA.0[0], without_provenance_mut(77), TEST_DATA.0[2]]);

// Mutate one of the TLS fields.
THREAD_LOCAL[1] = invalid_mut(78);
THREAD_LOCAL[1] = without_provenance_mut(78);

// Assert that the mutation happened properly.
check_eq([TEST_DATA.0[0], invalid_mut(78), TEST_DATA.0[2]]);
check_eq([TEST_DATA.0[0], without_provenance_mut(78), TEST_DATA.0[2]]);

program::exit(200);
}
Expand All @@ -100,7 +100,7 @@ struct SyncTestData([*const u32; 3]);
unsafe impl Sync for SyncTestData {}
static TEST_DATA: SyncTestData = unsafe {
SyncTestData([
invalid_mut(0xa0b1a2b3a4b5a6b7_u64 as usize),
without_provenance_mut(0xa0b1a2b3a4b5a6b7_u64 as usize),
addr_of_mut!(SOME_REGULAR_DATA),
addr_of_mut!(SOME_ZERO_DATA),
])
Expand All @@ -120,7 +120,7 @@ fn check_eq(data: [*const u32; 3]) {
assert_eq!(THREAD_LOCAL, data);

// Check `THREAD_LOCAL` using a dynamic address.
let mut thread_local_addr: *mut [*const u32; 3] = &mut THREAD_LOCAL;
let mut thread_local_addr: *mut [*const u32; 3] = addr_of_mut!(THREAD_LOCAL);
asm!("# {}", inout(reg) thread_local_addr, options(pure, nomem, nostack, preserves_flags));
assert_eq!(*thread_local_addr, data);
}
Expand Down