mem stuff

This commit is contained in:
able 2024-05-04 12:41:47 -05:00
parent 779f3bdd1f
commit 38986193ca
3 changed files with 61 additions and 11 deletions

View file

@ -4,12 +4,20 @@ use {
kernel_services::{block_read, mem_serve},
Vm,
},
log::info,
alloc::alloc::alloc_zeroed,
log::{debug, info},
};
pub enum MemoryServiceError {
InvalidMemoryFormat,
}
#[derive(Debug)]
pub enum MemoryQuotaType {
NoQuota = 0,
SoftQuota = 1,
HardQuota = 2,
KillQuota = 3,
}
fn alloc_page(vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), MemoryServiceError> {
let mut val = alloc::vec::Vec::new();
@ -28,14 +36,57 @@ pub fn memory_msg_handler(
length: usize,
) -> Result<(), MemoryServiceError> {
let mut msg_vec = block_read(mem_addr, length);
let msg_type = msg_vec[0];
msg_vec.remove(0);
match msg_type {
0 => {
let page_count = msg_vec[0];
msg_vec.remove(0);
// let mptr_raw: [u8; 8] = msg_vec[0..8].try_into().unwrap();
// let mptr: u64 = u64::from_le_bytes(mptr_raw);
// log::debug!("Allocating {} pages @ {}", page_count, mptr);
let mut val = alloc::vec::Vec::new();
for _ in 0..(page_count as isize * 4096) {
val.push(0);
}
vm.registers[1] = hbvm::value::Value(val.as_ptr() as u64);
}
1 => {
let page_count = msg_vec[0];
msg_vec.remove(0);
}
2 => {
use MemoryQuotaType::*;
let quota_type = match msg_vec[0] {
0 => NoQuota,
1 => SoftQuota,
2 => HardQuota,
3 => KillQuota,
_ => NoQuota,
};
msg_vec.remove(0);
let hid_raw: [u8; 8] = msg_vec[0..8].try_into().unwrap();
let hid: u64 = u64::from_le_bytes(hid_raw);
for _ in 0..8 {
msg_vec.remove(0);
}
let pid_raw: [u8; 8] = msg_vec[0..8].try_into().unwrap();
let pid: u64 = u64::from_le_bytes(hid_raw);
for _ in 0..8 {
msg_vec.remove(0);
}
debug!(
"Setting HID-{:x}:PID-{:x}'s quota type to {:?}",
hid, pid, quota_type
)
}
_ => {}
}
Ok(())
}
// match memory_msg_handler(vm, mem_addr, length) {
// Ok(()) => {
// let free_chunks = allocator::get_free_chunks_count();
// debug!("Free chunk count: {}", free_chunks);
// }
// Err(err) => log::error!("Improper log format"),
// };

View file

@ -39,7 +39,6 @@ impl hbvm::mem::Memory for Memory {
) -> Result<(), hbvm::mem::LoadError> {
use log::{error, info};
if addr.get() % 4096 == 0 {}
info!("a");
core::ptr::copy(addr.get() as *const u8, target, count);
Ok(())
}

View file

@ -94,7 +94,7 @@ pub fn kmain(cmdline: &str, boot_modules: BootModules) -> ! {
});
}
info!("{}", hardware_random_u64());
info!("Random number: {}", hardware_random_u64());
executor.run();
};