From 859686c79388b5c34022a8bf8d7794480c9ad2bd Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 11 Oct 2016 16:21:06 -0700 Subject: remove memory maximum in asm2wasm when memory growth is on --- src/asm2wasm.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/asm2wasm.h b/src/asm2wasm.h index 9b503c84d..9bf677e6f 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -981,6 +981,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) { // apply memory growth, if relevant if (memoryGrowth) { emscripten::generateMemoryGrowthFunction(wasm); + wasm.memory.max = Memory::kMaxSize; } #if 0 -- cgit v1.2.3 From 0f42a9d1d43dcffc76cd816725f278ed8cf28702 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 11 Oct 2016 17:16:43 -0700 Subject: handle memory growth with native wasm support: the result of grow_memory tells us if it succeeded, and then the new buffer can be found on the Memory object --- src/js/wasm.js-post.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/js/wasm.js-post.js b/src/js/wasm.js-post.js index f093ff64d..a4bc35f97 100644 --- a/src/js/wasm.js-post.js +++ b/src/js/wasm.js-post.js @@ -269,8 +269,18 @@ function integrateWasmJS(Module) { Module['reallocBuffer'] = function(size) { size = Math.ceil(size / wasmPageSize) * wasmPageSize; // round up to wasm page size var old = Module['buffer']; - exports['__growWasmMemory'](size / wasmPageSize); // tiny wasm method that just does grow_memory - return Module['buffer'] !== old ? Module['buffer'] : null; // if it was reallocated, it changed + var result = exports['__growWasmMemory'](size / wasmPageSize); // tiny wasm method that just does grow_memory + if (Module["usingWasm"]) { + if (result !== (-1 | 0)) { + // success in native wasm memory growth, get the buffer from the memory + return Module['buffer'] = Module['wasmMemory'].buffer; + } else { + return null; + } + } else { + // in interpreter, we replace Module.buffer if we allocate + return Module['buffer'] !== old ? Module['buffer'] : null; // if it was reallocated, it changed + } }; // Provide an "asm.js function" for the application, called to "link" the asm.js module. We instantiate -- cgit v1.2.3