-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use main module's realloc if available when applying an adapter (#900)
* use main module's realloc if available when applying an adapter Originally, adapters were expected to allocate their memory using `memory.grow`, and `wit-component` would also use `memory.grow` to allocate stack space for the adapter if needed. However, it turned out this didn't work reliably with `wasi-sdk`'s libc, which assumed it owned the entire memory region, leading to chaos when both the adapter and the main module thought they owned the same pages. Alex has since patched `wasi-sdk` to address the issue, but it still affects older toolchains, and particularly modules which were built prior to the patch. However, many of those older modules export `cabi_realloc` (or it's older equivalent, `canonical_abi_realloc`), so we might as well use that if it's available. That's what this commit does. In cases where the main module exports a realloc function and we have a use for it (i.e. either the adapter imports `cabi_realloc` or it needs a shadow stack), we'll use it. In cases where we have a use for it but the main module does _not_ export it, we fall back to the old behavior of using `memory.grow` and hope the module was built with a recent-enough `wasi-sdk`. This also addresses alternative toolchains which are not based on `wasi-sdk` and may expect to own the module's entire memory. In that case, the toolchain can simply export `cabi_realloc` and `wit-component` will use it. Signed-off-by: Joel Dice <[email protected]> * simplify code and name synthesized `cabi_realloc` import Signed-off-by: Joel Dice <[email protected]> --------- Signed-off-by: Joel Dice <[email protected]>
- Loading branch information
Showing
16 changed files
with
757 additions
and
56 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.