From 38332da9dad84141aa1587f55cd763866fea1585 Mon Sep 17 00:00:00 2001 From: Jakob Getz Date: Tue, 19 Dec 2023 14:24:06 +0900 Subject: [PATCH] fix store bug, added testcases for the fix --- .vscode/launch.json | 2 +- src/replay-generator.cts | 4 +-- .../index.wat | 33 +++++++++++++++++++ .../test.js | 22 +++++++++++++ .../mem-exp-host-mod-store-lastfunc/index.wat | 21 ++++++++++++ .../mem-exp-host-mod-store-lastfunc/test.js | 20 +++++++++++ 6 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 tests/node/mem-exp-host-mod-store-lastfunc-return/index.wat create mode 100644 tests/node/mem-exp-host-mod-store-lastfunc-return/test.js create mode 100644 tests/node/mem-exp-host-mod-store-lastfunc/index.wat create mode 100644 tests/node/mem-exp-host-mod-store-lastfunc/test.js diff --git a/.vscode/launch.json b/.vscode/launch.json index 89a9aa6e..4e5bdc9e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -27,7 +27,7 @@ "args": [ "node", "-t", - "exported-called-params-grow-mem", + "mem-exp-host-mod-pingpong", ] }, { diff --git a/src/replay-generator.cts b/src/replay-generator.cts index 7b877c98..430cac18 100644 --- a/src/replay-generator.cts +++ b/src/replay-generator.cts @@ -110,14 +110,14 @@ export default class Generator { this.state.lastFuncReturn = true r.slice(-1)[0].reps += 1 this.state.importCallStack.pop() - this.state.importCallStackFunction.pop() + this.state.lastFunc = this.state.importCallStackFunction.pop() break } } this.state.lastFuncReturn = true r.push({ results: event.results, reps: 1 }) this.state.importCallStack.pop() - this.state.importCallStackFunction.pop() + this.state.lastFunc = this.state.importCallStackFunction.pop() break case "Load": this.pushEvent({ diff --git a/tests/node/mem-exp-host-mod-store-lastfunc-return/index.wat b/tests/node/mem-exp-host-mod-store-lastfunc-return/index.wat new file mode 100644 index 00000000..8856dee7 --- /dev/null +++ b/tests/node/mem-exp-host-mod-store-lastfunc-return/index.wat @@ -0,0 +1,33 @@ +(module + (import "env" "changeMemAfterReentry" (func $changeMemAfterReentry (result i32))) + (import "env" "foo" (func $foo)) + (import "env" "bar" (func $bar (result i32))) + (func $main (export "main") + call $changeMemAfterReentry + drop + i32.const 1 + i32.load + drop + call $changeMemAfterReentry + drop + i32.const 1 + i32.load + drop + call $changeMemAfterReentry + drop + i32.const 1 + i32.load + drop + ) + (func (export "reentry") + call $foo + i32.const 1 + i32.load + drop + ) + (func (export "reentry2") + call $bar + drop + ) + (memory (export "memory") 1) +) diff --git a/tests/node/mem-exp-host-mod-store-lastfunc-return/test.js b/tests/node/mem-exp-host-mod-store-lastfunc-return/test.js new file mode 100644 index 00000000..94bb46e0 --- /dev/null +++ b/tests/node/mem-exp-host-mod-store-lastfunc-return/test.js @@ -0,0 +1,22 @@ +export default async function test(wasmBinary) { + let instance + let imports = { + env: { + changeMemAfterReentry: () => { + instance.exports.reentry() + new Uint8Array(instance.exports.memory.buffer)[1] = 1 + return 69 + }, + foo: () => { + instance.exports.reentry2() + }, + bar: () => { + new Uint8Array(instance.exports.memory.buffer)[1] = 2 + return 420 + } + } + } + let wasm = await WebAssembly.instantiate(wasmBinary, imports) + instance = wasm.instance + instance.exports.main() +} \ No newline at end of file diff --git a/tests/node/mem-exp-host-mod-store-lastfunc/index.wat b/tests/node/mem-exp-host-mod-store-lastfunc/index.wat new file mode 100644 index 00000000..36f985fd --- /dev/null +++ b/tests/node/mem-exp-host-mod-store-lastfunc/index.wat @@ -0,0 +1,21 @@ +(module + (import "env" "changeMemAfterReentry" (func $changeMemAfterReentry)) + (import "env" "foo" (func $foo)) + (import "env" "bar" (func $bar)) + (func $main (export "main") + call $changeMemAfterReentry + i32.const 1 + i32.load + drop + ) + (func (export "reentry") + call $foo + i32.const 1 + i32.load + drop + ) + (func (export "reentry2") + call $bar + ) + (memory (export "memory") 1) +) diff --git a/tests/node/mem-exp-host-mod-store-lastfunc/test.js b/tests/node/mem-exp-host-mod-store-lastfunc/test.js new file mode 100644 index 00000000..c415fcae --- /dev/null +++ b/tests/node/mem-exp-host-mod-store-lastfunc/test.js @@ -0,0 +1,20 @@ +export default async function test(wasmBinary) { + let instance + let imports = { + env: { + changeMemAfterReentry: () => { + instance.exports.reentry() + new Uint8Array(instance.exports.memory.buffer)[1] = 1 + }, + foo: () => { + instance.exports.reentry2() + }, + bar: () => { + new Uint8Array(instance.exports.memory.buffer)[1] = 2 + } + } + } + let wasm = await WebAssembly.instantiate(wasmBinary, imports) + instance = wasm.instance + instance.exports.main() +} \ No newline at end of file