diff --git a/src/userprog/exception.c b/src/userprog/exception.c index 4e104d5..39a8173 100644 --- a/src/userprog/exception.c +++ b/src/userprog/exception.c @@ -158,6 +158,16 @@ page_fault (struct intr_frame *f) #ifdef VM struct thread *t = thread_current (); void *upage = pg_round_down (fault_addr); + + /* If the fault address is in a user page that is not present, then it might + be an executable file page that needs to be lazily loaded. So, we check the + SPT to determine if this is the case, and if so load the page from disk. */ + if (not_present && is_user_vaddr (upage)) + { + if (try_fetch_page (upage, write)) + return; + } + if (user) { if (not_present) @@ -193,15 +203,6 @@ page_fault (struct intr_frame *f) f->eax = 0xffffffff; return; } - - /* If the fault address is in a user page that is not present, then it might - just need to be lazily loaded. So, we check our SPT to see if the page - is expected to have data loaded in memory. */ - if (not_present && is_user_vaddr (upage) && upage != NULL) - { - if (try_fetch_page (upage, write)) - return; - } #endif /* To implement virtual memory, delete the rest of the function