From e88a8c4c379d721e9901752d440a05295087da11 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 19 Jun 2012 01:44:56 +0200 Subject: implement page table and use it for lazy loading of segments --- userprog/exception.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'userprog/exception.c') diff --git a/userprog/exception.c b/userprog/exception.c index 17620ad..54621fa 100644 --- a/userprog/exception.c +++ b/userprog/exception.c @@ -5,6 +5,7 @@ #include "threads/interrupt.h" #include "threads/thread.h" #include "threads/vaddr.h" +#include "vm/page.h" /* Number of page faults processed. */ static long long page_fault_cnt; @@ -121,12 +122,13 @@ kill (struct intr_frame *f) description of "Interrupt 14--Page Fault Exception (#PF)" in [IA32-v3a] section 5.15 "Exception and Interrupt Reference". */ static void -page_fault (struct intr_frame *f) +page_fault (struct intr_frame *f) { bool not_present; /* True: not-present page, false: writing r/o page. */ bool write; /* True: access was write, false: access was read. */ bool user; /* True: access by user, false: access by kernel. */ void *fault_addr; /* Fault address. */ + struct page_table_entry *pte; /* Obtain faulting address, the virtual address that was accessed to cause the fault. It may point to code or to @@ -153,6 +155,17 @@ page_fault (struct intr_frame *f) body, adding code that brings in the page to which fault_addr refers. */ if (is_user_vaddr(fault_addr)) { + pte = page_table_fetch (&thread_current ()->page_table, pg_round_down (fault_addr)); + if (pte != NULL) + page_load (pte); + else + { + printf ("Page fault %p\n", pte); + kill (f); + } + + //TODO +#if 0 if (! user) { /* syscall exception; set eax and eip */ f->eip = (void*)f->eax; @@ -162,6 +175,7 @@ page_fault (struct intr_frame *f) /* user process access violation */ thread_exit(); } +#endif } else { printf ("Page fault at %p: %s error %s page in %s context.\n", fault_addr, -- cgit v1.2.3