From 941e1e067aee7496029048a29e02677abea5696b Mon Sep 17 00:00:00 2001 From: sBubshait Date: Wed, 4 Dec 2024 17:51:30 +0000 Subject: [PATCH] Update SPT page entry to change type from EXECUTABLE to PAGE_FILE to capture mmaps in addition to executables --- src/userprog/exception.c | 2 +- src/userprog/process.c | 2 +- src/userprog/syscall.c | 8 +++++--- src/vm/page.c | 18 ------------------ src/vm/page.h | 2 +- 5 files changed, 8 insertions(+), 24 deletions(-) diff --git a/src/userprog/exception.c b/src/userprog/exception.c index 1e3ccc0..5e1d82e 100644 --- a/src/userprog/exception.c +++ b/src/userprog/exception.c @@ -194,7 +194,7 @@ try_fetch_page (void *upage, bool write) /* Load the page into memory based on the type of data it is expecting. */ bool success = false; switch (page->type) { - case PAGE_EXECUTABLE: + case PAGE_FILE: success = page_load (page, page->writable); break; default: diff --git a/src/userprog/process.c b/src/userprog/process.c index f4a7439..8d649e9 100644 --- a/src/userprog/process.c +++ b/src/userprog/process.c @@ -706,7 +706,7 @@ load_segment (struct file *file, off_t ofs, uint8_t *upage, /* Add the page metadata to the SPT to be lazy loaded later on */ if (page_insert (file, ofs, upage, page_read_bytes, page_zero_bytes, - writable, PAGE_EXECUTABLE) == NULL) + writable, PAGE_FILE) == NULL) return false; /* Advance. */ diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index 7e94048..16e345f 100644 --- a/src/userprog/syscall.c +++ b/src/userprog/syscall.c @@ -444,7 +444,7 @@ syscall_mmap (int fd, void *addr) off_t zero_bytes = PGSIZE - read_bytes; if (page_insert (file, ofs, addr + ofs, read_bytes, zero_bytes, true, - PAGE_EXECUTABLE) == NULL) + PAGE_FILE) == NULL) return MMAP_FAILURE; } @@ -457,9 +457,11 @@ syscall_mmap (int fd, void *addr) return mmap->mapping; } -/* Handles the syscall for unmapping a memory mapped file. */ +/* Handles the syscall for unmapping a memory mapped file. + + Pre: mapping is a valid mapping identifier returned by mmap syscall.*/ static void -syscall_munmap (mapid_t mapping UNUSED) +syscall_munmap (mapid_t mapping) { } diff --git a/src/vm/page.c b/src/vm/page.c index 010bd9d..18f718e 100644 --- a/src/vm/page.c +++ b/src/vm/page.c @@ -107,21 +107,3 @@ page_cleanup (struct hash_elem *e, void *aux UNUSED) { free (hash_entry (e, struct page_entry, elem)); } - -/* Updates the 'owner' thread's page table entry for virtual address 'upage' - to have a present bit of 0 and stores the specified swap slot value in the - entry for later retrieval from disk. */ -void -page_set_swap (struct thread *owner, void *upage, size_t swap_slot) -{ - -} - -/* Given that the page with user address 'upage' owned by 'owner' is flagged - to be in the swap disk via the owner's page table, returns its stored - swap slot. Otherwise panics the kernel. */ -size_t -page_get_swap (struct thread *owner, void *upage) -{ - -} \ No newline at end of file diff --git a/src/vm/page.h b/src/vm/page.h index 481f219..f4a4aba 100644 --- a/src/vm/page.h +++ b/src/vm/page.h @@ -5,7 +5,7 @@ #include "filesys/off_t.h" enum page_type { - PAGE_EXECUTABLE, + PAGE_FILE, PAGE_EMPTY };