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
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.
uuid: UuidImmutable UUID. The UUID of a region never changes. Can be used for housekeeping and associating additional data with this region.
All undefined values
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.
uuid: UuidImmutable UUID. The UUID of a region never changes. Can be used for housekeeping and associating additional data with this region.
offset: u64Positon of the buffer in the address space.
In memory buffer
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.
uuid: UuidImmutable UUID. The UUID of a region never changes. Can be used for housekeeping and associating additional data with this region.
offset: u64Positon of the file in the address space.
file_offset: u64Start of mapping inside file
Memory mapped file.
Implementations
sourceimpl Region
impl Region
sourcepub fn undefined<S: Into<Str>>(name: S, address_bits: usize) -> Region
pub fn undefined<S: Into<Str>>(name: S, address_bits: usize) -> Region
Creates a new completly undefined region with name and address_bits.
sourcepub fn from_mmap<S, O, P>(
name: S,
address_bits: usize,
mmap: Mmap,
path: P,
file_offset: O,
offset: O
) -> Regionwhere
S: Into<Str>,
O: Into<Option<u64>>,
P: Into<Option<PathBuf>>,
pub fn from_mmap<S, O, P>(
name: S,
address_bits: usize,
mmap: Mmap,
path: P,
file_offset: O,
offset: O
) -> Regionwhere
S: Into<Str>,
O: Into<Option<u64>>,
P: Into<Option<PathBuf>>,
Creates a new region called name that is address_bits large. Maps mmap to offset.
sourcepub fn from_file<S, O, P>(
name: S,
address_bits: usize,
fd: File,
path: P,
offset: O
) -> Result<Region>where
S: Into<Str>,
O: Into<Option<u64>>,
P: Into<Option<PathBuf>>,
pub fn from_file<S, O, P>(
name: S,
address_bits: usize,
fd: File,
path: P,
offset: O
) -> Result<Region>where
S: Into<Str>,
O: Into<Option<u64>>,
P: Into<Option<PathBuf>>,
Creates a new region called name that is address_bits large. Maps fd to offset.
sourcepub fn from_buf<S: Into<Str>, O: Into<Option<u64>>, B: Into<Arc<[u8]>>>(
name: S,
address_bits: usize,
buf: B,
offset: O
) -> Region
pub fn from_buf<S: Into<Str>, O: Into<Option<u64>>, B: Into<Arc<[u8]>>>(
name: S,
address_bits: usize,
buf: B,
offset: O
) -> 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.