diff --git a/kernel/src/holeybytes/kernel_services/mem_serve.rs b/kernel/src/holeybytes/kernel_services/mem_serve.rs index 30be84504..816f4be05 100644 --- a/kernel/src/holeybytes/kernel_services/mem_serve.rs +++ b/kernel/src/holeybytes/kernel_services/mem_serve.rs @@ -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"), -// }; diff --git a/kernel/src/holeybytes/mem.rs b/kernel/src/holeybytes/mem.rs index a53d66a39..e9024c578 100644 --- a/kernel/src/holeybytes/mem.rs +++ b/kernel/src/holeybytes/mem.rs @@ -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(()) } diff --git a/kernel/src/kmain.rs b/kernel/src/kmain.rs index c016f310e..0c6790c0c 100644 --- a/kernel/src/kmain.rs +++ b/kernel/src/kmain.rs @@ -94,7 +94,7 @@ pub fn kmain(cmdline: &str, boot_modules: BootModules) -> ! { }); } - info!("{}", hardware_random_u64()); + info!("Random number: {}", hardware_random_u64()); executor.run(); };