feat(domain): add memory module with page pool, per-process tracking, and region table
This commit is contained in:
47
crates/domain/src/memory/process_memory.rs
Normal file
47
crates/domain/src/memory/process_memory.rs
Normal 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(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user