fix: modify stack growth to use frame allocation to allow for page swapping

This commit is contained in:
EDiasAlberto
2024-12-05 04:39:50 +00:00
parent 16db01d3d8
commit e779e8ac7c

View File

@@ -170,12 +170,12 @@ page_fault (struct intr_frame *f)
void *upage = pg_round_down (fault_addr); void *upage = pg_round_down (fault_addr);
if (not_present && is_user_vaddr (upage) && upage != NULL) if (not_present && is_user_vaddr (upage) && upage != NULL)
{ {
if (fetch_page (upage, write))
return;
if (is_valid_stack_access (fault_addr, esp)) if (is_valid_stack_access (fault_addr, esp))
if (grow_stack (upage)) if (grow_stack (upage))
return; return;
if (fetch_page (upage, write))
return;
} }
/* If the page fault occurred in kernel mode, then we intentionally indicate /* If the page fault occurred in kernel mode, then we intentionally indicate
@@ -232,14 +232,14 @@ static bool
grow_stack (void *upage) grow_stack (void *upage)
{ {
/* Allocate new page for stack */ /* Allocate new page for stack */
void *kpage = palloc_get_page (PAL_USER | PAL_ZERO); void *new_page = frame_alloc (PAL_ZERO, upage, thread_current ());
if (kpage == NULL) if (new_page == NULL)
return false; return false;
/* Install the page into user page table */ /* 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; return false;
} }