fix: don't discriminate between user and kernel page fault contexts for stack growth, lazy loading, and swapping
This commit is contained in:
@@ -156,22 +156,12 @@ page_fault (struct intr_frame *f)
|
||||
user = (f->error_code & PF_U) != 0;
|
||||
|
||||
#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;
|
||||
}
|
||||
struct thread *t = thread_current ();
|
||||
void *esp = user ? f->esp : t->curr_esp;
|
||||
|
||||
if (user)
|
||||
{
|
||||
if (not_present)
|
||||
{
|
||||
/* 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
|
||||
@@ -189,16 +179,19 @@ page_fault (struct intr_frame *f)
|
||||
/* 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
|
||||
{
|
||||
/* 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;
|
||||
if (handle_stack_fault (fault_addr, 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->eax = 0xffffffff;
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user