Skip to content

Commit 40e6322

Browse files
committed
review: plumb through a TypeFuncIndex for checking the indirectly-retrieved spawn function
1 parent abf3a84 commit 40e6322

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

Diff for: crates/cranelift/src/compiler/component.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,8 @@ impl<'a> TrampolineCompiler<'a> {
280280
rets[0] = me.raise_if_negative_one_and_truncate(rets[0]);
281281
})
282282
}
283-
Trampoline::ThreadSpawnIndirect { ty: _, table } => {
284-
// TODO: eventually pass through the `ty` argument to check the
285-
// table's funcref signature.
286-
self.translate_thread_spawn_indirect(*table)
283+
Trampoline::ThreadSpawnIndirect { ty, table } => {
284+
self.translate_thread_spawn_indirect(*ty, *table)
287285
}
288286
}
289287
}
@@ -1336,12 +1334,22 @@ impl<'a> TrampolineCompiler<'a> {
13361334
);
13371335
}
13381336

1339-
fn translate_thread_spawn_indirect(&mut self, table: RuntimeTableIndex) {
1337+
fn translate_thread_spawn_indirect(
1338+
&mut self,
1339+
func_ty: TypeFuncIndex,
1340+
table: RuntimeTableIndex,
1341+
) {
13401342
let args = self.builder.func.dfg.block_params(self.block0).to_vec();
13411343
let vmctx = args[0];
13421344
let element = args[1];
13431345
let context = args[2];
13441346

1347+
// func_ty: u32
1348+
let func_ty = self
1349+
.builder
1350+
.ins()
1351+
.iconst(ir::types::I32, i64::from(func_ty.as_u32()));
1352+
13451353
// table: u32
13461354
let table = self
13471355
.builder
@@ -1351,7 +1359,7 @@ impl<'a> TrampolineCompiler<'a> {
13511359
self.translate_intrinsic_libcall(
13521360
vmctx,
13531361
host::thread_spawn_indirect,
1354-
&[vmctx, table, element, context],
1362+
&[vmctx, func_ty, table, element, context],
13551363
TrapSentinel::Falsy,
13561364
);
13571365
}

Diff for: crates/environ/src/component.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ macro_rules! foreach_builtin_component_function {
155155
error_context_transfer(vmctx: vmctx, src_idx: u32, src_table: u32, dst_table: u32) -> u64;
156156

157157
#[cfg(feature = "threads")]
158-
thread_spawn_indirect(vmctx: vmctx, table: u32, element: u32, context: u32 ) -> u64;
158+
thread_spawn_indirect(vmctx: vmctx, func_ty: u32, table: u32, element: u32, context: u32 ) -> u64;
159159

160160
trap(vmctx: vmctx, code: u8);
161161

Diff for: crates/environ/src/component/info.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -997,9 +997,10 @@ pub enum Trampoline {
997997
/// The `thread.spawn_indirect` intrinsic to spawn a thread from a function
998998
/// of type `ty` stored in a `table`.
999999
ThreadSpawnIndirect {
1000-
/// TODO
1000+
/// The type of the function that is being spawned.
10011001
ty: TypeFuncIndex,
1002-
/// TODO
1002+
/// The table from which to indirectly retrieve retrieve the spawn
1003+
/// function.
10031004
table: RuntimeTableIndex,
10041005
},
10051006
}

Diff for: crates/wasmtime/src/runtime/vm/component.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,8 @@ impl ComponentInstance {
749749
#[cfg(feature = "threads")]
750750
pub(crate) fn thread_spawn_indirect(
751751
&mut self,
752-
table: u32,
752+
_func_ty: TypeFuncIndex,
753+
table: RuntimeTableIndex,
753754
element: u32,
754755
_context: u32,
755756
) -> Result<u32> {
@@ -760,7 +761,7 @@ impl ComponentInstance {
760761
// Retrieve the table referenced by the canonical builtin (i.e.,
761762
// `table`). By validation this is guaranteed to be a `shared funcref`
762763
// table.
763-
let VMTable { vmctx, from } = self.runtime_table(RuntimeTableIndex::from_u32(table));
764+
let VMTable { vmctx, from } = self.runtime_table(table);
764765
let element = u64::from(element);
765766
let table = unsafe {
766767
Instance::from_vmctx(vmctx.as_non_null(), |handle| {

Diff for: crates/wasmtime/src/runtime/vm/component/libcalls.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1271,11 +1271,16 @@ unsafe fn error_context_drop(
12711271
#[cfg(feature = "threads")]
12721272
unsafe fn thread_spawn_indirect(
12731273
vmctx: NonNull<VMComponentContext>,
1274+
func_ty: u32,
12741275
table: u32,
12751276
element: u32,
12761277
context: u32,
12771278
) -> Result<u32> {
1279+
use wasmtime_environ::component::{RuntimeTableIndex, TypeFuncIndex};
1280+
1281+
let func_ty = TypeFuncIndex::from_bits(func_ty);
1282+
let table = RuntimeTableIndex::from_u32(table);
12781283
ComponentInstance::from_vmctx(vmctx, |instance| {
1279-
instance.thread_spawn_indirect(table, element, context)
1284+
instance.thread_spawn_indirect(func_ty, table, element, context)
12801285
})
12811286
}

0 commit comments

Comments
 (0)