Implement VM #63
@@ -252,7 +252,7 @@ fetch_page (void *upage, bool write)
|
||||
{
|
||||
/* Check if the page is in the supplemental page table. That is, it is a page
|
||||
that is expected to be in memory. */
|
||||
struct page_entry *page = page_get (upage);
|
||||
struct page_entry *page = page_get (thread_current (), upage);
|
||||
if (page == NULL)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -462,7 +462,7 @@ syscall_mmap (int fd, void *addr)
|
||||
hold the entire file. */
|
||||
for (off_t ofs = 0; ofs < file_size; ofs += PGSIZE)
|
||||
{
|
||||
if (page_get (addr + ofs) != NULL)
|
||||
if (page_get (thread_current (), addr + ofs) != NULL)
|
||||
return MMAP_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "mmap.h"
|
||||
#include "page.h"
|
||||
#include "threads/thread.h"
|
||||
#include "threads/vaddr.h"
|
||||
#include "threads/malloc.h"
|
||||
#include "userprog/syscall.h"
|
||||
@@ -70,7 +71,7 @@ mmap_unmap (struct mmap_entry *mmap)
|
||||
void *upage = mmap->upage + ofs;
|
||||
|
||||
/* Get the SPT page entry for this page. */
|
||||
struct page_entry *page = page_get(upage);
|
||||
struct page_entry *page = page_get(thread_current (), upage);
|
||||
if (page == NULL)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ struct page_entry *
|
||||
page_insert_swapped (void *upage, void *kpage, struct thread *owner)
|
||||
{
|
||||
/* 1. Initialize swapped page entry. */
|
||||
struct page_entry *page = page_get (upage);
|
||||
struct page_entry *page = page_get (thread_current (), upage);
|
||||
if (page == NULL)
|
||||
{
|
||||
page = malloc (sizeof (struct page_entry));
|
||||
@@ -103,13 +103,13 @@ page_insert_file (struct file *file, off_t ofs, void *upage,
|
||||
/* Gets a page_entry from the starting address of the page. Returns NULL if no
|
||||
such page_entry exists in the hash map.*/
|
||||
struct page_entry *
|
||||
page_get (void *upage)
|
||||
page_get (struct thread *thread, void *upage)
|
||||
{
|
||||
struct page_entry fake_page_entry;
|
||||
fake_page_entry.upage = upage;
|
||||
|
||||
struct hash_elem *e
|
||||
= hash_find (&thread_current ()->pages, &fake_page_entry.elem);
|
||||
= hash_find (&thread->pages, &fake_page_entry.elem);
|
||||
if (e == NULL)
|
||||
return NULL;
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ struct page_entry *page_insert_swapped (void *upage, void* kpage,
|
||||
struct page_entry *page_insert_file (struct file *file, off_t ofs, void *upage,
|
||||
uint32_t read_bytes, uint32_t zero_bytes,
|
||||
bool writable, enum page_type);
|
||||
struct page_entry *page_get (void *upage);
|
||||
struct page_entry *page_get (struct thread *thread, void *upage);
|
||||
bool page_load_file (struct page_entry *page, bool writable);
|
||||
void page_cleanup (struct hash_elem *e, void *aux);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user