You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor resetting memory on MemoryImageSlot drop (#11510) (#11537)
* Refactor resetting memory on `MemoryImageSlot` drop
This commit refactors the behavior of dropping a `MemoryImageSlot` to no
longer map anonymous memory into the slot. This behavior was implemented
previously because if a `MemoryImageSlot` is dropped then the state of
the slot is unknown and to prevent any sort of data leakage a reset is
performed.
This reset operation, however, is fallible in that it calls `mmap`.
Calls to `mmap` can fail due to `ENOMEM`, for example, if the process
has reached its VMA limit. This means that if a process is in a near-OOM
condition then failing to allocate a memory image could panic the
process due to the `unwrap()` in the destructor of `MemoryImageSlot`.
The purpose of this commit is to avoid this `unwrap()` and instead move
the reset behavior to a location where an error can be propagated.
This commit removes the clear-on-drop behavior of `MemoryImageSlot`
slot. This was already disabled everywhere except the pooling allocator.
The pooling allocator now maintains an extra bit of state-per-slot where
instead of storing `Option<MemoryImageSlot>` it now stores effectively
one other variant of "unknown". On reuse of an "unknown" slot the memory
is reset back to an anonymous mapping and this is all done in a context
where an error can be propagated.
Two tests are added in this commit to confirm all of this behavior:
* The first test is a new test that passes both before and after this
commit which performs a failed allocation of a memory slot. A
successful allocation is then made to ensure that the previous image
is not present and zero memory is present. This test fails before the
commit if the clear-on-drop behavior is removed, and it fails with this
commit if the clear-on-reusing-unknown behavior is removed.
Effectively this test ensures that the clear-on-unknown-state logic is
present.
* The second test is a new test that panicked before this commit and
passes afterwards. This second test exhausts all VMAs in the current
process, or at least most of them, and then tries to allocate some
instances with an image. Instance allocation will eventually fail and
cause the erroneous path to get executed. This previously unwrapped a
`ENOMEM` failure, and now it can be handled gracefully by the
embedder.
* Skip the new test on QEMU, it fails on CI
* Only run test on Linux
0 commit comments