From fa58ae1e6a35501f8e8d69a7c5f82f019c95cd0f Mon Sep 17 00:00:00 2001 From: An N Tran <antran@caltech.edu> Date: Thu, 17 Nov 2022 17:00:46 +0000 Subject: [PATCH] Task 4 --- kernel.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel.c b/kernel.c index 6224e2f..3e2b33c 100644 --- a/kernel.c +++ b/kernel.c @@ -173,7 +173,7 @@ void process_setup(pid_t pid, const char* program_name) { ptable[pid].regs.reg_rip = pgm.entry(); // allocate and map stack segment - uintptr_t stack_addr = PROC_START_ADDR + PROC_SIZE * pid - PAGESIZE; + uintptr_t stack_addr = MEMSIZE_VIRTUAL - PAGESIZE; uintptr_t pa = (uintptr_t) kalloc(PAGESIZE); memory_map(process_pagetable, stack_addr, pa, PTE_PWU); ptable[pid].regs.reg_rsp = stack_addr + PAGESIZE; @@ -325,6 +325,7 @@ uintptr_t syscall(regstate* regs) { int syscall_page_alloc(uintptr_t addr) { uintptr_t pa = (uintptr_t) kalloc(PAGESIZE); + if (pa == 0) return -1; memory_map(current->pagetable, addr, pa, PTE_PWU); memset(memory_virtual_to_physical(current->pagetable, addr), 0, PAGESIZE); return 0; -- GitLab