Skip to content

Commit 7f781b8

Browse files
authored
Update table.fill intrinsics to use defined indices (#11254)
Similar to previous refactorings which handles the imported/exported distinction in wasm instead of in host code this updates the `table.fill`-related libcall intrinsics to take a defined table index instead of a general table index, enabling using a currently-safer helper function.
1 parent 2b776b0 commit 7f781b8

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

crates/cranelift/src/func_environ.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,11 +1938,10 @@ impl FuncEnvironment<'_> {
19381938
self.builtin_functions.table_fill_func_ref(&mut pos.func)
19391939
};
19401940

1941-
let vmctx = self.vmctx_val(&mut pos);
1941+
let (table_vmctx, table_index) = self.table_vmctx_and_defined_index(&mut pos, table_index);
19421942

1943-
let table_index_arg = pos.ins().iconst(I32, table_index.as_u32() as i64);
19441943
pos.ins()
1945-
.call(libcall, &[vmctx, table_index_arg, dst, val, len]);
1944+
.call(libcall, &[table_vmctx, table_index, dst, val, len]);
19461945

19471946
Ok(())
19481947
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ unsafe fn table_fill_func_ref(
305305
val: *mut u8,
306306
len: u64,
307307
) -> Result<()> {
308-
let table_index = TableIndex::from_u32(table_index);
309-
let table = &mut *instance.get_table(table_index);
308+
let table_index = DefinedTableIndex::from_u32(table_index);
309+
let table = instance.get_defined_table(table_index);
310310
match table.element_type() {
311311
TableElementType::Func => {
312312
let val = NonNull::new(val.cast::<VMFuncRef>());
@@ -327,8 +327,8 @@ unsafe fn table_fill_gc_ref(
327327
val: u32,
328328
len: u64,
329329
) -> Result<()> {
330-
let table_index = TableIndex::from_u32(table_index);
331-
let table = &mut *instance.get_table(table_index);
330+
let table_index = DefinedTableIndex::from_u32(table_index);
331+
let table = instance.get_defined_table(table_index);
332332
match table.element_type() {
333333
TableElementType::Func => unreachable!(),
334334
TableElementType::GcRef => {
@@ -353,8 +353,8 @@ unsafe fn table_fill_cont_obj(
353353
value_revision: u64,
354354
len: u64,
355355
) -> Result<()> {
356-
let table_index = TableIndex::from_u32(table_index);
357-
let table = &mut *instance.get_table(table_index);
356+
let table_index = DefinedTableIndex::from_u32(table_index);
357+
let table = instance.get_defined_table(table_index);
358358
match table.element_type() {
359359
TableElementType::Cont => {
360360
let contobj = VMContObj::from_raw_parts(value_contref, value_revision);

0 commit comments

Comments
 (0)