Skip to content

Commit 43d130f

Browse files
Fix segfault in v8 (#4986)
# Description of Changes This was originally introduced in #4302; essentially, we stopped unconditionally setting `HookFunctions.recv` to undefined and started setting it to the value stored in `ctx.get_embedder_data(RECV_SLOT_INDEX)`. However, in the code path for v1 js modules, we never actually set that embedder data slot, and so recv was a garbage value. # Expected complexity level and risk 1: concentrated fix # Testing - [x] Repro no longer segfaults. Co-authored-by: joshua-spacetime <josh@clockworklabs.io>
1 parent ae523db commit 43d130f

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

crates/core/src/host/v8/syscall/hooks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl ModuleHookKey {
9393
}
9494

9595
/// Context embedder slot holding the receiver (`this`) value used for hook calls.
96-
const RECV_SLOT_INDEX: i32 = ModuleHookKey::SenderErrorClass as i32 + 1;
96+
pub(super) const RECV_SLOT_INDEX: i32 = ModuleHookKey::SenderErrorClass as i32 + 1;
9797

9898
/// Holds the `AbiVersion` used by the module
9999
/// and the module hooks registered by the module

crates/core/src/host/v8/syscall/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ pub(super) fn get_hooks<'scope>(
125125
scope: &mut PinScope<'scope, '_>,
126126
exports_obj: Local<'_, v8::Object>,
127127
) -> Result<Option<HookFunctions<'scope>>, ErrorOrException<ExceptionThrown>> {
128+
// We only set RECV_SLOT_INDEX in set_registered_hooks, which is only called in
129+
// the v2 code path. Set it to undefined ahead of time so it's not a garbage value.
130+
scope
131+
.get_current_context()
132+
.set_embedder_data(hooks::RECV_SLOT_INDEX, v8::undefined(scope).into());
128133
if let Some(hooks) = get_registered_hooks(scope) {
129134
return Ok(Some(hooks));
130135
}

0 commit comments

Comments
 (0)