feat: merged shared-read-only-executables with the rest of VM

This commit is contained in:
Themis Demetriades
2024-12-06 04:15:13 +00:00
8 changed files with 479 additions and 101 deletions

View File

@@ -2,21 +2,20 @@
#include <inttypes.h>
#include <stdio.h>
#include "stdbool.h"
#include "threads/synch.h"
#include "userprog/gdt.h"
#include "userprog/pagedir.h"
#include "userprog/process.h"
#include "threads/interrupt.h"
#include "threads/palloc.h"
#include "threads/thread.h"
#include "threads/vaddr.h"
#ifdef VM
#include "vm/frame.h"
#include "vm/page.h"
#include "devices/swap.h"
#include "threads/vaddr.h"
#include "userprog/pagedir.h"
#endif
#define MAX_STACK_SIZE (8 * 1024 * 1024) // 8MB
#define MAX_STACK_OFFSET 32 // 32 bytes offset below stack pointer (ESP)
/* Number of page faults processed. */
static long long page_fault_cnt;
@@ -188,6 +187,7 @@ page_fault (struct intr_frame *f)
return;
}
/* To implement virtual memory, delete the rest of the function
body, and replace it with code that brings in the page to
which fault_addr refers. */
@@ -262,24 +262,24 @@ fetch_page (void *upage, bool write)
frame. */
struct thread *t = thread_current ();
if (page_in_swap (t, upage))
{
/* NOTE: This code should be refactored and moved into helper functions
within 'page.c'.*/
void *kpage = frame_alloc (0, upage, t);
lock_acquire (&page->lock);
{
/* NOTE: This code should be refactored and moved into helper functions
within 'page.c'.*/
void *kpage = frame_alloc (0, upage, t);
lock_acquire (&page->lock);
size_t swap_slot = page_get_swap (t, upage);
swap_in (kpage, swap_slot);
size_t swap_slot = page_get_swap (t, upage);
swap_in (kpage, swap_slot);
lock_release (&page->lock);
lock_release (&page->lock);
bool writeable = pagedir_is_writable (t->pagedir, upage);
bool writeable = pagedir_is_writable (t->pagedir, upage);
/* TODO: When this returns false we should quit the page fault,
but currently we continue and check the stack conditions in the
page fault handler. */
return pagedir_set_page (t->pagedir, upage, kpage, writeable);
}
/* TODO: When this returns false we should quit the page fault,
but currently we continue and check the stack conditions in the
page fault handler. */
return pagedir_set_page (t->pagedir, upage, kpage, writeable);
}
/* An attempt to write to a non-writeable should fail. */
if (write && !page->writable)
@@ -290,7 +290,8 @@ fetch_page (void *upage, bool write)
switch (page->type) {
case PAGE_MMAP:
case PAGE_FILE:
success = page_load_file (page, page->writable);
case PAGE_SHARED:
success = page_load_file (page);
break;
default:
return false;