pub struct GuestMemWriter { /* private fields */ }Expand description
Raw pointer wrapper for guest physical memory access.
Backed by the VM-lifetime mmap of guest RAM. Device-owned descriptor buffers are exclusive to the device per the VirtIO spec — the guest will not touch them until the used ring advances.
All public methods accept guest physical addresses (GPAs) and translate
them to slice offsets by subtracting gpa_base.
Implementations§
Source§impl GuestMemWriter
impl GuestMemWriter
Sourcepub unsafe fn new(ptr: *mut u8, len: usize, gpa_base: usize) -> GuestMemWriter
pub unsafe fn new(ptr: *mut u8, len: usize, gpa_base: usize) -> GuestMemWriter
Creates a new writer from the DeviceManager’s guest memory.
ptr must point to the host mapping of guest RAM, which starts
at GPA gpa_base. len is the size of that mapping in bytes.
§Safety
ptr must be valid for len bytes for the lifetime of the VM.
Sourcepub fn gpa_to_offset(&self, gpa: usize, access_len: usize) -> Option<usize>
pub fn gpa_to_offset(&self, gpa: usize, access_len: usize) -> Option<usize>
Translates a GPA to a host pointer offset, returning None if the
GPA falls below gpa_base (invalid) or the range exceeds the
mapped region.
Sourcepub unsafe fn slice_mut(&self, gpa: usize, len: usize) -> Option<&mut [u8]>
pub unsafe fn slice_mut(&self, gpa: usize, len: usize) -> Option<&mut [u8]>
Returns a mutable slice into guest memory at the given GPA range.
§Safety
Caller must ensure no other reference (mutable or shared) to the same GPA range exists for the lifetime of the returned slice. In practice, VirtIO descriptor ownership guarantees this — each descriptor buffer is exclusive to the device that owns it.
Sourcepub fn slice(&self, gpa: usize, len: usize) -> Option<&[u8]>
pub fn slice(&self, gpa: usize, len: usize) -> Option<&[u8]>
Returns an immutable slice into guest memory at the given GPA range.
Sourcepub fn read_u16(&self, gpa: usize) -> u16
pub fn read_u16(&self, gpa: usize) -> u16
Reads a little-endian u16 from the given GPA. Returns 0 on
out-of-bounds access.
Sourcepub fn write_u16(&self, gpa: usize, val: u16)
pub fn write_u16(&self, gpa: usize, val: u16)
Writes a little-endian u16 to the given GPA. No-op on
out-of-bounds access.
Sourcepub fn write_u32(&self, gpa: usize, val: u32)
pub fn write_u32(&self, gpa: usize, val: u32)
Writes a little-endian u32 to the given GPA. No-op on
out-of-bounds access.
Sourcepub fn write_byte(&self, gpa: usize, val: u8)
pub fn write_byte(&self, gpa: usize, val: u8)
Writes a single byte to the given GPA. No-op on out-of-bounds access.
Trait Implementations§
impl Send for GuestMemWriter
impl Sync for GuestMemWriter
Auto Trait Implementations§
impl Freeze for GuestMemWriter
impl RefUnwindSafe for GuestMemWriter
impl Unpin for GuestMemWriter
impl UnsafeUnpin for GuestMemWriter
impl UnwindSafe for GuestMemWriter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more