Add a usermode address space which can be switched to, make

FRAME_ALLOCATOR global, make XunilFrameAllocator not hold Limine entries
so it can be used without lifetimes, implement the process struct, add
user heap by giving back heap_start from ELF and adding sbrk syscall,
align ELF loading in userspace_stub, implement lots of libc functions in
libxunil, remove x86_64 dependency from libxunil, add malloc and all
required heap functions to libxunil and more syscall numbers, add a util
file to libxunil, add build scripts for libxunil and doomgeneric
This commit is contained in:
csd4ni3l
2026-04-05 20:12:59 +02:00
parent 1e899e2f97
commit ae3915147a
26 changed files with 785 additions and 219 deletions

View File

@@ -1,10 +1,15 @@
use alloc::collections::btree_map::BTreeMap;
use lazy_static::lazy_static;
use crate::{arch::x86_64::paging::XunilFrameAllocator, task::process::Process, util::Locked};
use crate::{
arch::{arch::enter_usermode, x86_64::paging::XunilFrameAllocator},
task::process::Process,
util::Locked,
};
pub struct Scheduler {
pub processes: BTreeMap<u64, Process>,
pub current_process: i64,
next_pid: u64,
}
@@ -12,26 +17,31 @@ impl Scheduler {
pub const fn new() -> Scheduler {
Scheduler {
processes: BTreeMap::new(),
current_process: -1,
next_pid: 1,
}
}
}
impl Locked<Scheduler> {
pub fn spawn_process(
&self,
entry_point: u64,
frame_allocator: &mut XunilFrameAllocator,
) -> Option<u64> {
pub fn spawn_process(&self, entry_point: u64, stack_top: u64, heap_base: u64) -> 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)?;
let process = Process::new(pid, entry_point, stack_top, heap_base, heap_base)?;
guard.processes.insert(pid, process);
Some(pid)
}
pub fn run_process(&self, pid: u64, entry_point: *const u8) {
let mut guard = self.lock();
let stack_top = guard.processes[&pid].stack_top;
guard.current_process = pid as i64;
enter_usermode(entry_point as u64, (stack_top & !0xF) - 8);
}
pub fn with_process<F, R>(&self, index: u64, f: F) -> Option<R>
where
F: FnOnce(&mut Process) -> R,