Struct Shm

Source
pub struct Shm { /* private fields */ }

Implementations§

Source§

impl Shm

Source

pub fn open(name: &str, oflags: OFlags, mode: Mode) -> Result<Self>

Opens shared memory at name.

Source

pub fn size(&self) -> Result<usize>

Returns the size of the shared memory reported by fstat.

Source

pub fn set_size(&mut self, size: usize) -> Result<()>

Sets the size of the shared memory with ftruncate.

Source

pub fn name(&self) -> &str

Source

pub unsafe fn map(&mut self, offset: usize) -> Result<BorrowedMap<'_>>

Try to create a memmap2::MmapMut by which we can read and write to this shared memory object. The provided offset may not be greater than or equal to the value returned by Self::size (if it is, this function will return an error).

This function is generally only useful if one has already called Self::set_size. If one hasn’t, this function will return a mapped area with a length of 0, so writing to and reading from it will either fail or do nothing.

§Safety

This is unsafe due to the fundamental nature of memory shared between processes. The documentation for memmap2::MmapOptions::map_mut can share more details, but doesn’t paint the whole picture. We aren’t using this to map a file, but rather just a chunk of memory that can be shared between processes. Because this can be shared between processes and the changes from one process are immediately visible from a different process, this very easily allows one to run into use-after-free issues if they are not safe.

There is no way to prevent this sort of intra-process borrow-dependency in safe rust, so one must simply be safe when using this. However, we do prevent one from easily accidentally making two mmaps from the same Shm by modeling the fact that the map borrows from the Shm in the type system with the BorrowedMap type.

Source

pub fn as_fd(&self) -> BorrowedFd<'_>

Source

pub fn name_ptr(&self) -> &CStr

Trait Implementations§

Source§

impl Debug for Shm

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Shm

§

impl RefUnwindSafe for Shm

§

impl Send for Shm

§

impl Sync for Shm

§

impl Unpin for Shm

§

impl UnwindSafe for Shm

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.