Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation on Wasm Workers #21686

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

juj
Copy link
Collaborator

@juj juj commented Apr 3, 2024

Update documentation on Wasm Workers stack size, and Wasm Workers vs Emscripten Workers API. Addresses #21610.

@juj juj enabled auto-merge (squash) April 3, 2024 07:00

Since WebAssembly does not support virtual memory, the size of the LLVM data stack that is defined both for Wasm Workers but also the main thread will not be possible to grow at runtime. So if the Worker (or the main thread) runs out of stack space, the program behavior will be undefined. Use the Emscripten linker flag -sSTACK_OVERFLOW_CHECK=2 to emit runtime stack overflow checks into the program code to detect these situations during development.

Note that a stack overflow in this LLVM data stack does not imply stack overflow security vulnerabilities in the WebAssembly VM. The Wasm VM program flow stack is separate from this LLVM data stack, and guarded from access from Wasm code. However, if your threat model consists of executing untrusted program code, or executing a program from untrusted input inside the WebAssembly module, you may need to consider your security model to include safekeeping the LLVM data stack as well.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/program flow/control flow/


Since WebAssembly does not support virtual memory, the size of the LLVM data stack that is defined both for Wasm Workers but also the main thread will not be possible to grow at runtime. So if the Worker (or the main thread) runs out of stack space, the program behavior will be undefined. Use the Emscripten linker flag -sSTACK_OVERFLOW_CHECK=2 to emit runtime stack overflow checks into the program code to detect these situations during development.

Note that a stack overflow in this LLVM data stack does not imply stack overflow security vulnerabilities in the WebAssembly VM. The Wasm VM program flow stack is separate from this LLVM data stack, and guarded from access from Wasm code. However, if your threat model consists of executing untrusted program code, or executing a program from untrusted input inside the WebAssembly module, you may need to consider your security model to include safekeeping the LLVM data stack as well.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both WebAssembly VM and Wasm VM are used here. Maybe just use one of them for consistency?


Since WebAssembly does not support virtual memory, the size of the LLVM data stack that is defined both for Wasm Workers but also the main thread will not be possible to grow at runtime. So if the Worker (or the main thread) runs out of stack space, the program behavior will be undefined. Use the Emscripten linker flag -sSTACK_OVERFLOW_CHECK=2 to emit runtime stack overflow checks into the program code to detect these situations during development.

Note that a stack overflow in this LLVM data stack does not imply stack overflow security vulnerabilities in the WebAssembly VM. The Wasm VM program flow stack is separate from this LLVM data stack, and guarded from access from Wasm code. However, if your threat model consists of executing untrusted program code, or executing a program from untrusted input inside the WebAssembly module, you may need to consider your security model to include safekeeping the LLVM data stack as well.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non of this stuff is specific to wasm workers as far as I can tell, so I wonder if this should be documents in the theading docs and perhaps linked to from here?


Both the Worker API and Wasm Workers API provide the user with ability to postMessage() function calls to the Worker. In Worker API, this message posting is restricted to need to originate/initiate from the main thread towards the Worker. With Wasm Workers however one can also postMessage() function calls to their parent (owning) thread.

If posting function calls with the Emscripten Worker API, it is required that the target Worker URL points to an Emscripten compiled program (so it has the ``Module`` structure to locate function names). Only functions that have been exported to the ``Module`` object are callable. With Wasm Workers, any C/C++ function may be posted, and does not need to be exported.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you format all these new paragaphs to 80 columns?

@msqr1
Copy link

msqr1 commented Apr 14, 2024

So the pre-allocated stack is for thread-local storage? @juj

@msqr1
Copy link

msqr1 commented Apr 19, 2024

If the normal worker api can be spawned using a custom URL, how do we postmessage wasm function calls over? How does the worker api function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants