Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit d5a2987

Browse files
committed
fix another provenance/lazy-init issue
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
1 parent ca7757e commit d5a2987

4 files changed

Lines changed: 21 additions & 16 deletions

File tree

crates/wasmtime/src/runtime/func.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,8 @@ impl Func {
10441044
params_and_returns: NonNull<[ValRaw]>,
10451045
) -> Result<()> {
10461046
invoke_wasm_and_catch_traps(store, |caller, vm| {
1047-
func_ref.as_ref().array_call(
1047+
VMFuncRef::array_call(
1048+
func_ref,
10481049
vm,
10491050
VMOpaqueContext::from_vmcontext(caller),
10501051
params_and_returns,

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,12 @@ where
235235
let storage = storage.cast::<ValRaw>();
236236
let storage = core::ptr::slice_from_raw_parts_mut(storage, storage_len);
237237
let storage = NonNull::new(storage).unwrap();
238-
func_ref
239-
.as_ref()
240-
.array_call(vm, VMOpaqueContext::from_vmcontext(caller), storage)
238+
VMFuncRef::array_call(
239+
*func_ref,
240+
vm,
241+
VMOpaqueContext::from_vmcontext(caller),
242+
storage,
243+
)
241244
});
242245

243246
let (_, storage) = captures;

crates/wasmtime/src/runtime/instance.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@ impl Instance {
341341
let caller_vmctx = instance.vmctx();
342342
unsafe {
343343
super::func::invoke_wasm_and_catch_traps(store, |_default_caller, vm| {
344-
f.func_ref.as_ref().array_call(
344+
VMFuncRef::array_call(
345+
f.func_ref,
345346
vm,
346347
VMOpaqueContext::from_vmcontext(caller_vmctx),
347348
NonNull::from(&mut []),

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -869,42 +869,42 @@ impl VMFuncRef {
869869
/// exhaustively documented.
870870
#[inline]
871871
pub unsafe fn array_call(
872-
&self,
872+
me: NonNull<Self>,
873873
pulley: Option<InterpreterRef<'_>>,
874874
caller: NonNull<VMOpaqueContext>,
875875
args_and_results: NonNull<[ValRaw]>,
876876
) -> bool {
877877
match pulley {
878-
Some(vm) => self.array_call_interpreted(vm, caller, args_and_results),
879-
None => self.array_call_native(caller, args_and_results),
878+
Some(vm) => Self::array_call_interpreted(me, vm, caller, args_and_results),
879+
None => Self::array_call_native(me, caller, args_and_results),
880880
}
881881
}
882882

883883
unsafe fn array_call_interpreted(
884-
&self,
884+
me: NonNull<Self>,
885885
vm: InterpreterRef<'_>,
886886
caller: NonNull<VMOpaqueContext>,
887887
args_and_results: NonNull<[ValRaw]>,
888888
) -> bool {
889889
// If `caller` is actually a `VMArrayCallHostFuncContext` then skip the
890890
// interpreter, even though it's available, as `array_call` will be
891891
// native code.
892-
if self.vmctx.as_non_null().as_ref().magic
892+
if me.as_ref().vmctx.as_non_null().as_ref().magic
893893
== wasmtime_environ::VM_ARRAY_CALL_HOST_FUNC_MAGIC
894894
{
895-
return self.array_call_native(caller, args_and_results);
895+
return Self::array_call_native(me, caller, args_and_results);
896896
}
897897
vm.call(
898-
self.array_call.as_non_null().cast(),
899-
self.vmctx.as_non_null(),
898+
me.as_ref().array_call.as_non_null().cast(),
899+
me.as_ref().vmctx.as_non_null(),
900900
caller,
901901
args_and_results,
902902
)
903903
}
904904

905905
#[inline]
906906
unsafe fn array_call_native(
907-
&self,
907+
me: NonNull<Self>,
908908
caller: NonNull<VMOpaqueContext>,
909909
args_and_results: NonNull<[ValRaw]>,
910910
) -> bool {
@@ -913,11 +913,11 @@ impl VMFuncRef {
913913
ptr: NonNull<VMArrayCallFunction>,
914914
}
915915
let native = GetNativePointer {
916-
ptr: self.array_call.as_non_null(),
916+
ptr: me.as_ref().array_call.as_non_null(),
917917
}
918918
.native;
919919
native(
920-
self.vmctx.as_non_null(),
920+
me.as_ref().vmctx.as_non_null(),
921921
caller,
922922
args_and_results.cast(),
923923
args_and_results.len(),

0 commit comments

Comments
 (0)