Refactor stack management on wasip3 - #870
Open
alexcrichton wants to merge 1 commit into
Open
Conversation
This commit is a refactor of how wasip3 works specifically with respect to management of the stack and intrinsics used. The end result of this work is that a number of bugs, present in wasi-libc today, are all fixed: * Sync-reentrant calls, allowed in the component model, previously used the same stack and stomped over each other. * Resource destructors, executed with fresh task state, did not correctly setup a stack to execute on. The fix for the first issue here is particularly gnarly because it means that stacks are required to be dynamically allocated in some situations. This in turn means that those same stacks need to be deallocated, and prior to this commit there was no great place to doing that. The fix for the second issue is a bit broader than wasi-libc as well as it couldn't be solved exclusively here. To resolve these problems this commit updates the `wasm-tools` version required, notably including recent PRs to adjust how linking works to transform `__wasm_init_task` and `__wasm_init_async_task` into a more-generic `__wasm_task_hook` function. This hook function is invoked in more locations, such as resource destructors, and additionally subsumes previous custom logic with `cabi_realloc`. Effectively `__wasm_task_hook` is now the sole location concerned with configuring a stack and TLS for the task-to-run. This handles all situations such as sync/async tasks, `_initialize`, `cabi_realloc`, resource destructors, and post-return. This was implemented in bytecodealliance/wasm-tools#2603 and bytecodealliance/wasm-tools#2605. To get existing tests all passing after updating `wasm-tools` many of the changes here were needed no matter what. To fully exercise the new functionality, however, I've also started adding a composition-based test suite which creates two components, composes them together, and runs that as a test. This creates the ability to test situations such as resource destructors and reentrant behavior purely within this repository. My hope is that as we discover bugs/issues elsewhere it'll be possible to add a small reduced test case to this repo as a composition. For now the composition tests are pretty simple and only cover the cases that failed before this PR and now fail after this PR.
Collaborator
Author
|
I'll note that like with #867 this will require an updated wasm-tools, not yet published, to pass CI. Locally, however, everything's passing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit is a refactor of how wasip3 works specifically with respect to management of the stack and intrinsics used. The end result of this work is that a number of bugs, present in wasi-libc today, are all fixed:
The fix for the first issue here is particularly gnarly because it means that stacks are required to be dynamically allocated in some situations. This in turn means that those same stacks need to be deallocated, and prior to this commit there was no great place to doing that. The fix for the second issue is a bit broader than wasi-libc as well as it couldn't be solved exclusively here.
To resolve these problems this commit updates the
wasm-toolsversion required, notably including recent PRs to adjust how linking works to transform__wasm_init_taskand__wasm_init_async_taskinto a more-generic__wasm_task_hookfunction. This hook function is invoked in more locations, such as resource destructors, and additionally subsumes previous custom logic withcabi_realloc. Effectively__wasm_task_hookis now the sole location concerned with configuring a stack and TLS for the task-to-run. This handles all situations such as sync/async tasks,_initialize,cabi_realloc, resource destructors, and post-return. This was implemented in bytecodealliance/wasm-tools#2603 and bytecodealliance/wasm-tools#2605.To get existing tests all passing after updating
wasm-toolsmany of the changes here were needed no matter what. To fully exercise the new functionality, however, I've also started adding a composition-based test suite which creates two components, composes them together, and runs that as a test. This creates the ability to test situations such as resource destructors and reentrant behavior purely within this repository. My hope is that as we discover bugs/issues elsewhere it'll be possible to add a small reduced test case to this repo as a composition. For now the composition tests are pretty simple and only cover the cases that failed before this PR and now fail after this PR.