fix: obtain correct page table entry when performing eviction

This commit is contained in:
Themis Demetriades
2024-12-06 00:56:03 +00:00
parent 8220b931a9
commit 31403ac7cb
5 changed files with 8 additions and 7 deletions

View File

@@ -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 /* Check if the page is in the supplemental page table. That is, it is a page
that is expected to be in memory. */ 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) if (page == NULL)
return false; return false;

View File

@@ -462,7 +462,7 @@ syscall_mmap (int fd, void *addr)
hold the entire file. */ hold the entire file. */
for (off_t ofs = 0; ofs < file_size; ofs += PGSIZE) 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; return MMAP_FAILURE;
} }

View File

@@ -1,5 +1,6 @@
#include "mmap.h" #include "mmap.h"
#include "page.h" #include "page.h"
#include "threads/thread.h"
#include "threads/vaddr.h" #include "threads/vaddr.h"
#include "threads/malloc.h" #include "threads/malloc.h"
#include "userprog/syscall.h" #include "userprog/syscall.h"
@@ -70,7 +71,7 @@ mmap_unmap (struct mmap_entry *mmap)
void *upage = mmap->upage + ofs; void *upage = mmap->upage + ofs;
/* Get the SPT page entry for this page. */ /* 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) if (page == NULL)
continue; continue;

View File

@@ -47,7 +47,7 @@ struct page_entry *
page_insert_swapped (void *upage, void *kpage, struct thread *owner) page_insert_swapped (void *upage, void *kpage, struct thread *owner)
{ {
/* 1. Initialize swapped page entry. */ /* 1. Initialize swapped page entry. */
struct page_entry *page = page_get (upage); struct page_entry *page = page_get (thread_current (), upage);
if (page == NULL) if (page == NULL)
{ {
page = malloc (sizeof (struct page_entry)); 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 /* Gets a page_entry from the starting address of the page. Returns NULL if no
such page_entry exists in the hash map.*/ such page_entry exists in the hash map.*/
struct page_entry * struct page_entry *
page_get (void *upage) page_get (struct thread *thread, void *upage)
{ {
struct page_entry fake_page_entry; struct page_entry fake_page_entry;
fake_page_entry.upage = upage; fake_page_entry.upage = upage;
struct hash_elem *e struct hash_elem *e
= hash_find (&thread_current ()->pages, &fake_page_entry.elem); = hash_find (&thread->pages, &fake_page_entry.elem);
if (e == NULL) if (e == NULL)
return NULL; return NULL;

View File

@@ -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, struct page_entry *page_insert_file (struct file *file, off_t ofs, void *upage,
uint32_t read_bytes, uint32_t zero_bytes, uint32_t read_bytes, uint32_t zero_bytes,
bool writable, enum page_type); 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); bool page_load_file (struct page_entry *page, bool writable);
void page_cleanup (struct hash_elem *e, void *aux); void page_cleanup (struct hash_elem *e, void *aux);