Skip to content

Commit 930eadc

Browse files
authored
Rename invalid_mut to without_provenance_mut (#109)
* Renamed `invalid_mut` to `without_provenance_mut` * Bump nightly version * Use `addr_of_mut!()` instead of a reference to a `static mut`.
1 parent 9b9b5f9 commit 930eadc

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2023-12-19"
2+
channel = "nightly-2024-02-26"
33
components = ["rustc", "cargo", "rust-std", "rust-src", "rustfmt"]

src/arch/x86.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use linux_raw_sys::general::{__NR_rt_sigreturn, __NR_sigreturn};
99
#[cfg(all(feature = "origin-thread", feature = "thread"))]
1010
use {
1111
core::ffi::c_void,
12-
core::ptr::invalid_mut,
12+
core::ptr::without_provenance_mut,
1313
linux_raw_sys::general::{__NR_clone, __NR_exit, __NR_munmap},
1414
rustix::thread::RawPid,
1515
};
@@ -219,8 +219,8 @@ pub(super) unsafe fn clone(
219219
entry = sym super::thread::entry,
220220
inout("eax") &[
221221
newtls.cast::<c_void>().cast_mut(),
222-
invalid_mut(__NR_clone as usize),
223-
invalid_mut(num_args)
222+
without_provenance_mut(__NR_clone as usize),
223+
without_provenance_mut(num_args)
224224
] => r0,
225225
in("ebx") flags,
226226
in("ecx") child_stack,

src/thread/libc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use alloc::boxed::Box;
44
use core::ffi::c_void;
55
use core::mem::{size_of, transmute, zeroed};
6-
use core::ptr::{from_exposed_addr_mut, invalid_mut, null_mut, NonNull};
6+
use core::ptr::{from_exposed_addr_mut, null_mut, without_provenance_mut, NonNull};
77
use core::slice;
88
use rustix::io;
99

@@ -134,7 +134,7 @@ pub unsafe fn create(
134134
thread_arg_ptr.cast::<Option<NonNull<c_void>>>(),
135135
args.len() + 2,
136136
);
137-
thread_args[0] = NonNull::new(invalid_mut(args.len()));
137+
thread_args[0] = NonNull::new(without_provenance_mut(args.len()));
138138
thread_args[1] = NonNull::new(fn_ as _);
139139
thread_args[2..].copy_from_slice(args);
140140

test-crates/origin-start/src/bin/tls.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ extern crate compiler_builtins;
1616
use alloc::boxed::Box;
1717
use atomic_dbg::dbg;
1818
use core::arch::asm;
19-
use core::ptr::{addr_of_mut, invalid_mut};
19+
use core::ptr::{addr_of_mut, without_provenance_mut};
2020
use origin::{program, thread};
2121

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

3939
// Mutate one of the TLS fields.
40-
THREAD_LOCAL[1] = invalid_mut(77);
40+
THREAD_LOCAL[1] = without_provenance_mut(77);
4141

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

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

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

5757
// Mutate one of the TLS fields.
58-
THREAD_LOCAL[1] = invalid_mut(79);
58+
THREAD_LOCAL[1] = without_provenance_mut(79);
5959
}));
6060

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

6666
// Mutate one of the TLS fields.
67-
THREAD_LOCAL[1] = invalid_mut(175);
67+
THREAD_LOCAL[1] = without_provenance_mut(175);
6868

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

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

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

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

9090
// Mutate one of the TLS fields.
91-
THREAD_LOCAL[1] = invalid_mut(78);
91+
THREAD_LOCAL[1] = without_provenance_mut(78);
9292

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

9696
program::exit(200);
9797
}
@@ -100,7 +100,7 @@ struct SyncTestData([*const u32; 3]);
100100
unsafe impl Sync for SyncTestData {}
101101
static TEST_DATA: SyncTestData = unsafe {
102102
SyncTestData([
103-
invalid_mut(0xa0b1a2b3a4b5a6b7_u64 as usize),
103+
without_provenance_mut(0xa0b1a2b3a4b5a6b7_u64 as usize),
104104
addr_of_mut!(SOME_REGULAR_DATA),
105105
addr_of_mut!(SOME_ZERO_DATA),
106106
])
@@ -120,7 +120,7 @@ fn check_eq(data: [*const u32; 3]) {
120120
assert_eq!(THREAD_LOCAL, data);
121121

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

0 commit comments

Comments
 (0)