embedded_shadow/view/
kernel.rs

1use crate::table::ShadowTable;
2
3pub struct KernelView<'a, const TS: usize, const BS: usize, const BC: usize>
4where
5    bitmaps::BitsImpl<BC>: bitmaps::Bits,
6{
7    table: &'a mut ShadowTable<TS, BS, BC>,
8}
9
10impl<'a, const TS: usize, const BS: usize, const BC: usize> KernelView<'a, TS, BS, BC>
11where
12    bitmaps::BitsImpl<BC>: bitmaps::Bits,
13{
14    pub(crate) fn new(table: &'a mut ShadowTable<TS, BS, BC>) -> Self {
15        Self { table }
16    }
17}
18
19impl<'a, const TS: usize, const BS: usize, const BC: usize> KernelView<'a, TS, BS, BC>
20where
21    bitmaps::BitsImpl<BC>: bitmaps::Bits,
22{
23    pub fn read_range(&self, addr: u16, out: &mut [u8]) -> Result<(), crate::ShadowError> {
24        self.table.read_range(addr, out)
25    }
26
27    pub fn write_range(&mut self, addr: u16, data: &[u8]) -> Result<(), crate::ShadowError> {
28        self.table.write_range(addr, data)?;
29        Ok(())
30    }
31
32    pub fn for_each_dirty_block<F>(&self, mut f: F) -> Result<(), crate::ShadowError>
33    where
34        F: FnMut(u16, &[u8]) -> Result<(), crate::ShadowError>,
35    {
36        self.table.for_each_dirty_block(|addr, data| f(addr, data))
37    }
38
39    pub fn is_dirty(&self, addr: u16, len: usize) -> Result<bool, crate::ShadowError> {
40        self.table.is_dirty(addr, len)
41    }
42
43    pub fn any_dirty(&self) -> bool {
44        self.table.any_dirty()
45    }
46
47    pub fn clear_dirty(&mut self) {
48        self.table.clear_dirty()
49    }
50}