Better proc_kill () and process cleanup
All checks were successful
Build documentation / build-and-deploy (push) Successful in 27s

This commit is contained in:
2026-01-06 01:19:11 +01:00
parent 6538fd8023
commit a8423fe657
10 changed files with 216 additions and 116 deletions

View File

@@ -1,5 +1,6 @@
#include <amd64/gdt.h>
#include <aux/elf.h>
#include <libk/list.h>
#include <libk/std.h>
#include <libk/string.h>
#include <limine/requests.h>
@@ -41,10 +42,8 @@ struct proc* proc_from_elf (uint8_t* elf_contents) {
pmm_free (kernel_stack, USTACK_SIZE / PAGE_SIZE);
return NULL;
}
uintptr_t user_stack = proc->pdata.user_stack;
proc->pdata.user_stack += USTACK_SIZE;
proc_map (proc, user_stack, PROC_USTACK_TOP - USTACK_SIZE, USTACK_SIZE / PAGE_SIZE,
proc_map (proc, proc->pdata.user_stack, PROC_USTACK_TOP - USTACK_SIZE, USTACK_SIZE / PAGE_SIZE,
MM_PG_USER | MM_PG_PRESENT | MM_PG_RW);
struct elf_aux aux = proc_load_segments (proc, elf_contents);
@@ -60,3 +59,26 @@ struct proc* proc_from_elf (uint8_t* elf_contents) {
return proc;
}
void proc_cleanup (struct proc* proc) {
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
struct proc_mapping *mapping, *mapping_tmp;
spin_lock (&proc->pd.lock);
linklist_foreach (proc->mappings, mapping, mapping_tmp) {
pmm_free (mapping->paddr, mapping->size / PAGE_SIZE);
linklist_remove (struct proc_mapping*, proc->mappings, mapping);
free (mapping);
}
spin_unlock (&proc->pd.lock);
pmm_free (proc->pd.cr3_paddr, 1);
pmm_free (proc->pdata.kernel_stack - (uintptr_t)hhdm->offset - KSTACK_SIZE,
KSTACK_SIZE / PAGE_SIZE);
pmm_free (proc->pdata.user_stack, USTACK_SIZE / PAGE_SIZE);
free (proc);
}