summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Gohman <sunfish@mozilla.com>2016-05-13 11:20:28 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-05-13 11:20:28 -0700
commit348565b6a9a823c0fee30c96d8d783810d540a78 (patch)
treeabb41a1a8220d5631003fa3b0b72a1060f09bd62
parent4a720eca42c463d53db1c81f9957a3e5d9011836 (diff)
downloadbinaryen-348565b6a9a823c0fee30c96d8d783810d540a78.tar.gz
binaryen-348565b6a9a823c0fee30c96d8d783810d540a78.tar.bz2
binaryen-348565b6a9a823c0fee30c96d8d783810d540a78.zip
Fix the maximum memory size to be valid. (#492)
-rw-r--r--src/passes/Print.cpp2
-rw-r--r--src/wasm-js.cpp4
-rw-r--r--src/wasm.h3
3 files changed, 5 insertions, 4 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 85ecd9724..aa0657727 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -491,7 +491,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
incIndent();
doIndent(o, indent);
printOpening(o, "memory") << " " << curr->memory.initial;
- if (curr->memory.max && curr->memory.max != (uint32_t)-1) o << " " << curr->memory.max;
+ if (curr->memory.max && curr->memory.max != Memory::kMaxSize) o << " " << curr->memory.max;
for (auto segment : curr->memory.segments) {
o << maybeNewLine;
o << (minify ? "" : " ") << "(segment " << segment.offset << " \"";
diff --git a/src/wasm-js.cpp b/src/wasm-js.cpp
index 6626f46e1..80eaaa720 100644
--- a/src/wasm-js.cpp
+++ b/src/wasm-js.cpp
@@ -76,7 +76,7 @@ extern "C" void EMSCRIPTEN_KEEPALIVE load_asm2wasm(char *input) {
exit(EXIT_FAILURE);
}
module->memory.initial = providedMemory / Memory::kPageSize;
- module->memory.max = pre.memoryGrowth ? -1 : module->memory.initial;
+ module->memory.max = pre.memoryGrowth ? Memory::kMaxSize : module->memory.initial;
if (wasmJSDebug) std::cerr << "wasming...\n";
asm2wasm = new Asm2WasmBuilder(*module, pre.memoryGrowth, debug, false /* TODO: support imprecise? */);
@@ -110,7 +110,7 @@ void finalizeModule() {
exit(EXIT_FAILURE);
}
module->memory.initial = providedMemory / Memory::kPageSize;
- module->memory.max = module->checkExport(GROW_WASM_MEMORY) ? -1 : module->memory.initial;
+ module->memory.max = module->checkExport(GROW_WASM_MEMORY) ? Memory::kMaxSize : module->memory.initial;
// global mapping is done in js in post.js
}
diff --git a/src/wasm.h b/src/wasm.h
index 327be9c7e..56e74f372 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -1281,6 +1281,7 @@ public:
class Memory {
public:
static const Address::address_t kPageSize = 64 * 1024;
+ static const Address::address_t kMaxSize = ~Address::address_t(0) / kPageSize;
static const Address::address_t kPageMask = ~(kPageSize - 1);
struct Segment {
Address offset;
@@ -1299,7 +1300,7 @@ public:
std::vector<Segment> segments;
Name exportName;
- Memory() : initial(0), max(-1U) {}
+ Memory() : initial(0), max(kMaxSize) {}
};
class Module {