From 31403ac7cb825f49fdc04db2a44c9d7f1999b897 Mon Sep 17 00:00:00 2001 From: Themis Demetriades Date: Fri, 6 Dec 2024 00:56:03 +0000 Subject: [PATCH] fix: obtain correct page table entry when performing eviction --- src/userprog/exception.c | 2 +- src/userprog/syscall.c | 2 +- src/vm/mmap.c | 3 ++- src/vm/page.c | 6 +++--- src/vm/page.h | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/userprog/exception.c b/src/userprog/exception.c index ca2911c..560d7b2 100644 --- a/src/userprog/exception.c +++ b/src/userprog/exception.c @@ -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; diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index b1a43dd..8275d51 100644 --- a/src/userprog/syscall.c +++ b/src/userprog/syscall.c @@ -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; } diff --git a/src/vm/mmap.c b/src/vm/mmap.c index b369650..64ad28f 100644 --- a/src/vm/mmap.c +++ b/src/vm/mmap.c @@ -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; diff --git a/src/vm/page.c b/src/vm/page.c index 56c6f30..fe71bb5 100644 --- a/src/vm/page.c +++ b/src/vm/page.c @@ -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; diff --git a/src/vm/page.h b/src/vm/page.h index be7a0aa..2d2f612 100644 --- a/src/vm/page.h +++ b/src/vm/page.h @@ -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);