Allow multiple registration of same image in the GlobalRegistry #10874
+94
−73
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.
With
Module::deserialize_raw
it is possible to create multipleCodeMemory
objects that refer to the same underlying image. This is useful when embedder uses multipleEngine
objects with different config. Currently this fails on assertion when trying to register same region of code second time in theglobal_code
registry.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_data
field which must be identical for all items.This commit modifies global registry to only store raw pointers to the
trap_data
section along with an usage count. Unregistration is moved intoDrop
guard to ensure that underlying data is not freed before unregistration is manually called.