pub struct BorrowedMap<'shm> { /* private fields */ }
Expand description
A wrapper around an memmap2::MmapMut
to prevent one from accidentally calling Shm::map
twice on the same Shm (which could very easily introduce memory unsoundness). To use the
contained map, just call BorrowedMap::map
. One cannot safely move the map out of this
struct, as that would easily allow them to break the lifetime-dependent relationship between
this map and the Shm
it’s mapped onto.
To be clear: This risk of memory unsafety does not come from an actual borrowing of memory
between the Shm
and the MmapMut
- a MmapMut
can be dropped before or after the
Shm
which it is mapped from and nothing bad will happen. The issue comes when two
MmapMut
s are mapped from the same Shm
- this could allow e.g. something to borrow from
one MmapMut
, then the other MmapMut
could be shrunk, thus invalidating the references
from the first map.