Skip to content

Commit 5d85d48

Browse files
committed
Added post return event to rr
1 parent 4b32230 commit 5d85d48

File tree

5 files changed

+77
-2
lines changed

5 files changed

+77
-2
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,12 @@ impl Func {
704704
/// This only works with functions defined within a synchronous store.
705705
#[inline]
706706
pub fn post_return(&self, mut store: impl AsContextMut) -> Result<()> {
707-
let store = store.as_context_mut();
707+
let mut store = store.as_context_mut();
708+
component_hooks::record_wasm_func_post_return(
709+
self.instance.id().instance(),
710+
self.index,
711+
&mut store,
712+
)?;
708713
assert!(
709714
!store.0.async_support(),
710715
"must use `post_return_async` when async support is enabled on the config"

crates/wasmtime/src/runtime/rr/core.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ rr_event! {
156156
ComponentMemorySliceWrite(__component_events::MemorySliceWriteEvent),
157157
/// Return from a component builtin
158158
ComponentBuiltinReturn(__component_events::BuiltinReturnEvent),
159+
/// Call to `post_return` (after the function call)
160+
ComponentPostReturn(__component_events::PostReturnEvent),
159161

160162
// OPTIONAL events for replay validation (Component)
161163

crates/wasmtime/src/runtime/rr/core/events/component_events.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ pub struct InstantiationEvent {
2626
pub instance: ComponentInstanceId,
2727
}
2828

29+
/// A call to `post_return` (after the function call)
30+
#[derive(Debug, Clone, Serialize, Deserialize)]
31+
pub struct PostReturnEvent {
32+
/// Instance ID for the component instance
33+
pub instance: ComponentInstanceId,
34+
/// Export index for the function on which post_return is invoked
35+
pub func_idx: ExportIndex,
36+
}
37+
2938
/// A call event from Host into a Wasm component function
3039
#[derive(Debug, Clone, Serialize, Deserialize)]
3140
pub struct WasmFuncEntryEvent {

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::rr::common_events::{HostFuncEntryEvent, WasmFuncReturnEvent};
1111
#[cfg(feature = "rr-component")]
1212
use crate::rr::component_events::{
1313
LowerFlatEntryEvent, LowerFlatReturnEvent, LowerMemoryEntryEvent, LowerMemoryReturnEvent,
14-
WasmFuncBeginEvent, WasmFuncEntryEvent,
14+
PostReturnEvent, WasmFuncBeginEvent, WasmFuncEntryEvent,
1515
};
1616
#[cfg(feature = "rr-component")]
1717
use crate::rr::{RRFuncArgVals, ResultEvent, common_events::HostFuncReturnEvent};
@@ -47,6 +47,21 @@ pub fn record_wasm_func_begin(
4747
Ok(())
4848
}
4949

50+
/// Record hook for wasm component function post_return call
51+
#[inline]
52+
pub fn record_wasm_func_post_return<T>(
53+
instance: ComponentInstanceId,
54+
func_idx: ExportIndex,
55+
store: &mut StoreContextMut<'_, T>,
56+
) -> Result<()> {
57+
#[cfg(feature = "rr-component")]
58+
store
59+
.0
60+
.record_event(|| PostReturnEvent { instance, func_idx })?;
61+
let _ = (instance, func_idx, store);
62+
Ok(())
63+
}
64+
5065
/// Record hook wrapping a wasm component export function invocation and replay
5166
/// validation of return value
5267
#[inline]

crates/wasmtime/src/runtime/rr/replay_driver.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,28 @@ impl<T: 'static> ReplayInstance<T> {
277277
);
278278
}
279279
}
280+
RREvent::ComponentPostReturn(event) => {
281+
#[cfg(feature = "rr-component")]
282+
{
283+
// Grab the correct component instance
284+
let key = event.instance;
285+
let instance = self
286+
.component_instances
287+
.get_mut(&key)
288+
.ok_or(ReplayError::MissingComponentInstance(key.as_u32()))?;
289+
290+
let func = component::Func::from_lifted_func(*instance, event.func_idx);
291+
let mut store = self.store.as_context_mut();
292+
293+
func.post_return(&mut store)?;
294+
}
295+
#[cfg(not(feature = "rr-component"))]
296+
{
297+
bail!(
298+
"Cannot parse ComponentPostReturn replay event without rr-component feature enabled"
299+
);
300+
}
301+
}
280302
RREvent::CoreWasmInstantiation(event) => {
281303
// Find matching module from environment to instantiate
282304
let module = self
@@ -442,6 +464,28 @@ impl<T: 'static> ReplayInstance<T> {
442464
);
443465
}
444466
}
467+
RREvent::ComponentPostReturn(event) => {
468+
#[cfg(feature = "rr-component")]
469+
{
470+
// Grab the correct component instance
471+
let key = event.instance;
472+
let instance = self
473+
.component_instances
474+
.get_mut(&key)
475+
.ok_or(ReplayError::MissingComponentInstance(key.as_u32()))?;
476+
477+
let func = component::Func::from_lifted_func(*instance, event.func_idx);
478+
let mut store = self.store.as_context_mut();
479+
480+
func.post_return_async(&mut store).await?;
481+
}
482+
#[cfg(not(feature = "rr-component"))]
483+
{
484+
bail!(
485+
"Cannot parse ComponentPostReturn replay event without rr-component feature enabled"
486+
);
487+
}
488+
}
445489
RREvent::CoreWasmInstantiation(event) => {
446490
// Find matching module from environment to instantiate
447491
let module = self

0 commit comments

Comments
 (0)