pub enum Region {
Undefined {
address_bits: usize,
name: Str,
uuid: UUID,
},
Buffer {
address_bits: usize,
name: Str,
uuid: UUID,
offset: u64,
buffer: Arc<[u8]>,
},
File {
address_bits: usize,
name: Str,
uuid: UUID,
offset: u64,
file: Arc<Mmap>,
path: Option<PathBuf>,
file_offset: u64,
},
}Expand description
A continuous address space. Regions are an array of cells numbered from 0. Each cell is either
undefined of carries a single byte value.
Variants§
Undefined
All undefined values
Fields
address_bits: usizeAddressable space. All cells in a region have addresses between 0 and 2^address_bits - 1.
Buffer
In memory buffer
Fields
address_bits: usizeAddressable space. All cells in a region have addresses between 0 and 2^address_bits - 1.
name: StrHuman readable name. This name can vary over the livetime of a region and bears no semantic meaning. It’s for use in UIs.
File
Memory mapped file.
Fields
address_bits: usizeAddressable space. All cells in a region have addresses between 0 and 2^address_bits - 1.
name: StrHuman readable name. This name can vary over the livetime of a region and bears no semantic meaning. It’s for use in UIs.
Implementations§
Source§impl Region
impl Region
Sourcepub fn undefined<S, U>(name: S, address_bits: usize, uuid: U) -> Region
pub fn undefined<S, U>(name: S, address_bits: usize, uuid: U) -> Region
Creates a new completly undefined region with name and address_bits.
Sourcepub fn from_mmap<S, O, P, U>(
name: S,
address_bits: usize,
mmap: Mmap,
path: P,
file_offset: O,
offset: O,
uuid: U,
) -> Region
pub fn from_mmap<S, O, P, U>( name: S, address_bits: usize, mmap: Mmap, path: P, file_offset: O, offset: O, uuid: U, ) -> Region
Creates a new region called name that is address_bits large. Maps mmap to offset.
Sourcepub fn from_file<S, O, P, U>(
name: S,
address_bits: usize,
fd: File,
path: P,
offset: O,
uuid: U,
) -> Result<Region>
pub fn from_file<S, O, P, U>( name: S, address_bits: usize, fd: File, path: P, offset: O, uuid: U, ) -> Result<Region>
Creates a new region called name that is address_bits large. Maps fd to offset.
Sourcepub fn from_buf<S, O, B, U>(
name: S,
address_bits: usize,
buf: B,
offset: O,
uuid: U,
) -> Region
pub fn from_buf<S, O, B, U>( name: S, address_bits: usize, buf: B, offset: O, uuid: U, ) -> Region
Creates a new region called name that is address_bits large. Maps buf to offset.
Sourcepub fn file<'a>(&'a self) -> Option<(&'a Path, u64)>
pub fn file<'a>(&'a self) -> Option<(&'a Path, u64)>
If this is a mmap()’d file, return the path to it and mmap() starting position.
Sourcepub fn address_bits(&self) -> usize
pub fn address_bits(&self) -> usize
Size of this region.
Sourcepub fn read<'a>(&'a self, start: u64, len: usize) -> Result<&'a [u8]>
pub fn read<'a>(&'a self, start: u64, len: usize) -> Result<&'a [u8]>
Fill buf the the values starting at address. Fails if address..address + buf.len()
is outside of the addressable range or contains undefined values.
Sourcepub fn try_read(&self, address: u64, buf: &mut [u8]) -> Result<usize>
pub fn try_read(&self, address: u64, buf: &mut [u8]) -> Result<usize>
Trys to fill buf the the values starting at address. Returns early if address..address + buf.len()
contains undefined values and fails if it’s outside of the addressable range. Returns the number of bytes read.
Sourcepub fn read_integer(
&self,
address: u64,
endianess: Endianess,
bytes: usize,
) -> Result<u64>
pub fn read_integer( &self, address: u64, endianess: Endianess, bytes: usize, ) -> Result<u64>
Reads an bytes large integer from address and zero-extends it to an u64. Fails if address..address + bytes
is outside of the addressable range or contains undefined values.
Sourcepub fn in_range(&self, range: Range<u64>) -> bool
pub fn in_range(&self, range: Range<u64>) -> bool
Returns true if range is in the addressable space of this region, i.e. 0..address_bits^2 - .
Sourcepub fn is_defined(&self, range: Range<u64>) -> bool
pub fn is_defined(&self, range: Range<u64>) -> bool
Returns true if range is in the addressable space of this region and contains no undefined values.