aboutsummaryrefslogtreecommitdiff
path: root/misc/wasm
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2019-09-04 15:14:13 -0400
committerAustin Clements <austin@google.com>2019-09-15 23:53:48 +0000
commit142c002ee714c871a5644557f8320171c8569a1f (patch)
treec6b8feb8b6a12bde24e3a857c4812f87fcbf5da0 /misc/wasm
parentd12c62d12dc87a086815ca9d8beaa8f0c8e26b00 (diff)
downloadgo-142c002ee714c871a5644557f8320171c8569a1f.tar.gz
go-142c002ee714c871a5644557f8320171c8569a1f.zip
misc/wasm: fix argv/envp layout
The wasm_exec.js wrapper tries to set up the argv and envp following the UNIX conventions, but doesn't get it quite right, which can cause runtime.goenv to crash if you get unlucky. The main problem was that the envp array wasn't terminated with a nil pointer, so the runtime didn't know when to stop reading the array. This CL adds that nil pointer to the end of the envp array. The other problem was harmless, but confusing. In the UNIX convention, the argv array consists of argc pointers followed by a nil pointer, followed by the envp array. However, wasm_exec.js put the environment variable count between the two pointer arrays rather than a nil pointer. The runtime never looks at this slot, so it didn't matter, but the break from convention left Cherry and I trying to debug why it *wasn't* losing any environment variables before we realized that that layouts happened to be close enough to work. This CL switches to the UNIX convention of simply terminating the argv array with a nil pointer. Change-Id: Ic9a4cd9eabb5dfa599a809b960f9e579b9f1f4db Reviewed-on: https://go-review.googlesource.com/c/go/+/193417 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Richard Musiol <neelance@gmail.com>
Diffstat (limited to 'misc/wasm')
-rw-r--r--misc/wasm/wasm_exec.js3
1 files changed, 2 insertions, 1 deletions
diff --git a/misc/wasm/wasm_exec.js b/misc/wasm/wasm_exec.js
index 1e1ba636ca..9639585693 100644
--- a/misc/wasm/wasm_exec.js
+++ b/misc/wasm/wasm_exec.js
@@ -457,12 +457,13 @@
this.argv.forEach((arg) => {
argvPtrs.push(strPtr(arg));
});
+ argvPtrs.push(0);
const keys = Object.keys(this.env).sort();
- argvPtrs.push(keys.length);
keys.forEach((key) => {
argvPtrs.push(strPtr(`${key}=${this.env[key]}`));
});
+ argvPtrs.push(0);
const argv = offset;
argvPtrs.forEach((ptr) => {