Trait multiboot::information::MemoryManagement
source · pub trait MemoryManagement {
// Required methods
unsafe fn paddr_to_slice(
&self,
addr: PAddr,
length: usize
) -> Option<&'static [u8]>;
unsafe fn allocate(&mut self, length: usize) -> Option<(PAddr, &mut [u8])>;
unsafe fn deallocate(&mut self, addr: PAddr);
}
Expand description
Implement this trait to be able to get or set fields containing a pointer.
Memory translation, allocation and deallocation happens here.
Required Methods§
sourceunsafe fn paddr_to_slice(
&self,
addr: PAddr,
length: usize
) -> Option<&'static [u8]>
unsafe fn paddr_to_slice( &self, addr: PAddr, length: usize ) -> Option<&'static [u8]>
Translates physical addr + size into a kernel accessible slice.
The simplest paddr_to_slice function would for example be just the identity function. But this may vary depending on how your page table layout looks like.
If you only want to set fields, this can just always return None
.
§Safety
Pretty unsafe. Translate a physical buffer in multiboot into something accessible in the current address space. Probably involves querying/knowledge about page-table setup. Also might want to verify that multiboot information is actually valid.
sourceunsafe fn allocate(&mut self, length: usize) -> Option<(PAddr, &mut [u8])>
unsafe fn allocate(&mut self, length: usize) -> Option<(PAddr, &mut [u8])>
Allocates length
bytes.
The returned tuple consists of the physical address (that goes into the struct) and the slice which to use to write to.
If you only want to read fields, this can just always return None
.
§Safety
Lifetime of buffer should be >= self.
sourceunsafe fn deallocate(&mut self, addr: PAddr)
unsafe fn deallocate(&mut self, addr: PAddr)
Free the previously allocated memory.
This should handle null pointers by doing nothing.
If you only want to read fields, this can just always panic.
§Safety
TBD.