Skip to content

Commit 54a9543

Browse files
committed
review: plumb through a TypeFuncIndex for checking the indirectly-retrieved spawn function
1 parent cb2e84f commit 54a9543

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

crates/cranelift/src/compiler/component.rs

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

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

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

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

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
}

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| {

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)