Skip to content

Commit 80f44cb

Browse files
authored
Use &raw from Rust 1.82 (bytecodealliance#9960)
This commit leverages bytecodealliance#9956 to use the `&raw` syntax for creating raw pointers instead of using the `ptr::addr_of!` macro.
1 parent 00b7f8d commit 80f44cb

File tree

8 files changed

+24
-25
lines changed

8 files changed

+24
-25
lines changed

crates/wasi-preview1-component-adapter/src/descriptors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl Descriptors {
270270
if len >= (*table).len() {
271271
return Err(wasi::ERRNO_NOMEM);
272272
}
273-
core::ptr::addr_of_mut!((*table)[len]).write(desc);
273+
(&raw mut (*table)[len]).write(desc);
274274
self.table_len.set(u16::try_from(len + 1).trapping_unwrap());
275275
Ok(Fd::from(u32::try_from(len).trapping_unwrap()))
276276
}

crates/wasmtime/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,11 @@ macro_rules! map_maybe_uninit {
334334
use $crate::MaybeUninitExt;
335335

336336
let m: &mut core::mem::MaybeUninit<_> = $maybe_uninit;
337-
// Note the usage of `addr_of_mut!` here which is an attempt to "stay
337+
// Note the usage of `&raw` here which is an attempt to "stay
338338
// safe" here where we never accidentally create `&mut T` where `T` is
339339
// actually uninitialized, hopefully appeasing the Rust unsafe
340340
// guidelines gods.
341-
m.map(|p| core::ptr::addr_of_mut!((*p)$($field)*))
341+
m.map(|p| &raw mut (*p)$($field)*)
342342
}
343343
}
344344
})

crates/wasmtime/src/runtime/store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1834,7 +1834,7 @@ impl StoreOpaque {
18341834

18351835
Some(AsyncCx {
18361836
current_suspend: self.async_state.current_suspend.get(),
1837-
current_poll_cx: unsafe { core::ptr::addr_of_mut!((*poll_cx_box_ptr).future_context) },
1837+
current_poll_cx: unsafe { &raw mut (*poll_cx_box_ptr).future_context },
18381838
track_pkey_context_switch: self.pkey.is_some(),
18391839
})
18401840
}

crates/wasmtime/src/runtime/vm/component.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl ComponentInstance {
228228
}
229229

230230
fn vmctx(&self) -> *mut VMComponentContext {
231-
let addr = core::ptr::addr_of!(self.vmctx);
231+
let addr = &raw const self.vmctx;
232232
Strict::with_addr(self.vmctx_self_reference.as_ptr(), Strict::addr(addr))
233233
}
234234

crates/wasmtime/src/runtime/vm/instance.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ impl Instance {
644644
// today so the `sptr` crate is used. This crate provides the extension
645645
// trait `Strict` but the method names conflict with the nightly methods
646646
// so a different syntax is used to invoke methods here.
647-
let addr = ptr::addr_of!(self.vmctx);
647+
let addr = &raw const self.vmctx;
648648
Strict::with_addr(self.vmctx_self_reference.as_ptr(), Strict::addr(addr))
649649
}
650650

@@ -1067,7 +1067,7 @@ impl Instance {
10671067

10681068
/// Get a locally-defined memory.
10691069
pub fn get_defined_memory(&mut self, index: DefinedMemoryIndex) -> *mut Memory {
1070-
ptr::addr_of_mut!(self.memories[index].1)
1070+
&raw mut self.memories[index].1
10711071
}
10721072

10731073
/// Do a `memory.copy`
@@ -1287,20 +1287,20 @@ impl Instance {
12871287
}
12881288
}
12891289

1290-
ptr::addr_of_mut!(self.tables[idx].1)
1290+
&raw mut self.tables[idx].1
12911291
}
12921292

12931293
/// Get a table by index regardless of whether it is locally-defined or an
12941294
/// imported, foreign table.
12951295
pub(crate) fn get_table(&mut self, table_index: TableIndex) -> *mut Table {
12961296
self.with_defined_table_index_and_instance(table_index, |idx, instance| {
1297-
ptr::addr_of_mut!(instance.tables[idx].1)
1297+
&raw mut instance.tables[idx].1
12981298
})
12991299
}
13001300

13011301
/// Get a locally-defined table.
13021302
pub(crate) fn get_defined_table(&mut self, index: DefinedTableIndex) -> *mut Table {
1303-
ptr::addr_of_mut!(self.tables[index].1)
1303+
&raw mut self.tables[index].1
13041304
}
13051305

