diff options
author | Derek Schuff <dschuff@chromium.org> | 2016-03-04 17:09:47 -0800 |
---|---|---|
committer | Derek Schuff <dschuff@chromium.org> | 2016-03-09 13:04:18 -0800 |
commit | 1b45938aadd6e03e9210d88436be9c393623fb42 (patch) | |
tree | 24028248c7b9999a8d46bbab913fbe460d76bc46 /src/wasm-js.cpp | |
parent | e9d98deed872a72a826f78c8525464c446c6f21b (diff) | |
download | binaryen-1b45938aadd6e03e9210d88436be9c393623fb42.tar.gz binaryen-1b45938aadd6e03e9210d88436be9c393623fb42.tar.bz2 binaryen-1b45938aadd6e03e9210d88436be9c393623fb42.zip |
Make initial and max memory sizes be in pages instead of bytes
The AST and everything that uses it treats the values as
pages. Javascript continues to use bytes.
This matches v8 and sexpr-wasm, and the consensus from live discussion
and PR209 in the spec.
Diffstat (limited to 'src/wasm-js.cpp')
-rw-r--r-- | src/wasm-js.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/wasm-js.cpp b/src/wasm-js.cpp index 7b9afab30..000092da8 100644 --- a/src/wasm-js.cpp +++ b/src/wasm-js.cpp @@ -67,9 +67,14 @@ extern "C" void EMSCRIPTEN_KEEPALIVE load_asm2wasm(char *input) { Ref asmjs = builder.parseToplevel(input); module = new AllocatingModule(); - module->memory.initial = EM_ASM_INT_V({ + uint32_t providedMemory = EM_ASM_INT_V({ return Module['providedTotalMemory']; // we receive the size of memory from emscripten }); + if (providedMemory & ~Memory::kPageMask) { + std::cerr << "Error: provided memory is not a multiple of the 64k wasm page size\n"; + exit(EXIT_FAILURE); + } + module->memory.initial = providedMemory / Memory::kPageSize; module->memory.max = pre.memoryGrowth ? -1 : module->memory.initial; if (wasmJSDebug) std::cerr << "wasming...\n"; @@ -114,9 +119,14 @@ extern "C" void EMSCRIPTEN_KEEPALIVE load_s_expr2wasm(char *input, char *mappedG abort(); }); - module->memory.initial = EM_ASM_INT_V({ + uint32_t providedMemory = EM_ASM_INT_V({ return Module['providedTotalMemory']; // we receive the size of memory from emscripten }); + if (providedMemory & ~Memory::kPageMask) { + std::cerr << "Error: provided memory is not a multiple of the 64k wasm page size\n"; + exit(EXIT_FAILURE); + } + module->memory.initial = providedMemory / Memory::kPageSize; module->memory.max = (module->exportsMap.find(GROW_WASM_MEMORY) != module->exportsMap.end()) ? -1 : module->memory.initial; // global mapping is done in js in post.js @@ -151,7 +161,7 @@ extern "C" void EMSCRIPTEN_KEEPALIVE instantiate() { // create a new buffer here, just like native wasm support would. EM_ASM_({ Module['outside']['newBuffer'] = new ArrayBuffer($0); - }, wasm.memory.initial); + }, wasm.memory.initial * Memory::kPageSize); for (auto segment : wasm.memory.segments) { EM_ASM_({ var source = Module['HEAP8'].subarray($1, $1 + $2); |