pub struct RelocatablePointer<T> { /* private fields */ }Expand description
A RelocatablePointer stores only the distance from its memory starting position to the
memory location it is pointing to. When the RelocatablePointer is now shared between
processes its virtual memory starting position changes but the distance to the object it is
pointing to is the same.
Important:
- Every construct which relies on a
RelocatablePointermust be declared with[repr(C)]. Otherwise different compilation units may have a different structural layout of the data type which is shared between processes which leads to undefined behavior. - The construct which is using the
RelocatablePointerand the pointee must be stored in the same shared memory object. Pointing to a different shared memory segment most likely leads to crashes since it can be mapped in a different order, at a different position and the distance to the memory destination is off.
Implementations§
Source§impl<T> RelocatablePointer<T>
impl<T> RelocatablePointer<T>
Sourcepub fn new(distance: isize) -> Self
pub fn new(distance: isize) -> Self
Creates a new RelocatablePointer. The distance is the relative distance to the memory
destination starting from the memory location of this RelocatablePointer.
Sourcepub unsafe fn new_uninit() -> Self
pub unsafe fn new_uninit() -> Self
Creates a new uninitialized RelocatablePointer.
§Safety
RelocatablePointer::init()must be called once before use
Sourcepub unsafe fn init(&self, ptr: NonNull<[u8]>)
pub unsafe fn init(&self, ptr: NonNull<[u8]>)
Initializes the RelocatablePointer by setting the distance to the memory destination
by providing an absolut pointer to it. The distance can be calculated from the
RelocatablePointer memory location and the absolut position of the destination.
Important: The pointer must point into the same shared memory object.
§Safety
RelocatablePointerwas created withRelocatablePointer::new_uninit()- ptr has an alignment of
core::mem::align_of<T>() - ptr has a size which is an multiple of
core::mem::size_of<T>() - It must be called exactly once before using the
RelocatablePointer