feat(domain): add memory module with page pool, per-process tracking, and region table

This commit is contained in:
2026-10-17 23:45:17 +02:00
parent 021b2d83b9
commit ed80fc43a6
8 changed files with 437 additions and 13 deletions

View File

@@ -0,0 +1,47 @@
use types::id::ProcessId;
use crate::error::KernelError;
pub struct ProcessMemory {
process: ProcessId,
page_count: usize,
limit: usize,
}
impl ProcessMemory {
pub fn new(process: ProcessId, limit: usize) -> Self {
Self {
process,
page_count: 0,
limit,
}
}
pub fn process(&self) -> ProcessId {
self.process
}
pub fn page_count(&self) -> usize {
self.page_count
}
pub fn limit(&self) -> usize {
self.limit
}
pub fn grant(&mut self, count: usize) -> Result<(), KernelError> {
if self.page_count + count > self.limit {
return Err(KernelError::OutOfMemory);
}
self.page_count += count;
Ok(())
}
pub fn release(&mut self, count: usize) -> Result<(), KernelError> {
if count > self.page_count {
return Err(KernelError::OutOfMemory);
}
self.page_count -= count;
Ok(())
}
}