Skip to content

Commit 72872f6

Browse files
committed
Add support for memory/table.grow record and replay
1 parent 27f9a8b commit 72872f6

File tree

4 files changed

+93
-1
lines changed

4 files changed

+93
-1
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ rr_event! {
137137
// REQUIRED events
138138
/// Return from host function (core or component) to host
139139
HostFuncReturn(common_events::HostFuncReturnEvent),
140+
/// Return value of a memory.grow instruction
141+
MemoryGrow(common_events::MemoryGrowEvent),
142+
/// Return value of a table.grow instruction
143+
TableGrow(common_events::TableGrowEvent),
140144
// OPTIONAL events
141145
/// Call into host function from Wasm (core or component)
142146
HostFuncEntry(common_events::HostFuncEntryEvent),

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,20 @@ impl Validate<str> for TraceSignatureEvent {
6363
}
6464
}
6565

66+
/// A memory.grow return event
67+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
68+
pub struct MemoryGrowEvent {
69+
/// Result of the grow
70+
pub result: u32,
71+
}
72+
73+
/// A table.grow return event
74+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
75+
pub struct TableGrowEvent {
76+
/// Result of the grow
77+
pub result: u32,
78+
}
79+
6680
/// A diagnostic event for custom String messages.
6781
#[derive(Debug, Clone, Serialize, Deserialize)]
6882
pub struct CustomMessageEvent(pub String);

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::rr::FlatBytes;
44
#[cfg(feature = "rr")]
55
use crate::rr::{
66
RREvent, RRFuncArgVals, RRFuncArgValsConvertable, ReplayError, Replayer, ResultEvent, Validate,
7-
common_events::{HostFuncEntryEvent, HostFuncReturnEvent, WasmFuncReturnEvent},
7+
common_events::{HostFuncEntryEvent, HostFuncReturnEvent, MemoryGrowEvent, TableGrowEvent, WasmFuncReturnEvent},
88
core_events::{InstantiationEvent, WasmFuncEntryEvent},
99
};
1010
use crate::store::{InstanceId, StoreOpaque};
@@ -215,6 +215,40 @@ pub fn record_and_replay_validate_instantiation<T: 'static>(
215215
Ok(())
216216
}
217217

218+
/// Record and replay hook for memory.grow return value
219+
#[inline]
220+
pub fn record_and_replay_validate_memory_grow(
221+
result: u32,
222+
store: &mut StoreOpaque,
223+
) -> Result<()> {
224+
let _ = (result, &store);
225+
#[cfg(feature = "rr")]
226+
{
227+
store.record_event(|| MemoryGrowEvent { result })?;
228+
store.next_replay_event_validation::<MemoryGrowEvent, _, _>(|| MemoryGrowEvent {
229+
result,
230+
})?;
231+
}
232+
Ok(())
233+
}
234+
235+
/// Record and replay hook for table.grow return value
236+
#[inline]
237+
pub fn record_and_replay_validate_table_grow(
238+
result: u32,
239+
store: &mut StoreOpaque,
240+
) -> Result<()> {
241+
let _ = (result, &store);
242+
#[cfg(feature = "rr")]
243+
{
244+
store.record_event(|| TableGrowEvent { result })?;
245+
store.next_replay_event_validation::<TableGrowEvent, _, _>(|| TableGrowEvent {
246+
result,
247+
})?;
248+
}
249+
Ok(())
250+
}
251+
218252
/// Ensure that memories are not exported memories in Core wasm modules when
219253
/// recording is enabled.
220254
pub fn rr_validate_module_unexported_memory(module: &Module) -> Result<()> {

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#[cfg(feature = "stack-switching")]
5858
use super::stack_switching::VMContObj;
5959
use crate::prelude::*;
60+
use crate::rr;
6061
use crate::runtime::store::{InstanceId, StoreInstanceId, StoreOpaque};
6162
#[cfg(feature = "gc")]
6263
use crate::runtime::vm::VMGcRef;
@@ -229,6 +230,15 @@ fn memory_grow(
229230
.await?
230231
.map(|size_in_bytes| AllocationSize(size_in_bytes >> page_size_log2));
231232

233+
// Record/replay hook for memory.grow
234+
rr::core_hooks::record_and_replay_validate_memory_grow(
235+
match &result {
236+
Some(a) => a.0 as u32,
237+
None => u32::MAX,
238+
},
239+
store,
240+
)?;
241+
232242
Ok(result)
233243
})?
234244
}
@@ -295,6 +305,16 @@ unsafe fn table_grow_func_ref(
295305
})
296306
.await?
297307
.map(AllocationSize);
308+
309+
// Record/replay hook for table.grow
310+
rr::core_hooks::record_and_replay_validate_table_grow(
311+
match &result {
312+
Some(a) => a.0 as u32,
313+
None => u32::MAX,
314+
},
315+
store,
316+
)?;
317+
298318
Ok(result)
299319
})?
300320
}
@@ -328,6 +348,16 @@ fn table_grow_gc_ref(
328348
})
329349
.await?
330350
.map(AllocationSize);
351+
352+
// Record/replay hook for table.grow
353+
rr::core_hooks::record_and_replay_validate_table_grow(
354+
match &result {
355+
Some(a) => a.0 as u32,
356+
None => u32::MAX,
357+
},
358+
store,
359+
)?;
360+
331361
Ok(result)
332362
})?
333363
}
@@ -360,6 +390,16 @@ unsafe fn table_grow_cont_obj(
360390
})
361391
.await?
362392
.map(AllocationSize);
393+
394+
// Record/replay hook for table.grow
395+
rr::core_hooks::record_and_replay_validate_table_grow(
396+
match &result {
397+
Some(a) => a.0 as u32,
398+
None => u32::MAX,
399+
},
400+
store,
401+
)?;
402+
363403
Ok(result)
364404
})?
365405
}

0 commit comments

Comments
 (0)