Add a check to command modules to ensure that they're only started once.#329
Add a check to command modules to ensure that they're only started once.#329sunfishcode merged 2 commits intomainfrom
Conversation
libc-bottom-half/crt/crt1-command.c
Outdated
|
|
||
| // Commands should only be called once per instance. This simple check ensures | ||
| // that the `_start` function isn't started more than once. `address_space(1)` | ||
| // tells clang to put this variable in a wasm global. |
There was a problem hiding this comment.
Does that actually work? It seems a little risky to depend on this now. Why not just is a simple static?
There was a problem hiding this comment.
No big reason; and depending on it breaks LLVM 11, which we still support for now, so I'll switch to a static.
libc-bottom-half/crt/crt1-command.c
Outdated
| if (started != 0) { | ||
| __builtin_trap(); | ||
| } | ||
| started = 0; |
There was a problem hiding this comment.
Seems like it would be good place for #ifndef NDEBUG but we don't have a debug version of libc yet IIUC
There was a problem hiding this comment.
I care about code size, but this is just a few bytes. And this hazard comes up in both component use cases and JS embedding use cases, where creating an instance is separated from running the command and there's no other way to prevent the command from being run multiple times, causing UB.
Wasm command modules should only be called once per instance, because the programming model doesn't leave linear memory in a reusable state when the program exits. As use cases arise for loading wasm modules in environments that want to treat them like reactors, add a safety check to ensure that command modules are used according to their expectations.
8f56960 to
2323070
Compare
libc-bottom-half/crt/crt1-command.c
Outdated
| if (started != 0) { | ||
| __builtin_trap(); | ||
| } | ||
| started = 0; |
|
Oops; fixed. |
…ce. (WebAssembly#329) * Add a check to command modules to ensure that they're only started once. Wasm command modules should only be called once per instance, because the programming model doesn't leave linear memory in a reusable state when the program exits. As use cases arise for loading wasm modules in environments that want to treat them like reactors, add a safety check to ensure that command modules are used according to their expectations.
…nce (WebAssembly#388) Calling _initialize multiple times is undefined behavior, since the ctors are not guaranteed to be idempotent. We should have this safety check which is similar to WebAssembly#329.
Wasm command modules should only be called once per instance, because the programming model doesn't leave linear memory in a reusable state when the program exits. As use cases arise for loading wasm modules in environments that want to treat them like reactors, add a safety check to ensure that command modules are used according to their expectations.