13061306
pub(crate) fn with_defined_table_index_and_instance<R>(

crates/wasmtime/src/runtime/vm/sys/unix/machports.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ use mach2::thread_status::*;
5656
use mach2::traps::*;
5757
use std::io;
5858
use std::mem;
59-
use std::ptr::addr_of_mut;
6059
use std::thread;
6160
use wasmtime_environ::Trap;
6261

@@ -85,7 +84,7 @@ impl TrapHandler {
8584
// Allocate our WASMTIME_PORT and make sure that it can be sent to so we
8685
// can receive exceptions.
8786
let me = mach_task_self();
88-
let kret = mach_port_allocate(me, MACH_PORT_RIGHT_RECEIVE, addr_of_mut!(WASMTIME_PORT));
87+
let kret = mach_port_allocate(me, MACH_PORT_RIGHT_RECEIVE, &raw mut WASMTIME_PORT);
8988
assert_eq!(kret, KERN_SUCCESS, "failed to allocate port");
9089
let kret =
9190
mach_port_insert_right(me, WASMTIME_PORT, WASMTIME_PORT, MACH_MSG_TYPE_MAKE_SEND);
@@ -103,7 +102,7 @@ impl TrapHandler {
103102
handler.sa_flags = libc::SA_SIGINFO | libc::SA_ONSTACK;
104103
handler.sa_sigaction = sigbus_handler as usize;
105104
libc::sigemptyset(&mut handler.sa_mask);
106-
if libc::sigaction(libc::SIGBUS, &handler, addr_of_mut!(PREV_SIGBUS)) != 0 {
105+
if libc::sigaction(libc::SIGBUS, &handler, &raw mut PREV_SIGBUS) != 0 {
107106
panic!(
108107
"unable to install signal handler: {}",
109108
io::Error::last_os_error(),
@@ -149,7 +148,7 @@ unsafe extern "C" fn sigbus_handler(
149148
});
150149

151150
super::signals::delegate_signal_to_previous_handler(
152-
addr_of_mut!(PREV_SIGBUS),
151+
&raw mut PREV_SIGBUS,
153152
signum,
154153
siginfo,
155154
context,

crates/wasmtime/src/runtime/vm/sys/unix/signals.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::runtime::vm::traphandlers::{tls, TrapRegisters, TrapTest};
66
use std::cell::RefCell;
77
use std::io;
88
use std::mem;
9-
use std::ptr::{self, addr_of, addr_of_mut, null_mut};
9+
use std::ptr::{self, null_mut};
1010

1111
/// Function which may handle custom signals while processing traps.
1212
pub type SignalHandler =
@@ -67,22 +67,22 @@ impl TrapHandler {
6767
}
6868
}
6969

70-
unsafe fn foreach_handler(mut f: impl FnMut(*mut libc::sigaction, i32)) {
70+
fn foreach_handler(mut f: impl FnMut(*mut libc::sigaction, i32)) {
7171
// Allow handling OOB with signals on all architectures
72-
f(addr_of_mut!(PREV_SIGSEGV), libc::SIGSEGV);
72+
f(&raw mut PREV_SIGSEGV, libc::SIGSEGV);
7373

7474
// Handle `unreachable` instructions which execute `ud2` right now
75-
f(addr_of_mut!(PREV_SIGILL), libc::SIGILL);
75+
f(&raw mut PREV_SIGILL, libc::SIGILL);
7676

7777
// x86 and s390x use SIGFPE to report division by zero
7878
if cfg!(target_arch = "x86_64") || cfg!(target_arch = "s390x") {
79-
f(addr_of_mut!(PREV_SIGFPE), libc::SIGFPE);
79+
f(&raw mut PREV_SIGFPE, libc::SIGFPE);
8080
}
8181

8282
// Sometimes we need to handle SIGBUS too:
8383
// - On Darwin, guard page accesses are raised as SIGBUS.
8484
if cfg!(target_vendor = "apple") || cfg!(target_os = "freebsd") {
85-
f(addr_of_mut!(PREV_SIGBUS), libc::SIGBUS);
85+
f(&raw mut PREV_SIGBUS, libc::SIGBUS);
8686
}
8787

8888
// TODO(#1980): x86-32, if we support it, will also need a SIGFPE handler.
@@ -132,10 +132,10 @@ unsafe extern "C" fn trap_handler(
132132
context: *mut libc::c_void,
133133
) {
134134
let previous = match signum {
135-
libc::SIGSEGV => addr_of!(PREV_SIGSEGV),
136-
libc::SIGBUS => addr_of!(PREV_SIGBUS),
137-
libc::SIGFPE => addr_of!(PREV_SIGFPE),
138-
libc::SIGILL => addr_of!(PREV_SIGILL),
135+
libc::SIGSEGV => &raw const PREV_SIGSEGV,
136+
libc::SIGBUS => &raw const PREV_SIGBUS,
137+
libc::SIGFPE => &raw const PREV_SIGFPE,
138+
libc::SIGILL => &raw const PREV_SIGILL,
139139
_ => panic!("unknown signal: {signum}"),
140140
};
141141
let handled = tls::with(|info| {

examples/min-platform/embedding/src/allocator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ unsafe impl dlmalloc::Allocator for MyAllocator {
7474
(ptr::null_mut(), 0, 0)
7575
} else {
7676
INITIAL_HEAP_ALLOCATED = true;
77-
(ptr::addr_of_mut!(INITIAL_HEAP).cast(), INITIAL_HEAP_SIZE, 0)
77+
((&raw mut INITIAL_HEAP).cast(), INITIAL_HEAP_SIZE, 0)
7878
}
7979
}
8080
}

0 commit comments

Comments
 (0)