Skip to content

Commit 7c41b1c

Browse files
committed
Make all usize serialized types into u64
1 parent 1507a01 commit 7c41b1c

6 files changed

Lines changed: 43 additions & 20 deletions

File tree

crates/wasmtime/src/runtime/component/func/options.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,15 @@ impl<'a, T: 'static> LowerContext<'a, T> {
245245
) -> Result<usize> {
246246
#[cfg(feature = "rr")]
247247
self.store.0.record_event(|| ReallocEntryEvent {
248-
old_addr: old,
249-
old_size,
248+
old_addr: old as u64,
249+
old_size: old_size as u64,
250250
old_align,
251-
new_size,
251+
new_size: new_size as u64,
252252
})?;
253253
let result = self.realloc_inner(old, old_size, old_align, new_size);
254254
#[cfg(feature = "rr")]
255255
self.store.0.record_event_validation(|| {
256-
ReallocReturnEvent(ResultEvent::from_anyhow_result(&result))
256+
ReallocReturnEvent(ResultEvent::from_anyhow_result_usize(&result))
257257
})?;
258258
result
259259
}
@@ -473,8 +473,12 @@ impl<'a, T: 'static> LowerContext<'a, T> {
473473
complete = true;
474474
}
475475
RREvent::ComponentReallocEntry(e) => {
476-
let result =
477-
self.realloc_inner(e.old_addr, e.old_size, e.old_align, e.new_size);
476+
let result = self.realloc_inner(
477+
e.old_addr as usize,
478+
e.old_size as usize,
479+
e.old_align,
480+
e.new_size as usize,
481+
);
478482
if run_validate {
479483
realloc_stack.push(result);
480484
}
@@ -495,9 +499,10 @@ impl<'a, T: 'static> LowerContext<'a, T> {
495499
lowering_error = e.0.ret().map_err(Into::into).err();
496500
}
497501
RREvent::ComponentMemorySliceWrite(e) => {
502+
let offset = e.offset as usize;
498503
// The bounds check is performed here is required here (in the absence of
499504
// trace validation) to protect against malicious out-of-bounds slice writes
500-
self.as_slice_mut()[e.offset..e.offset + e.bytes.len()]
505+
self.as_slice_mut()[offset..offset + e.bytes.len()]
501506
.copy_from_slice(e.bytes.as_slice());
502507
}
503508
// Optional events
@@ -510,7 +515,9 @@ impl<'a, T: 'static> LowerContext<'a, T> {
510515
// Unwrapping should never occur on valid executions since *Entry should be before *Return in trace
511516
RREvent::ComponentReallocReturn(e) => {
512517
if run_validate {
513-
lowering_error = e.0.validate(&realloc_stack.pop().unwrap()).err()
518+
lowering_error =
519+
e.0.validate(&realloc_stack.pop().unwrap().map(|r| r as u64))
520+
.err()
514521
}
515522
}
516523
RREvent::ComponentLowerFlatEntry(_) => {

crates/wasmtime/src/runtime/rr/backend/crimp/events.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,19 @@ where
117117
}
118118
}
119119

120+
impl<E> ResultEvent<u64, E>
121+
where
122+
E: EventError,
123+
{
124+
pub fn from_anyhow_result_usize(ret: &Result<usize>) -> Self {
125+
Self(
126+
ret.as_ref()
127+
.map(|t| *t as u64)
128+
.map_err(|e| E::new(e.to_string())),
129+
)
130+
}
131+
}
132+
120133
impl<T, E> Validate<Result<T>> for ResultEvent<T, E>
121134
where
122135
T: fmt::Debug + PartialEq,

