From 08a8fa9c471603c7ec44895392c6bfa31a8ddcb6 Mon Sep 17 00:00:00 2001 From: Richard Musiol Date: Sun, 23 May 2021 23:06:43 +0200 Subject: [PATCH] misc/wasm: ensure correct stack pointer in catch clauses The stack pointer may have changed after a call from JavaScript into Go code because of stack growth. The normal case already updated the sp variable accordingly, but the catch case did not yet. Fixes #45433 Change-Id: I3e0a33381929626f6b21902948935eb5ffb26c96 Reviewed-on: https://go-review.googlesource.com/c/go/+/321936 Trust: Richard Musiol Run-TryBot: Richard Musiol TryBot-Result: Go Bot Reviewed-by: Cherry Mui --- misc/wasm/wasm_exec.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/misc/wasm/wasm_exec.js b/misc/wasm/wasm_exec.js index 3e41e628ef..231185a123 100644 --- a/misc/wasm/wasm_exec.js +++ b/misc/wasm/wasm_exec.js @@ -401,6 +401,7 @@ storeValue(sp + 56, result); this.mem.setUint8(sp + 64, 1); } catch (err) { + sp = this._inst.exports.getsp() >>> 0; // see comment above storeValue(sp + 56, err); this.mem.setUint8(sp + 64, 0); } @@ -417,6 +418,7 @@ storeValue(sp + 40, result); this.mem.setUint8(sp + 48, 1); } catch (err) { + sp = this._inst.exports.getsp() >>> 0; // see comment above storeValue(sp + 40, err); this.mem.setUint8(sp + 48, 0); } @@ -433,6 +435,7 @@ storeValue(sp + 40, result); this.mem.setUint8(sp + 48, 1); } catch (err) { + sp = this._inst.exports.getsp() >>> 0; // see comment above storeValue(sp + 40, err); this.mem.setUint8(sp + 48, 0); } -- 2.50.0