diff --git a/src/userprog/exception.c b/src/userprog/exception.c index 6c707b1..7c4f2ad 100644 --- a/src/userprog/exception.c +++ b/src/userprog/exception.c @@ -155,11 +155,15 @@ page_fault (struct intr_frame *f) user = (f->error_code & PF_U) != 0; #ifdef VM + struct thread *t = thread_current (); if (user) { if (not_present) { - struct thread *t = thread_current (); + /* Check if the non-present user page is in the swap partition. + If so, swap it back into main memory, updating the PTE for + the faulted virtual address to point to the newly allocated + frame. */ if (page_in_swap (t, fault_addr)) { size_t swap_slot = page_get_swap (t, fault_addr); @@ -171,15 +175,18 @@ page_fault (struct intr_frame *f) if (pagedir_set_page (t->pagedir, upage, kpage, writeable)) return; } - /* Handle page faults that need to be resolved by dynamic stack growth - by checking if this is such a fault and resolving it appropriately. */ + /* Handle user page faults that need to be resolved by dynamic + stack growth by checking if this is such a fault and responding + accordingly. */ if (handle_stack_fault (fault_addr, f->esp)) return; } } else { - /* Allows for stack growth in kernel context, due to syscall failure */ - if (handle_stack_fault (fault_addr, thread_current ()->curr_esp)) return; + /* Handle kernel page faults that need to be resolved by dynamic stack + growth by checking if this is such a fault and responding + accordingly. */ + if (not_present && handle_stack_fault (fault_addr, t->curr_esp)) return; f->eip = (void *)f->eax; f->eax = 0xffffffff;