Introduce concept of Process Resources (PR_MEM), implement necessary syscalls
All checks were successful
Build documentation / build-and-deploy (push) Successful in 42s

This commit is contained in:
2026-01-07 22:47:30 +01:00
parent 28aef30f77
commit d7b734306f
16 changed files with 451 additions and 50 deletions

View File

@@ -10,6 +10,7 @@
#include <mm/liballoc.h>
#include <mm/pmm.h>
#include <proc/proc.h>
#include <proc/resource.h>
#include <rd/rd.h>
#include <sync/spin_lock.h>
#include <sys/debug.h>
@@ -40,9 +41,6 @@ static bool proc_check_elf (uint8_t* elf) {
bool proc_map (struct proc* proc, uintptr_t start_paddr, uintptr_t start_vaddr, size_t pages,
uint32_t flags) {
DEBUG ("start_vaddr=%p, start_paddr=%p, pages=%zu, flags=%x\n", start_vaddr, start_paddr, pages,
flags);
struct proc_mapping* mapping = malloc (sizeof (*mapping));
if (mapping == NULL)
@@ -74,8 +72,6 @@ bool proc_unmap (struct proc* proc, uintptr_t start_vaddr, size_t pages) {
struct list_node_link *mapping_link, *mapping_link_tmp;
bool used_tail_mapping = false;
DEBUG ("start_vaddr=%p, pages=%zu\n", start_vaddr, pages);
struct proc_mapping* tail_mapping = malloc (sizeof (*tail_mapping));
if (tail_mapping == NULL)
return false;
@@ -154,9 +150,15 @@ struct elf_aux proc_load_segments (struct proc* proc, uint8_t* elf) {
size_t blks = div_align_up (phdr->p_memsz + off, PAGE_SIZE);
uintptr_t p_addr = pmm_alloc (blks);
if (p_addr == PMM_ALLOC_ERR)
int rid = atomic_fetch_add (&proc->rids, 1);
struct proc_resource_mem_init mem_init = {.pages = blks};
struct proc_resource* r =
proc_create_resource (proc, rid, PR_MEM, RV_PRIVATE, (void*)&mem_init);
if (r == NULL) {
DEBUG ("pmm oom error while loading ELF segments! (tried to alloc %zu blks)\n", blks);
}
uintptr_t p_addr = r->u.mem.paddr;
memset ((void*)((uintptr_t)hhdm->offset + p_addr), 0, blks * PAGE_SIZE);
memcpy ((void*)((uintptr_t)hhdm->offset + p_addr + off),
@@ -213,8 +215,11 @@ static struct proc* proc_find_sched (void) {
if (!node)
rbtree_first (&thiscpu->proc_run_q, node);
if (!node)
return NULL;
struct rb_node_link* first = node;
while (node) {
do {
proc = rbtree_entry (node, struct proc, cpu_run_q_link);
if (atomic_load (&proc->state) == PROC_READY)
@@ -228,7 +233,7 @@ static struct proc* proc_find_sched (void) {
if (node == first)
break;
}
} while (node != first);
return NULL;
}