Milek7 opened PR #10874 from Milek7:global-trap-registry to bytecodealliance:main:
With
Module::deserialize_rawit is possible to create multipleCodeMemoryobjects that refer to the same underlying image. This is useful when embedder uses multipleEngineobjects with different config. Currently this fails on assertion when trying to register same region of code second time in theglobal_coderegistry.Global code registry stores
Arc<CodeMemory>, but only needs to access trap data section in the image. Storing list of these in code registry would be silly, because on PC lookup one item would need to be picked arbitrarily, possibly different than the one which is currently executing, only to accesstrap_datafield which must be identical for all items.This commit modifies global registry to only store raw pointers to the
trap_datasection along with an usage count. Unregistration is moved intoDropguard to ensure that underlying data is not freed before unregistration is manually called.
Milek7 requested wasmtime-core-reviewers for a review on PR #10874.
Milek7 requested fitzgen for a review on PR #10874.
fitzgen commented on PR #10874:
This is useful when embedder uses multiple
Engineobjects with different config.If the engines have different configs, then the same compiled artifact will not be compatible with all engines, only the one using the config that it was compiled with.
fitzgen commented on PR #10874:
(And if the engines all have the same config, then you might as well just use one engine.)
Milek7 commented on PR #10874:
I think it's not nice if it crashes on assert just because you used same image more than once. There's no such limitation for modules loaded from normal file. (and to be precise there are config settings that are not dependent on the artifact, like stack limits, memory allocators and few others)
alexcrichton commented on PR #10874:
One comment on this I've got is that we've generally been trying to reduce
unsafeusage in Wasmtime wherever possible, so if this is added it'd be great to do it without increasing the amount ofunsafe. Additionally can you ensure there's a test for this? Otherwise it's pretty likely functionality is lost in a future refactoring.
Milek7 commented on PR #10874:
I think avoiding unsafe would require storing registry as
BTreeMap<usize, Vec<Arc<CodeMemory>>>, would that be preferable?
Last updated: Dec 06 2025 at 07:03 UTC