pub struct VolatileSlice<'a, B = ()> { /* private fields */ }Expand description
A slice of raw memory that supports volatile access.
Implementations§
Source§impl<'a> VolatileSlice<'a, ()>
impl<'a> VolatileSlice<'a, ()>
Sourcepub unsafe fn new(addr: *mut u8, size: usize) -> VolatileSlice<'a>
pub unsafe fn new(addr: *mut u8, size: usize) -> VolatileSlice<'a>
Creates a slice of raw memory that must support volatile access.
§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 VolatileSlice. The caller
must also guarantee that all other users of the given chunk of memory are using volatile
accesses.
Source§impl<'a, B: BitmapSlice> VolatileSlice<'a, B>
impl<'a, B: BitmapSlice> VolatileSlice<'a, B>
Sourcepub unsafe fn with_bitmap(
addr: *mut u8,
size: usize,
bitmap: B,
mmap: Option<&'a MmapInfo>,
) -> VolatileSlice<'a, B>
pub unsafe fn with_bitmap( addr: *mut u8, size: usize, bitmap: B, mmap: Option<&'a MmapInfo>, ) -> VolatileSlice<'a, B>
Creates a slice of raw memory that must support volatile access, and uses the provided
bitmap object for dirty page tracking.
§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 VolatileSlice. The caller
must also guarantee that all other users of the given chunk of memory are using volatile
accesses.
Sourcepub fn ptr_guard_mut(&self) -> PtrGuardMut
pub fn ptr_guard_mut(&self) -> PtrGuardMut
Returns a mutable guard for the pointer to the underlying memory.
Sourcepub fn split_at(&self, mid: usize) -> Result<(Self, Self)>
pub fn split_at(&self, mid: usize) -> Result<(Self, Self)>
Divides one slice into two at an index.
§Example
let vslice = VolatileSlice::from(&mut mem[..]);
let (start, end) = vslice.split_at(8).expect("Could not split VolatileSlice");
assert_eq!(8, start.len());
assert_eq!(24, end.len());Sourcepub fn subslice(&self, offset: usize, count: usize) -> Result<Self>
pub fn subslice(&self, offset: usize, count: usize) -> Result<Self>
Returns a subslice of this VolatileSlice starting at
offset with count length.
The returned subslice is a copy of this slice with the address increased by offset bytes
and the size set to count bytes.
Sourcepub fn offset(&self, count: usize) -> Result<VolatileSlice<'a, B>>
pub fn offset(&self, count: usize) -> Result<VolatileSlice<'a, B>>
Returns a subslice of this VolatileSlice starting at
offset.
The returned subslice is a copy of this slice with the address increased by count bytes
and the size reduced by count bytes.
Sourcepub fn copy_to<T>(&self, buf: &mut [T]) -> usizewhere
T: ByteValued,
pub fn copy_to<T>(&self, buf: &mut [T]) -> usizewhere
T: ByteValued,
Copies as many elements of type T as possible from this slice to buf.
Copies self.len() or buf.len() times the size of T bytes, whichever is smaller,
to buf. The copy happens from smallest to largest address in T sized chunks
using volatile reads.
§Examples
let mut mem = [0u8; 32];
let vslice = VolatileSlice::from(&mut mem[..]);
let mut buf = [5u8; 16];
let res = vslice.copy_to(&mut buf[..]);
assert_eq!(16, res);
for &v in &buf[..] {
assert_eq!(v, 0);
}Sourcepub fn copy_to_volatile_slice<S: BitmapSlice>(
&self,
slice: VolatileSlice<'_, S>,
)
pub fn copy_to_volatile_slice<S: BitmapSlice>( &self, slice: VolatileSlice<'_, S>, )
Copies as many bytes as possible from this slice to the provided slice.
The copies happen in an undefined order.
§Examples
vslice.copy_to_volatile_slice(
vslice
.get_slice(16, 16)
.expect("Could not get VolatileSlice"),
);Sourcepub fn copy_from<T>(&self, buf: &[T])where
T: ByteValued,
pub fn copy_from<T>(&self, buf: &[T])where
T: ByteValued,
Copies as many elements of type T as possible from buf to this slice.
The copy happens from smallest to largest address in T sized chunks using volatile writes.
§Examples
let mut mem = [0u8; 32];
let vslice = VolatileSlice::from(&mut mem[..]);
let buf = [5u8; 64];
vslice.copy_from(&buf[..]);
for i in 0..4 {
let val = vslice
.get_ref::<u32>(i * 4)
.expect("Could not get value")
.load();
assert_eq!(val, 0x05050505);
}Trait Implementations§
Source§impl<B: BitmapSlice> Bytes<usize> for VolatileSlice<'_, B>
impl<B: BitmapSlice> Bytes<usize> for VolatileSlice<'_, B>
Source§fn write(&self, buf: &[u8], addr: usize) -> Result<usize>
fn write(&self, buf: &[u8], addr: usize) -> Result<usize>
§Examples
- Write a slice of size 5 at offset 1020 of a 1024-byte
VolatileSlice.
let mut mem = [0u8; 1024];
let vslice = VolatileSlice::from(&mut mem[..]);
let res = vslice.write(&[1, 2, 3, 4, 5], 1020);
assert!(res.is_ok());
assert_eq!(res.unwrap(), 4);Source§fn read(&self, buf: &mut [u8], addr: usize) -> Result<usize>
fn read(&self, buf: &mut [u8], addr: usize) -> Result<usize>
§Examples
- Read a slice of size 16 at offset 1010 of a 1024-byte
VolatileSlice.
let mut mem = [0u8; 1024];
let vslice = VolatileSlice::from(&mut mem[..]);
let buf = &mut [0u8; 16];
let res = vslice.read(buf, 1010);
assert!(res.is_ok());
assert_eq!(res.unwrap(), 14);Source§fn write_slice(&self, buf: &[u8], addr: usize) -> Result<()>
fn write_slice(&self, buf: &[u8], addr: usize) -> Result<()>
§Examples
- Write a slice at offset 256.
let res = vslice.write_slice(&[1, 2, 3, 4, 5], 256);
assert!(res.is_ok());
assert_eq!(res.unwrap(), ());Source§fn read_slice(&self, buf: &mut [u8], addr: usize) -> Result<()>
fn read_slice(&self, buf: &mut [u8], addr: usize) -> Result<()>
§Examples
- Read a slice of size 16 at offset 256.
let buf = &mut [0u8; 16];
let res = vslice.read_slice(buf, 256);
assert!(res.is_ok());Source§fn read_volatile_from<F>(
&self,
addr: usize,
src: &mut F,
count: usize,
) -> Result<usize>where
F: ReadVolatile,
fn read_volatile_from<F>(
&self,
addr: usize,
src: &mut F,
count: usize,
) -> Result<usize>where
F: ReadVolatile,
count bytes from src and writes them into the container at addr.
Unlike VolatileRead::read_volatile, this function retries on EINTR being returned from
the underlying I/O read operation. Read moreSource§fn read_exact_volatile_from<F>(
&self,
addr: usize,
src: &mut F,
count: usize,
) -> Result<()>where
F: ReadVolatile,
fn read_exact_volatile_from<F>(
&self,
addr: usize,
src: &mut F,
count: usize,
) -> Result<()>where
F: ReadVolatile,
Source§fn write_volatile_to<F>(
&self,
addr: usize,
dst: &mut F,
count: usize,
) -> Result<usize>where
F: WriteVolatile,
fn write_volatile_to<F>(
&self,
addr: usize,
dst: &mut F,
count: usize,
) -> Result<usize>where
F: WriteVolatile,
count bytes from the container at addr and writes them into dst.
Unlike VolatileWrite::write_volatile, this function retries on EINTR being returned by
the underlying I/O write operation. Read moreSource§fn write_all_volatile_to<F>(
&self,
addr: usize,
dst: &mut F,
count: usize,
) -> Result<()>where
F: WriteVolatile,
fn write_all_volatile_to<F>(
&self,
addr: usize,
dst: &mut F,
count: usize,
) -> Result<()>where
F: WriteVolatile,
Source§fn store<T: AtomicAccess>(
&self,
val: T,
addr: usize,
order: Ordering,
) -> Result<()>
fn store<T: AtomicAccess>( &self, val: T, addr: usize, order: Ordering, ) -> Result<()>
Source§fn load<T: AtomicAccess>(&self, addr: usize, order: Ordering) -> Result<T>
fn load<T: AtomicAccess>(&self, addr: usize, order: Ordering) -> Result<T>
Source§impl<'a, B: Clone> Clone for VolatileSlice<'a, B>
impl<'a, B: Clone> Clone for VolatileSlice<'a, B>
Source§fn clone(&self) -> VolatileSlice<'a, B>
fn clone(&self) -> VolatileSlice<'a, B>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a, B: Debug> Debug for VolatileSlice<'a, B>
impl<'a, B: Debug> Debug for VolatileSlice<'a, B>
Source§impl<'a, B: BitmapSlice> From<VolatileSlice<'a, B>> for VolatileArrayRef<'a, u8, B>
impl<'a, B: BitmapSlice> From<VolatileSlice<'a, B>> for VolatileArrayRef<'a, u8, B>
Source§fn from(slice: VolatileSlice<'a, B>) -> Self
fn from(slice: VolatileSlice<'a, B>) -> Self
Source§impl<B: BitmapSlice> VolatileMemory for VolatileSlice<'_, B>
impl<B: BitmapSlice> VolatileMemory for VolatileSlice<'_, B>
Source§fn as_volatile_slice(&self) -> VolatileSlice<'_, BS<'_, Self::B>>
fn as_volatile_slice(&self) -> VolatileSlice<'_, BS<'_, Self::B>>
Source§fn get_ref<T: ByteValued>(
&self,
offset: usize,
) -> Result<VolatileRef<'_, T, BS<'_, Self::B>>>
fn get_ref<T: ByteValued>( &self, offset: usize, ) -> Result<VolatileRef<'_, T, BS<'_, Self::B>>>
VolatileRef at offset.Source§fn get_array_ref<T: ByteValued>(
&self,
offset: usize,
n: usize,
) -> Result<VolatileArrayRef<'_, T, BS<'_, Self::B>>>
fn get_array_ref<T: ByteValued>( &self, offset: usize, n: usize, ) -> Result<VolatileArrayRef<'_, T, BS<'_, Self::B>>>
Source§unsafe fn aligned_as_ref<T: ByteValued>(&self, offset: usize) -> Result<&T>
unsafe fn aligned_as_ref<T: ByteValued>(&self, offset: usize) -> Result<&T>
Source§unsafe fn aligned_as_mut<T: ByteValued>(&self, offset: usize) -> Result<&mut T>
unsafe fn aligned_as_mut<T: ByteValued>(&self, offset: usize) -> Result<&mut T>
T at offset. Mutable accesses performed
using the resulting reference are not automatically accounted for by the dirty bitmap
tracking functionality. Read moreSource§fn get_atomic_ref<T: AtomicInteger>(&self, offset: usize) -> Result<&T>
fn get_atomic_ref<T: AtomicInteger>(&self, offset: usize) -> Result<&T>
T at offset. Mutable accesses performed
using the resulting reference are not automatically accounted for by the dirty bitmap
tracking functionality. Read more