Add a scheduler which just keeps of processes for now, and a

with_process to interact with them. User space now has it's own address
space and mapper which means we will be able to allocate memory for it.
I added a bunch of functions as stubs into libxunil which are required
for doomgeneric.
This commit is contained in:
csd4ni3l
2026-04-03 11:28:31 +02:00
parent 720b68190d
commit 1e899e2f97
28 changed files with 535 additions and 57 deletions

View File

@@ -0,0 +1,45 @@
use alloc::collections::btree_map::BTreeMap;
use lazy_static::lazy_static;
use crate::{arch::x86_64::paging::XunilFrameAllocator, task::process::Process, util::Locked};
pub struct Scheduler {
pub processes: BTreeMap<u64, Process>,
next_pid: u64,
}
impl Scheduler {
pub const fn new() -> Scheduler {
Scheduler {
processes: BTreeMap::new(),
next_pid: 1,
}
}
}
impl Locked<Scheduler> {
pub fn spawn_process(
&self,
entry_point: u64,
frame_allocator: &mut XunilFrameAllocator,
) -> Option<u64> {
let mut guard = self.lock();
let pid = guard.next_pid;
guard.next_pid += 1;
let process = Process::new(pid, entry_point, frame_allocator)?;
guard.processes.insert(pid, process);
Some(pid)
}
pub fn with_process<F, R>(&self, index: u64, f: F) -> Option<R>
where
F: FnOnce(&mut Process) -> R,
{
let mut guard = self.lock();
let process = guard.processes.get_mut(&index)?;
Some(f(process))
}
}
pub static SCHEDULER: Locked<Scheduler> = Locked::new(Scheduler::new());