diff options
-rw-r--r-- | src/asm2wasm.h | 1 | ||||
-rw-r--r-- | src/js/wasm.js-post.js | 14 | ||||
-rw-r--r-- | test/memorygrowth.fromasm | 2 | ||||
-rw-r--r-- | test/memorygrowth.fromasm.imprecise | 2 | ||||
-rw-r--r-- | test/memorygrowth.fromasm.imprecise.no-opts | 2 | ||||
-rw-r--r-- | test/memorygrowth.fromasm.no-opts | 2 |
6 files changed, 17 insertions, 6 deletions
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 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 diff --git a/test/memorygrowth.fromasm b/test/memorygrowth.fromasm index f3f217292..2ebb9f60f 100644 --- a/test/memorygrowth.fromasm +++ b/test/memorygrowth.fromasm @@ -24,7 +24,7 @@ (import "env" "___unlock" (func $xa (param i32))) (import "env" "___syscall146" (func $ya (param i32 i32) (result i32))) (import "asm2wasm" "i32u-div" (func $i32u-div (param i32 i32) (result i32))) - (import "env" "memory" (memory $0 256 256)) + (import "env" "memory" (memory $0 256)) (import "env" "table" (table 8 8 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) diff --git a/test/memorygrowth.fromasm.imprecise b/test/memorygrowth.fromasm.imprecise index 882197b46..7e970f096 100644 --- a/test/memorygrowth.fromasm.imprecise +++ b/test/memorygrowth.fromasm.imprecise @@ -23,7 +23,7 @@ (import "env" "___syscall54" (func $wa (param i32 i32) (result i32))) (import "env" "___unlock" (func $xa (param i32))) (import "env" "___syscall146" (func $ya (param i32 i32) (result i32))) - (import "env" "memory" (memory $0 256 256)) + (import "env" "memory" (memory $0 256)) (import "env" "table" (table 8 8 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) diff --git a/test/memorygrowth.fromasm.imprecise.no-opts b/test/memorygrowth.fromasm.imprecise.no-opts index 54ae2646d..579ea01fa 100644 --- a/test/memorygrowth.fromasm.imprecise.no-opts +++ b/test/memorygrowth.fromasm.imprecise.no-opts @@ -23,7 +23,7 @@ (import "env" "___syscall54" (func $wa (param i32 i32) (result i32))) (import "env" "___unlock" (func $xa (param i32))) (import "env" "___syscall146" (func $ya (param i32 i32) (result i32))) - (import "env" "memory" (memory $0 256 256)) + (import "env" "memory" (memory $0 256)) (import "env" "table" (table 8 8 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) diff --git a/test/memorygrowth.fromasm.no-opts b/test/memorygrowth.fromasm.no-opts index a595d965d..7c877fb39 100644 --- a/test/memorygrowth.fromasm.no-opts +++ b/test/memorygrowth.fromasm.no-opts @@ -24,7 +24,7 @@ (import "env" "___unlock" (func $xa (param i32))) (import "env" "___syscall146" (func $ya (param i32 i32) (result i32))) (import "asm2wasm" "i32u-div" (func $i32u-div (param i32 i32) (result i32))) - (import "env" "memory" (memory $0 256 256)) + (import "env" "memory" (memory $0 256)) (import "env" "table" (table 8 8 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) |