pub struct Vmo(/* private fields */);
Expand description
An object representing a Zircon virtual memory object.
As essentially a subtype of Handle
, it can be freely interconverted.
Implementations§
Source§impl Vmo
impl Vmo
Sourcepub fn create(size: u64) -> Result<Vmo, Status>
pub fn create(size: u64) -> Result<Vmo, Status>
Create a virtual memory object.
Wraps the
zx_vmo_create
syscall. See the
Shared Memory: Virtual Memory Objects (VMOs)
for more information.
Sourcepub fn create_with_opts(opts: VmoOptions, size: u64) -> Result<Vmo, Status>
pub fn create_with_opts(opts: VmoOptions, size: u64) -> Result<Vmo, Status>
Create a virtual memory object with options.
Wraps the
zx_vmo_create
syscall, allowing options to be passed.
Sourcepub fn create_contiguous(
bti: &Bti,
size: usize,
alignment_log2: u32,
) -> Result<Vmo, Status>
pub fn create_contiguous( bti: &Bti, size: usize, alignment_log2: u32, ) -> Result<Vmo, Status>
Create a physically contiguous virtual memory object.
Wraps the
zx_vmo_create_contiguous
syscall.
Sourcepub fn read(&self, data: &mut [u8], offset: u64) -> Result<(), Status>
pub fn read(&self, data: &mut [u8], offset: u64) -> Result<(), Status>
Read from a virtual memory object.
Wraps the zx_vmo_read
syscall.
Sourcepub unsafe fn read_raw<T>(
&self,
buffer: *mut T,
buffer_length: usize,
offset: u64,
) -> Result<(), Status>where
T: FromBytes,
pub unsafe fn read_raw<T>(
&self,
buffer: *mut T,
buffer_length: usize,
offset: u64,
) -> Result<(), Status>where
T: FromBytes,
Provides a very thin wrapper over zx_vmo_read
.
§Safety
Callers must guarantee that the buffer is valid to write to.
Sourcepub fn read_uninit<'a, T>(
&self,
data: &'a mut [MaybeUninit<T>],
offset: u64,
) -> Result<&'a mut [T], Status>where
T: Copy + FromBytes,
pub fn read_uninit<'a, T>(
&self,
data: &'a mut [MaybeUninit<T>],
offset: u64,
) -> Result<&'a mut [T], Status>where
T: Copy + FromBytes,
Same as read, but reads into memory that might not be initialized, returning an initialized slice of bytes on success.
Copy
is required to ensure that there are no custom Drop
implementations. It is
difficult to correctly run custom drop code after initializing a MaybeUninit
.
Sourcepub fn read_to_vec<T>(&self, offset: u64, length: u64) -> Result<Vec<T>, Status>where
T: Copy + FromBytes,
pub fn read_to_vec<T>(&self, offset: u64, length: u64) -> Result<Vec<T>, Status>where
T: Copy + FromBytes,
Same as read, but returns a Vec.
Sourcepub fn read_to_array<T, const N: usize>(
&self,
offset: u64,
) -> Result<[T; N], Status>where
T: Copy + FromBytes,
pub fn read_to_array<T, const N: usize>(
&self,
offset: u64,
) -> Result<[T; N], Status>where
T: Copy + FromBytes,
Same as read, but returns an array.
Sourcepub fn read_to_object<T>(&self, offset: u64) -> Result<T, Status>where
T: Copy + FromBytes,
pub fn read_to_object<T>(&self, offset: u64) -> Result<T, Status>where
T: Copy + FromBytes,
Same as read, but returns a T
.
Sourcepub fn write(&self, data: &[u8], offset: u64) -> Result<(), Status>
pub fn write(&self, data: &[u8], offset: u64) -> Result<(), Status>
Write to a virtual memory object.
Wraps the zx_vmo_write
syscall.
Sourcepub fn transfer_data(
&self,
options: TransferDataOptions,
offset: u64,
length: u64,
src_vmo: &Vmo,
src_offset: u64,
) -> Result<(), Status>
pub fn transfer_data( &self, options: TransferDataOptions, offset: u64, length: u64, src_vmo: &Vmo, src_offset: u64, ) -> Result<(), Status>
Efficiently transfers data from one VMO to another.
Sourcepub fn get_size(&self) -> Result<u64, Status>
pub fn get_size(&self) -> Result<u64, Status>
Get the size of a virtual memory object.
Wraps the zx_vmo_get_size
syscall.
Sourcepub fn set_size(&self, size: u64) -> Result<(), Status>
pub fn set_size(&self, size: u64) -> Result<(), Status>
Attempt to change the size of a virtual memory object.
Wraps the zx_vmo_set_size
syscall.
Sourcepub fn get_stream_size(&self) -> Result<u64, Status>
pub fn get_stream_size(&self) -> Result<u64, Status>
Get the stream size of a virtual memory object.
Wraps the zx_vmo_get_stream_size
syscall.
Sourcepub fn set_stream_size(&self, size: u64) -> Result<(), Status>
pub fn set_stream_size(&self, size: u64) -> Result<(), Status>
Attempt to set the stream size of a virtual memory object.
Wraps the zx_vmo_set_stream_size
syscall.
Sourcepub fn set_cache_policy(&self, cache_policy: CachePolicy) -> Result<(), Status>
pub fn set_cache_policy(&self, cache_policy: CachePolicy) -> Result<(), Status>
Attempt to change the cache policy of a virtual memory object.
Wraps the zx_vmo_set_cache_policy
syscall.
Sourcepub fn op_range(&self, op: VmoOp, offset: u64, size: u64) -> Result<(), Status>
pub fn op_range(&self, op: VmoOp, offset: u64, size: u64) -> Result<(), Status>
Perform an operation on a range of a virtual memory object.
Wraps the zx_vmo_op_range syscall.
Sourcepub fn info(&self) -> Result<VmoInfo, Status>
pub fn info(&self) -> Result<VmoInfo, Status>
Wraps the zx_object_get_info syscall for the ZX_INFO_VMO topic.
Sourcepub fn create_child(
&self,
opts: VmoChildOptions,
offset: u64,
size: u64,
) -> Result<Vmo, Status>
pub fn create_child( &self, opts: VmoChildOptions, offset: u64, size: u64, ) -> Result<Vmo, Status>
Create a new virtual memory object that clones a range of this one.
Wraps the zx_vmo_create_child syscall.
Sourcepub fn replace_as_executable(self, vmex: &Resource) -> Result<Vmo, Status>
pub fn replace_as_executable(self, vmex: &Resource) -> Result<Vmo, Status>
Replace a VMO, adding execute rights.
Wraps the zx_vmo_replace_as_executable syscall.
Trait Implementations§
Source§impl AsHandleRef for Vmo
impl AsHandleRef for Vmo
Source§fn as_handle_ref(&self) -> Unowned<'_, Handle>
fn as_handle_ref(&self) -> Unowned<'_, Handle>
object_wait_many
.