RelocatablePointer

Struct RelocatablePointer 

Source
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:

  1. Every construct which relies on a RelocatablePointer must 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.
  2. The construct which is using the RelocatablePointer and 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>

Source

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.

Source

pub unsafe fn new_uninit() -> Self

Creates a new uninitialized RelocatablePointer.

§Safety
Source

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

Trait Implementations§

Source§

impl<T: Debug> Debug for RelocatablePointer<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> PointerTrait<T> for RelocatablePointer<T>

Source§

unsafe fn as_ptr(&self) -> *const T

Return a pointer to the underlying const type Read more
Source§

unsafe fn as_mut_ptr(&mut self) -> *mut T

Return a pointer to the underlying mutable type Read more
Source§

fn is_initialized(&self) -> bool

Indicates whether the pointer has been initialized. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for RelocatablePointer<T>

§

impl<T> RefUnwindSafe for RelocatablePointer<T>
where T: RefUnwindSafe,

§

impl<T> Send for RelocatablePointer<T>
where T: Send,

§

impl<T> Sync for RelocatablePointer<T>
where T: Sync,

§

impl<T> Unpin for RelocatablePointer<T>
where T: Unpin,

§

impl<T> UnwindSafe for RelocatablePointer<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.