pub trait MemoryMapper {
// Required methods
fn remap_range(
&self,
range: &Range<usize>,
set: u64,
clr: u64,
) -> Result<(), &str>;
fn query_range(&self, range: &Range<usize>) -> Option<u64>;
}Expand description
An implementation of this trait must be provided to the EFI runtime at initialization time so that the PE/COFF loader as well as the Memory Attributes Protocol implementation exposed by the EFI runtime are able to manage permission attributes on memory ranges.
§Example
struct MemoryMapper;
impl efiloader::MemoryMapper for MemoryMapper {
fn remap_range(&self, range: &Range<usize>, set: u64, clr: u64) -> Result<(), &str> {
let prot = libc::PROT_READ
| match clr & !set {
EFI_MEMORY_RO => libc::PROT_WRITE,
EFI_MEMORY_XP => libc::PROT_EXEC,
0 => 0,
_ => libc::PROT_WRITE | libc::PROT_EXEC,
};
unsafe { libc::mprotect(range.start as *mut _, range.end - range.start, prot) };
Ok(())
}
fn query_range(&self, _range: &Range<usize>) -> Option<u64> {
todo!();
}
}