summaryrefslogtreecommitdiff
path: root/src/wasm
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm')
-rw-r--r--src/wasm/wasm-binary.cpp16
-rw-r--r--src/wasm/wasm-s-parser.cpp7
-rw-r--r--src/wasm/wasm-validator.cpp2
3 files changed, 14 insertions, 11 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 1839c9cbd..fddb9c3a0 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -143,7 +143,7 @@ void WasmBinaryWriter::writeMemory() {
auto start = startSection(BinaryConsts::Section::Memory);
o << U32LEB(1); // Define 1 memory
writeResizableLimits(wasm->memory.initial, wasm->memory.max,
- wasm->memory.max != Memory::kMaxSize, wasm->memory.shared);
+ wasm->memory.hasMax(), wasm->memory.shared);
finishSection(start);
}
@@ -205,14 +205,14 @@ void WasmBinaryWriter::writeImports() {
writeImportHeader(&wasm->memory);
o << U32LEB(int32_t(ExternalKind::Memory));
writeResizableLimits(wasm->memory.initial, wasm->memory.max,
- wasm->memory.max != Memory::kMaxSize, wasm->memory.shared);
+ wasm->memory.hasMax(), wasm->memory.shared);
}
if (wasm->table.imported()) {
if (debug) std::cerr << "write one table" << std::endl;
writeImportHeader(&wasm->table);
o << U32LEB(int32_t(ExternalKind::Table));
o << S32LEB(BinaryConsts::EncodedType::AnyFunc);
- writeResizableLimits(wasm->table.initial, wasm->table.max, wasm->table.max != Table::kMaxSize, /*shared=*/false);
+ writeResizableLimits(wasm->table.initial, wasm->table.max, wasm->table.hasMax(), /*shared=*/false);
}
finishSection(start);
}
@@ -418,7 +418,7 @@ void WasmBinaryWriter::writeFunctionTableDeclaration() {
auto start = startSection(BinaryConsts::Section::Table);
o << U32LEB(1); // Declare 1 table.
o << S32LEB(BinaryConsts::EncodedType::AnyFunc);
- writeResizableLimits(wasm->table.initial, wasm->table.max, wasm->table.max != Table::kMaxSize, /*shared=*/false);
+ writeResizableLimits(wasm->table.initial, wasm->table.max, wasm->table.hasMax(), /*shared=*/false);
finishSection(start);
}
@@ -899,7 +899,7 @@ void WasmBinaryBuilder::readMemory() {
throwError("Memory cannot be both imported and defined");
}
wasm.memory.exists = true;
- getResizableLimits(wasm.memory.initial, wasm.memory.max, wasm.memory.shared, Memory::kMaxSize);
+ getResizableLimits(wasm.memory.initial, wasm.memory.max, wasm.memory.shared, Memory::kUnlimitedSize);
}
void WasmBinaryBuilder::readSignatures() {
@@ -987,7 +987,7 @@ void WasmBinaryBuilder::readImports() {
if (elementType != BinaryConsts::EncodedType::AnyFunc) throwError("Imported table type is not AnyFunc");
wasm.table.exists = true;
bool is_shared;
- getResizableLimits(wasm.table.initial, wasm.table.max, is_shared, Table::kMaxSize);
+ getResizableLimits(wasm.table.initial, wasm.table.max, is_shared, Table::kUnlimitedSize);
if (is_shared) throwError("Tables may not be shared");
break;
}
@@ -996,7 +996,7 @@ void WasmBinaryBuilder::readImports() {
wasm.memory.base = base;
wasm.memory.name = Name(std::to_string(i));
wasm.memory.exists = true;
- getResizableLimits(wasm.memory.initial, wasm.memory.max, wasm.memory.shared, Memory::kMaxSize);
+ getResizableLimits(wasm.memory.initial, wasm.memory.max, wasm.memory.shared, Memory::kUnlimitedSize);
break;
}
case ExternalKind::Global: {
@@ -1542,7 +1542,7 @@ void WasmBinaryBuilder::readFunctionTableDeclaration() {
auto elemType = getS32LEB();
if (elemType != BinaryConsts::EncodedType::AnyFunc) throwError("ElementType must be AnyFunc in MVP");
bool is_shared;
- getResizableLimits(wasm.table.initial, wasm.table.max, is_shared, Table::kMaxSize);
+ getResizableLimits(wasm.table.initial, wasm.table.max, is_shared, Table::kUnlimitedSize);
if (is_shared) throwError("Tables may not be shared");
}
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index 7085666bb..ee37f23f3 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -1510,7 +1510,10 @@ void SExpressionWasmBuilder::stringToBinary(const char* input, size_t size, std:
Index SExpressionWasmBuilder::parseMemoryLimits(Element& s, Index i) {
wasm.memory.initial = getCheckedAddress(s[i++], "excessive memory init");
- if (i == s.size()) return i;
+ if (i == s.size()) {
+ wasm.memory.max = Memory::kUnlimitedSize;
+ return i;
+ }
uint64_t max = atoll(s[i++]->c_str());
if (max > Memory::kMaxSize) throw ParseException("total memory must be <= 4GB");
wasm.memory.max = max;
@@ -1764,7 +1767,7 @@ void SExpressionWasmBuilder::parseImport(Element& s) {
if (j < inner.size() - 1) {
wasm.table.max = getCheckedAddress(inner[j++], "excessive table max size");
} else {
- wasm.table.max = Table::kMaxSize;
+ wasm.table.max = Table::kUnlimitedSize;
}
// ends with the table element type
} else if (kind == ExternalKind::Memory) {
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp
index 07c7b6aad..fbd31b920 100644
--- a/src/wasm/wasm-validator.cpp
+++ b/src/wasm/wasm-validator.cpp
@@ -969,7 +969,7 @@ static void validateGlobals(Module& module, ValidationInfo& info) {
static void validateMemory(Module& module, ValidationInfo& info) {
auto& curr = module.memory;
info.shouldBeFalse(curr.initial > curr.max, "memory", "memory max >= initial");
- info.shouldBeTrue(curr.max <= Memory::kMaxSize, "memory", "max memory must be <= 4GB");
+ info.shouldBeTrue(!curr.hasMax() || curr.max <= Memory::kMaxSize, "memory", "max memory must be <= 4GB, or unlimited");
info.shouldBeTrue(!curr.shared || curr.hasMax(), "memory", "shared memory must have max size");
if (curr.shared) info.shouldBeTrue(info.features & Feature::Atomics, "memory", "memory is shared, but atomics are disabled");
for (auto& segment : curr.segments) {