summaryrefslogtreecommitdiff
path: root/src/wasm-interpreter.h
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-11-06 16:26:09 -0800
committerGitHub <noreply@github.com>2024-11-06 16:26:09 -0800
commitde680182bcd1d64d597538cfa4ad6857ce298bc3 (patch)
treea0a77f23bc01c47ec3d739f9ab07b2b41a884eb9 /src/wasm-interpreter.h
parentb57a6d74cb9edc88b2f7d203270f98467c0961af (diff)
downloadbinaryen-de680182bcd1d64d597538cfa4ad6857ce298bc3.tar.gz
binaryen-de680182bcd1d64d597538cfa4ad6857ce298bc3.tar.bz2
binaryen-de680182bcd1d64d597538cfa4ad6857ce298bc3.zip
[wasm64] Fix 64-bit memory/table operations in interpreter (#7058)
A bunch of places assumed a 32-bit index.
Diffstat (limited to 'src/wasm-interpreter.h')
-rw-r--r--src/wasm-interpreter.h23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index 5f20819a1..7f1cf9054 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -2957,18 +2957,22 @@ private:
void initializeMemoryContents() {
initializeMemorySizes();
- Const zero;
- zero.value = Literal(uint32_t(0));
- zero.finalize();
-
// apply active memory segments
for (size_t i = 0, e = wasm.dataSegments.size(); i < e; ++i) {
auto& segment = wasm.dataSegments[i];
if (segment->isPassive) {
continue;
}
+
+ auto* memory = wasm.getMemory(segment->memory);
+
+ Const zero;
+ zero.value = Literal::makeFromInt32(0, memory->indexType);
+ zero.finalize();
+
Const size;
- size.value = Literal(uint32_t(segment->data.size()));
+ size.value =
+ Literal::makeFromInt32(segment->data.size(), memory->indexType);
size.finalize();
MemoryInit init;
@@ -3136,13 +3140,14 @@ public:
return target;
}
- Index index = target.getSingleValue().geti32();
+ auto index = target.getSingleValue().getUnsigned();
auto info = getTableInstanceInfo(curr->table);
if (curr->isReturn) {
// Return calls are represented by their arguments followed by a reference
// to the function to be called.
+ // TODO: switch tableLoad index from Index to Address, to support table64.
auto funcref = info.interface()->tableLoad(info.name, index);
if (!Type::isSubType(funcref.type, Type(curr->heapType, NonNullable))) {
trap("cast failure in call_indirect");
@@ -3673,7 +3678,7 @@ public:
return flow;
}
NOTE_EVAL1(flow);
- Address src(uint32_t(flow.getSingleValue().geti32()));
+ Address src(flow.getSingleValue().getUnsigned());
auto info = getMemoryInstanceInfo(curr->memory);
auto loadLane = [&](Address addr) {
switch (curr->op) {
@@ -3878,8 +3883,8 @@ public:
auto* segment = wasm.getDataSegment(curr->segment);
Address destVal(dest.getSingleValue().getUnsigned());
- Address offsetVal(uint32_t(offset.getSingleValue().geti32()));
- Address sizeVal(uint32_t(size.getSingleValue().geti32()));
+ Address offsetVal(offset.getSingleValue().getUnsigned());
+ Address sizeVal(size.getSingleValue().getUnsigned());
if (offsetVal + sizeVal > 0 && droppedDataSegments.count(curr->segment)) {
trap("out of bounds segment access in memory.init");