From 38986193caf78ccb865c6ef362b8d186e28c8ee8 Mon Sep 17 00:00:00 2001 From: able Date: Sat, 4 May 2024 12:41:47 -0500 Subject: [PATCH] mem stuff --- .../holeybytes/kernel_services/mem_serve.rs | 69 ++++++++++++++++--- kernel/src/holeybytes/mem.rs | 1 - kernel/src/kmain.rs | 2 +- 3 files changed, 61 insertions(+), 11 deletions(-) diff --git a/kernel/src/holeybytes/kernel_services/mem_serve.rs b/kernel/src/holeybytes/kernel_services/mem_serve.rs index 30be8450..816f4be0 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 a53d66a3..e9024c57 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 c016f310..0c6790c0 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(); };