diff --git a/src/userprog/exception.c b/src/userprog/exception.c index 1cd91dd..aae3690 100644 --- a/src/userprog/exception.c +++ b/src/userprog/exception.c @@ -170,12 +170,12 @@ page_fault (struct intr_frame *f) void *upage = pg_round_down (fault_addr); if (not_present && is_user_vaddr (upage) && upage != NULL) { + if (fetch_page (upage, write)) + return; + if (is_valid_stack_access (fault_addr, esp)) if (grow_stack (upage)) return; - - if (fetch_page (upage, write)) - return; } /* If the page fault occurred in kernel mode, then we intentionally indicate @@ -232,14 +232,14 @@ static bool grow_stack (void *upage) { /* Allocate new page for stack */ - void *kpage = palloc_get_page (PAL_USER | PAL_ZERO); - if (kpage == NULL) + void *new_page = frame_alloc (PAL_ZERO, upage, thread_current ()); + if (new_page == NULL) return false; /* Install the page into user page table */ - if (!install_page (upage, kpage, true)) + if (!pagedir_set_page (thread_current ()->pagedir, upage, new_page, true)) { - palloc_free_page (kpage); + frame_free (new_page); return false; }