2023-10-27 20:26:04 -05:00
|
|
|
//! Security? Multiple address spaces? What are you talking about
|
|
|
|
//! young adventurer. In this temple, we know no such words.
|
|
|
|
//!
|
|
|
|
//! Want your program to override other program's data or even the
|
|
|
|
//! data of the kernel itself? Sure. This right shall not be infringed.
|
|
|
|
|
|
|
|
use hbvm::mem::Address;
|
|
|
|
|
|
|
|
pub struct Memory;
|
|
|
|
impl hbvm::mem::Memory for Memory {
|
|
|
|
#[inline]
|
|
|
|
unsafe fn load(
|
|
|
|
&mut self,
|
|
|
|
addr: Address,
|
|
|
|
target: *mut u8,
|
|
|
|
count: usize,
|
|
|
|
) -> Result<(), hbvm::mem::LoadError> {
|
2023-11-02 14:08:48 -05:00
|
|
|
log::info!("Loading memory");
|
2023-10-27 20:26:04 -05:00
|
|
|
core::ptr::copy(addr.get() as *const u8, target, count);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
unsafe fn store(
|
|
|
|
&mut self,
|
|
|
|
addr: Address,
|
|
|
|
source: *const u8,
|
|
|
|
count: usize,
|
|
|
|
) -> Result<(), hbvm::mem::StoreError> {
|
2023-11-02 14:12:10 -05:00
|
|
|
// log::info!("Storing memory");
|
2023-11-02 14:08:48 -05:00
|
|
|
|
2023-10-27 20:26:04 -05:00
|
|
|
core::ptr::copy(source, addr.get() as *mut u8, count);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
unsafe fn prog_read<T: Copy>(&mut self, addr: Address) -> T {
|
|
|
|
(addr.get() as *const T).read()
|
|
|
|
}
|
|
|
|
}
|