feat: implement page swapping
This commit is contained in:
@@ -1,10 +1,18 @@
|
||||
#include "userprog/exception.h"
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include "stdbool.h"
|
||||
#include "userprog/gdt.h"
|
||||
#include "threads/interrupt.h"
|
||||
#include "threads/thread.h"
|
||||
#include "userprog/pagedir.h"
|
||||
#ifdef VM
|
||||
#include "vm/stackgrowth.h"
|
||||
#include "vm/frame.h"
|
||||
#include "vm/page.h"
|
||||
#include "devices/swap.h"
|
||||
#include "threads/vaddr.h"
|
||||
#endif
|
||||
|
||||
/* Number of page faults processed. */
|
||||
static long long page_fault_cnt;
|
||||
@@ -147,9 +155,26 @@ page_fault (struct intr_frame *f)
|
||||
user = (f->error_code & PF_U) != 0;
|
||||
|
||||
#ifdef VM
|
||||
if (user && not_present)
|
||||
if (user)
|
||||
{
|
||||
if (handle_stack_fault (fault_addr, f->esp)) return;
|
||||
if (not_present)
|
||||
{
|
||||
struct thread *t = thread_current ();
|
||||
if (page_in_swap (t, fault_addr))
|
||||
{
|
||||
size_t swap_slot = page_get_swap (t, fault_addr);
|
||||
void *upage = pg_round_down (fault_addr);
|
||||
void *kpage = frame_alloc (0, upage, t);
|
||||
swap_in (kpage, swap_slot);
|
||||
|
||||
bool writeable = pagedir_is_writable (t->pagedir, upage);
|
||||
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. */
|
||||
if (handle_stack_fault (fault_addr, f->esp)) return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user