Struct SharedMemory

Source
pub struct SharedMemory { /* private fields */ }
Expand description

A shared memory file descriptor and its size.

Implementations§

Source§

impl SharedMemory

Source

pub fn new(name: Option<&CStr>) -> Result<SharedMemory>

Creates a new shared memory file descriptor with zero size.

If a name is given, it will appear in /proc/self/fd/<shm fd> for the purposes of debugging. The name does not need to be unique.

The file descriptor is opened with the close on exec flag and allows memfd sealing.

Source

pub fn from_raw_fd<T: IntoRawFd>(fd: T) -> Result<SharedMemory>

Constructs a SharedMemory instance from a file descriptor that represents shared memory.

The size of the resulting shared memory will be determined using File::seek. If the given file’s size can not be determined this way, this will return an error.

Source

pub fn get_seals(&self) -> Result<MemfdSeals>

Gets the memfd seals that have already been added to this.

This may fail if this instance was not constructed from a memfd.

Source

pub fn add_seals(&mut self, seals: MemfdSeals) -> Result<()>

Adds the given set of memfd seals.

This may fail if this instance was not constructed from a memfd with sealing allowed or if the seal seal (F_SEAL_SEAL) bit was already added.

Source

pub fn size(&self) -> u64

Gets the size in bytes of the shared memory.

The size returned here does not reflect changes by other interfaces or users of the shared memory file descriptor..

Source

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

Sets the size in bytes of the shared memory.

Note that if some process has already mapped this shared memory and the new size is smaller, that process may get signaled with SIGBUS if they access any page past the new size.

Trait Implementations§

Source§

impl AsRawFd for SharedMemory

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl Into<File> for SharedMemory

Source§

fn into(self) -> File

Converts this type into the (usually inferred) input type.

Auto Trait Implementations§

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.