From 44a73ecab6e91519627786a5101cd4f1a2f2b0d7 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Wed, 30 Oct 2024 00:57:33 +0200 Subject: most of the way to passing tests --- src/vmem.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/vmem.c') diff --git a/src/vmem.c b/src/vmem.c index f4f1bf7..bd0cd7c 100644 --- a/src/vmem.c +++ b/src/vmem.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -408,3 +409,25 @@ vmflags_t sanitize_uvflags(vmflags_t flags) { return (flags & (VM_R | VM_W | VM_X)) | VM_V | VM_U; } + +void handle_pagefault(vm_t addr) +{ + struct tcb *t = cur_tcb(); + struct tcb *p = get_cproc(t); + + size_t ref = __page(addr); + + struct mem_region *m = find_closest_used_region(&p->uvmem.region, addr); + if (!m || (ref < m->start || ref > m->end) || !is_region_used(m)) { + error("cannot handle actual page fault just yet :(\n"); + kernel_panic(NULL, NULL, 0); + return; + } + + /* this is a valid address so presumably the proc virtual memory has + * some changes that haven't been reflected over in our rpc virtual + * memory so make them visible */ + clone_uvmem(p->proc.vmem, t->rpc.vmem); + flush_tlb_all(); + return; +} -- cgit v1.3