crates/wasmtime/src/runtime/rr/backend/crimp/events/component_events.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ pub struct WasmFuncEntryEvent {
5050
/// A reallocation call event in the Wasm Component Model canonical ABI.
5151
#[derive(Debug, Clone, Serialize, Deserialize)]
5252
pub struct ReallocEntryEvent {
53-
pub old_addr: usize,
54-
pub old_size: usize,
53+
pub old_addr: u64,
54+
pub old_size: u64,
5555
pub old_align: u32,
56-
pub new_size: usize,
56+
pub new_size: u64,
5757
}
5858

5959
/// Entry to a type lowering invocation to flat destination.
@@ -66,7 +66,7 @@ pub struct LowerFlatEntryEvent {
6666
#[derive(Debug, Clone, Serialize, Deserialize)]
6767
pub struct LowerMemoryEntryEvent {
6868
pub ty: InterfaceType,
69-
pub offset: usize,
69+
pub offset: u64,
7070
}
7171

7272
/// A write to a mutable slice of Wasm linear memory by the host. This is the
@@ -78,7 +78,7 @@ pub struct LowerMemoryEntryEvent {
7878
/// larger granularity operations in the future at either the recording or the replay level.
7979
#[derive(Debug, Clone, Serialize, Deserialize)]
8080
pub struct MemorySliceWriteEvent {
81-
pub offset: usize,
81+
pub offset: u64,
8282
pub bytes: Vec<u8>,
8383
}
8484

@@ -92,7 +92,7 @@ event_error_types! {
9292
/// Return from a reallocation call in the Component Model canonical ABI, providing
9393
/// the address of allocation if successful.
9494
#[derive(Debug, Clone, Serialize, Deserialize)]
95-
pub struct ReallocReturnEvent(pub ResultEvent<usize, ReallocError>);
95+
pub struct ReallocReturnEvent(pub ResultEvent<u64, ReallocError>);
9696

9797
/// Return from type lowering to flat destination.
9898
#[derive(Debug, Clone, Serialize, Deserialize)]

crates/wasmtime/src/runtime/rr/hooks/component_hooks.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ where
181181
#[cfg(feature = "rr")]
182182
cx.store
183183
.0
184-
.record_event_validation(|| LowerMemoryEntryEvent { ty, offset })?;
184+
.record_event_validation(|| LowerMemoryEntryEvent {
185+
ty,
186+
offset: offset as u64,
187+
})?;
185188
let store_result = lower_store(cx, ty, offset);
186189
#[cfg(feature = "rr")]
187190
cx.store
@@ -283,7 +286,7 @@ impl Drop for DynamicMemorySlice<'_> {
283286
// We don't need to record empty slices
284287
if !self.bytes.is_empty() {
285288
buf.record_event(|| MemorySliceWriteEvent {
286-
offset: self.offset,
289+
offset: self.offset as u64,
287290
bytes: self.bytes.to_vec(),
288291
})
289292
.unwrap();
@@ -346,7 +349,7 @@ impl<'a, const N: usize> Drop for FixedMemorySlice<'a, N> {
346349
// We don't need to record empty slices
347350
if !self.bytes.is_empty() {
348351
buf.record_event(|| MemorySliceWriteEvent {
349-
offset: self.offset,
352+
offset: self.offset as u64,
350353
bytes: self.bytes.to_vec(),
351354
})
352355
.unwrap();

crates/wasmtime/src/runtime/vm/stack_switching/stack/unix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl VMContinuationStack {
258258

259259
let to_store = [
260260
// Data near top of stack:
261-
(0x08, wasmtime_continuation_start as usize),
261+
(0x08, wasmtime_continuation_start as *const () as usize),
262262
(0x10, tos.sub(0x10).addr()),
263263
(0x18, tos.sub(0x40 + args_data_size).addr()),
264264
(0x20, usize::try_from(args_capacity).unwrap()),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl TrapHandler {
4949
// crash while handling the signal, and fall through to the
5050
// Breakpad handler by testing handlingSegFault.
5151
handler.sa_flags = libc::SA_SIGINFO | libc::SA_NODEFER | libc::SA_ONSTACK;
52-
handler.sa_sigaction = trap_handler as usize;
52+
handler.sa_sigaction = trap_handler as *const () as usize;
5353
unsafe {
5454
libc::sigemptyset(&mut handler.sa_mask);
5555
if libc::sigaction(signal, &handler, slot) != 0 {
@@ -111,7 +111,7 @@ impl Drop for TrapHandler {
111111
// signal handler state and don't know how to remove ourselves
112112
// from the signal handling state. Inform the user of this and
113113
// abort the process.
114-
if prev.sa_sigaction != trap_handler as usize {
114+
if prev.sa_sigaction != trap_handler as *const () as usize {
115115
eprintln!(
116116
"
117117
Wasmtime's signal handler was not the last signal handler to be installed

0 commit comments

Comments
 (0)