Skip to content

Commit 3dbef5a

Browse files
committed
Always assert on calling proxied function from wasm worker. NFC
Follow up to #20135. See #20135 (comment)
1 parent cbf4256 commit 3dbef5a

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/jsifier.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ if (ENVIRONMENT_IS_PTHREAD)
253253
${body}
254254
}\n`
255255
});
256-
} else if (WASM_WORKERS && ASSERTIONS) {
256+
}
257+
if (WASM_WORKERS && ASSERTIONS) {
257258
// In ASSERTIONS builds add runtime checks that proxied functions are not attempted to be called in Wasm Workers
258259
// (since there is no automatic proxying architecture available)
259260
snippet = modifyJSFunction(snippet, (args, body) => `

src/library.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3794,7 +3794,7 @@ function wrapSyscallFunction(x, library, isWasi) {
37943794
if (!WASMFS) {
37953795
library[x + '__deps'].push('$SYSCALLS');
37963796
}
3797-
#if PTHREADS
3797+
#if SHARED_MEMORY
37983798
// Most syscalls need to happen on the main JS thread (e.g. because the
37993799
// filesystem is in JS and on that thread). Proxy synchronously to there.
38003800
// There are some exceptions, syscalls that we know are ok to just run in
@@ -3804,6 +3804,10 @@ function wrapSyscallFunction(x, library, isWasi) {
38043804
// instead of synchronously, and marked with
38053805
// __proxy: 'async'
38063806
// (but essentially all syscalls do have return values).
3807+
//
3808+
// Note that we add this even in the WASM_WORKERS case since we want calls
3809+
// to these functions from wasm workers to assert in debug builds (since wasm
3810+
// workers lack proxying support).
38073811
if (library[x + '__proxy'] === undefined) {
38083812
library[x + '__proxy'] = 'sync';
38093813
}

src/library_wasi.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,11 @@ var WasiLibrary = {
263263
},
264264
fd_write__deps: ['$flush_NO_FILESYSTEM', '$printChar'],
265265
fd_write__postset: () => addAtExit('flush_NO_FILESYSTEM()'),
266+
// Avoid proxying when we are not using the filesystem
267+
fd_write__proxy: 'none',
266268
#else
267269
fd_write__deps: ['$printChar'],
270+
fd_write__proxy: 'none',
268271
#endif
269272
fd_write: (fd, iov, iovcnt, pnum) => {
270273
#if SYSCALLS_REQUIRE_FILESYSTEM
@@ -305,6 +308,9 @@ var WasiLibrary = {
305308
#endif
306309
},
307310

311+
#if !SYSCALLS_REQUIRE_FILESYSTEM
312+
fd_close__sync: 'none',
313+
#endif
308314
fd_close: (fd) => {
309315
#if SYSCALLS_REQUIRE_FILESYSTEM
310316
var stream = SYSCALLS.getStreamFromFD(fd);

0 commit comments

Comments
 (0)