fix: don't discriminate between user and kernel page fault contexts for stack growth, lazy loading, and swapping

This commit is contained in:
Themis Demetriades
2024-12-04 23:46:31 +00:00
parent 60faf995ea
commit 0288e13206

View File

@@ -156,22 +156,12 @@ page_fault (struct intr_frame *f)
user = (f->error_code & PF_U) != 0; user = (f->error_code & PF_U) != 0;
#ifdef VM #ifdef VM
struct thread *t = thread_current ();
void *upage = pg_round_down (fault_addr); void *upage = pg_round_down (fault_addr);
if (not_present && is_user_vaddr(upage))
{
struct thread *t = thread_current ();
void *esp = user ? f->esp : t->curr_esp;
/* 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)
{
/* Check if the non-present user page is in the swap partition. /* Check if the non-present user page is in the swap partition.
If so, swap it back into main memory, updating the PTE for If so, swap it back into main memory, updating the PTE for
the faulted virtual address to point to the newly allocated the faulted virtual address to point to the newly allocated
@@ -189,16 +179,19 @@ page_fault (struct intr_frame *f)
/* Handle user page faults that need to be resolved by dynamic /* Handle user page faults that need to be resolved by dynamic
stack growth by checking if this is such a fault and responding stack growth by checking if this is such a fault and responding
accordingly. */ accordingly. */
if (handle_stack_fault (fault_addr, f->esp)) return; if (handle_stack_fault (fault_addr, esp)) return;
}
}
else
{
/* 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;
/* Handle user page faults that need to be resolved by lazy loading
of executable files by checking if they contain entries in the
SPT hash map and responding accordingly. */
if (try_fetch_page (upage, write))
return;
}
/* Allows for page faults within a kernel context to communicate with
user pages for sending error codes. */
if (!user)
{
f->eip = (void *)f->eax; f->eip = (void *)f->eax;
f->eax = 0xffffffff; f->eax = 0xffffffff;
return; return;