Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,30 @@ public void shouldCallIndirectCrossModuleTypeIndex(
assertEquals(42, instance.export("call-other").apply()[0]);
}

@ParameterizedTest(name = "{0}")
@MethodSource("crossModuleMachineFactories")
public void shouldCallTableInitialiserInItsDefiningInstance(
String name,
Function<Instance, Machine> callerFactory,
Function<Instance, Machine> definerFactory) {
var store = new Store();

var definer =
Instance.builder(loadModule("compiled/table_init_owner-export.wat.wasm"))
.withMachineFactory(definerFactory)
.build();
store.register("test", definer);

var caller =
Instance.builder(loadModule("compiled/table_init_owner-import.wat.wasm"))
.withImportValues(store.toImportValues())
.withMachineFactory(callerFactory)
.build();

assertEquals(42, caller.export("call").apply(1)[0]);
assertEquals(definer, definer.table(0).instance(1));
}

@Test
public void tailcallReturnCallAot() {
var instance =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public final class NativeCodeSerializer {

private static final int MAGIC = 0x434C344A; // "CL4J"
private static final int VERSION = 3;
private static final int VERSION = 4;

private NativeCodeSerializer() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* 0 i64 funcTablePtr Pointer to function pointer table
* 8 i64 trampolinePtr Upcall stub for CALL_INDIRECT fallback
* 16 i32 trapCode Trap code written by native pre-checks
* 20 i32 typeId CALL_INDIRECT: expected type index
* 24 i32 tableIdx CALL_INDIRECT: table index
* 28 i32 elemIdx CALL_INDIRECT: table element index
* 20 i32 typeId Foreign CALL_INDIRECT: expected type index
* 24 i32 tableIdx Foreign CALL_INDIRECT: table index
* 28 i32 elemIdx Foreign CALL_INDIRECT: table element index
* 32 i32 argCount Number of call arguments
* 36 i32 memGrowDelta Page count delta for memory.grow
* 40 i64 argsPtr Pointer to separate args buffer
Expand All @@ -20,6 +20,8 @@
* 64 i64 memsetPtr Pointer to libc memset
* 72 i64 interruptFlag Non-zero = interrupt requested
* 80 i64 memoryPagesPtr Shared memory: pointer to its current page count (i32)
* 88 i64 ownerId Unique id of this instance, held by the entries it owns
* 96 i64 tableWritersPtr Pointer to an i32 per table, set once it keeps this instance
* 200 i64 globalsPtr Pointer to globals buffer
* 208 i64 memGrowPtr Upcall stub for memory.grow
* 216 i32 memoryPages Current memory page count
Expand Down Expand Up @@ -54,6 +56,8 @@ private CtxBuffer() {}
public static final int MEMSET_PTR = 64;
public static final int INTERRUPT_FLAG = 72;
public static final int MEMORY_PAGES_PTR = 80;
public static final int OWNER_ID = 88;
public static final int TABLE_WRITERS_PTR = 96;

public static final int GLOBALS_PTR = 200;
public static final int MEM_GROW_PTR = 208;
Expand Down Expand Up @@ -86,11 +90,14 @@ private CtxBuffer() {}
public static final int TABLE_SIZE_OFFSET = 0;
public static final int TABLE_MAX_OFFSET = 4;
public static final int TABLE_ENTRIES_OFFSET = 8;
public static final int TABLE_ENTRY_SIZE = 16;
public static final int TABLE_ENTRY_SIZE = 24;
public static final int ENTRY_TYPE_IDX_OFFSET = 0;
public static final int ENTRY_FUNC_ID_OFFSET = 4;
public static final int ENTRY_FUNC_PTR_OFFSET = 8;

// Owner id of the native instance defining the function, or 0 if there is none
public static final int ENTRY_OWNER_ID_OFFSET = 16;

public static int argOffset(int i) {
return 8 * i;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,18 @@ public void roundTripKeepsTheLayout() throws IOException {
}

@Test
public void aVersionOneFileIsRejected() throws IOException {
var out = new ByteArrayOutputStream();
var dos = new DataOutputStream(out);
dos.writeInt(0x434C344A);
dos.writeInt(1);
dos.writeInt(0);
public void anOlderVersionIsRejected() throws IOException {
// Version 3 code reads 16-byte table entries
for (int version = 1; version <= 3; version++) {
var out = new ByteArrayOutputStream();
var dos = new DataOutputStream(out);
dos.writeInt(0x434C344A);
dos.writeInt(version);
dos.writeInt(0);

var e = assertThrows(IOException.class, () -> deserialize(out.toByteArray()));
assertTrue(e.getMessage().contains("version"), e.getMessage());
var e = assertThrows(IOException.class, () -> deserialize(out.toByteArray()));
assertTrue(e.getMessage().contains("version"), e.getMessage());
}
}

@Test
Expand Down
Loading
Loading