Struct fuse_backend_rs::common::file_buf::FileVolatileSlice
source · pub struct FileVolatileSlice<'a> { /* private fields */ }
Expand description
An adapter structure to work around limitations of the vm-memory
crate.
It solves the compilation failure by masking out the vm_memory::BitmapSlice
generic type
parameter of vm_memory::VolatileSlice
.
Implementations§
source§impl<'a> FileVolatileSlice<'a>
impl<'a> FileVolatileSlice<'a>
sourcepub unsafe fn from_raw_ptr(addr: *mut u8, size: usize) -> Self
pub unsafe fn from_raw_ptr(addr: *mut u8, size: usize) -> Self
Create a new instance of FileVolatileSlice
from a raw pointer.
§Safety
To use this safely, the caller must guarantee that the memory at addr
is size
bytes long
and is available for the duration of the lifetime of the new FileVolatileSlice.
The caller must also guarantee that all other users of the given chunk of memory are using
volatile accesses.
§Example
let mut buffer = [0u8; 1024];
let s = unsafe { FileVolatileSlice::from_raw_ptr(buffer.as_mut_ptr(), buffer.len()) };
{
let o: u32 = s.load(0x10, Ordering::Acquire).unwrap();
assert_eq!(o, 0);
s.store(1u8, 0x10, Ordering::Release).unwrap();
let s2 = s.as_volatile_slice();
let s3 = FileVolatileSlice::from_volatile_slice(&s2);
assert_eq!(s3.len(), 1024);
}
assert_eq!(buffer[0x10], 1);
sourcepub unsafe fn from_mut_slice(buf: &'a mut [u8]) -> Self
pub unsafe fn from_mut_slice(buf: &'a mut [u8]) -> Self
Create a new instance of FileVolatileSlice
from a mutable slice.
§Safety
The caller must guarantee that all other users of the given chunk of memory are using volatile accesses.
sourcepub fn from_volatile_slice<S: BitmapSlice>(s: &VolatileSlice<'a, S>) -> Self
pub fn from_volatile_slice<S: BitmapSlice>(s: &VolatileSlice<'a, S>) -> Self
Create a new FileVolatileSlice
from vm_memory::VolatileSlice
and strip off the
vm_memory::BitmapSlice
.
The caller needs to handle dirty page tracking for the data buffer.
sourcepub fn as_volatile_slice(&self) -> VolatileSlice<'a, ()>
pub fn as_volatile_slice(&self) -> VolatileSlice<'a, ()>
Create a vm_memory::VolatileSlice
from FileVolatileSlice without dirty page tracking.
sourcepub unsafe fn borrow_as_buf(&self, inited: bool) -> FileVolatileBuf
pub unsafe fn borrow_as_buf(&self, inited: bool) -> FileVolatileBuf
Borrow as a FileVolatileSlice object to temporarily elide the lifetime parameter.
§Safety
The FileVolatileSlice is borrowed without a lifetime parameter, so the caller must ensure that FileVolatileBuf doesn’t out-live the borrowed FileVolatileSlice object.
Trait Implementations§
source§impl<'a> Bytes<usize> for FileVolatileSlice<'a>
impl<'a> Bytes<usize> for FileVolatileSlice<'a>
source§fn write(&self, buf: &[u8], addr: usize) -> Result<usize, Self::E>
fn write(&self, buf: &[u8], addr: usize) -> Result<usize, Self::E>
addr
. Read moresource§fn read(&self, buf: &mut [u8], addr: usize) -> Result<usize, Self::E>
fn read(&self, buf: &mut [u8], addr: usize) -> Result<usize, Self::E>
addr
into a slice. Read moresource§fn write_slice(&self, buf: &[u8], addr: usize) -> Result<(), Self::E>
fn write_slice(&self, buf: &[u8], addr: usize) -> Result<(), Self::E>
addr
. Read moresource§fn read_slice(&self, buf: &mut [u8], addr: usize) -> Result<(), Self::E>
fn read_slice(&self, buf: &mut [u8], addr: usize) -> Result<(), Self::E>
addr
to fill an entire slice. Read moresource§fn read_from<F>(
&self,
addr: usize,
src: &mut F,
count: usize,
) -> Result<usize, Self::E>where
F: Read,
fn read_from<F>(
&self,
addr: usize,
src: &mut F,
count: usize,
) -> Result<usize, Self::E>where
F: Read,
source§fn read_exact_from<F>(
&self,
addr: usize,
src: &mut F,
count: usize,
) -> Result<(), Self::E>where
F: Read,
fn read_exact_from<F>(
&self,
addr: usize,
src: &mut F,
count: usize,
) -> Result<(), Self::E>where
F: Read,
source§fn write_to<F>(
&self,
addr: usize,
dst: &mut F,
count: usize,
) -> Result<usize, Self::E>where
F: Write,
fn write_to<F>(
&self,
addr: usize,
dst: &mut F,
count: usize,
) -> Result<usize, Self::E>where
F: Write,
source§fn write_all_to<F>(
&self,
addr: usize,
dst: &mut F,
count: usize,
) -> Result<(), Self::E>where
F: Write,
fn write_all_to<F>(
&self,
addr: usize,
dst: &mut F,
count: usize,
) -> Result<(), Self::E>where
F: Write,
source§fn store<T: AtomicAccess>(
&self,
val: T,
addr: usize,
order: Ordering,
) -> Result<(), Self::E>
fn store<T: AtomicAccess>( &self, val: T, addr: usize, order: Ordering, ) -> Result<(), Self::E>
source§fn load<T: AtomicAccess>(
&self,
addr: usize,
order: Ordering,
) -> Result<T, Self::E>
fn load<T: AtomicAccess>( &self, addr: usize, order: Ordering, ) -> Result<T, Self::E>
source§impl<'a> Clone for FileVolatileSlice<'a>
impl<'a> Clone for FileVolatileSlice<'a>
source§fn clone(&self) -> FileVolatileSlice<'a>
fn clone(&self) -> FileVolatileSlice<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'a> Debug for FileVolatileSlice<'a>
impl<'a> Debug for FileVolatileSlice<'a>
impl<'a> Copy for FileVolatileSlice<'a>
Auto Trait Implementations§
impl<'a> Freeze for FileVolatileSlice<'a>
impl<'a> RefUnwindSafe for FileVolatileSlice<'a>
impl<'a> Send for FileVolatileSlice<'a>
impl<'a> Sync for FileVolatileSlice<'a>
impl<'a> Unpin for FileVolatileSlice<'a>
impl<'a> UnwindSafe for FileVolatileSlice<'a>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)