Implement page fault for lazy loading executables, w/ G

This commit is contained in:
sBubshait
2024-11-28 20:03:50 +00:00
parent df20e0fdfe
commit 801fd7d310
136 changed files with 15097 additions and 5 deletions

View File

@@ -1,5 +1,11 @@
#include "page.h"
#include <string.h>
#include <stdio.h>
#include "filesys/file.h"
#include "threads/malloc.h"
#include "threads/palloc.h"
#include "userprog/process.h"
#include "vm/frame.h"
/* Hashing function needed for the SPT table. Returns a hash for an entry,
based on its upage. */
@@ -45,7 +51,7 @@ page_insert (struct file *file, off_t ofs, void *upage, uint32_t read_bytes,
/* Gets a page_entry from the starting address of the page. Returns NULL if no
such page_entry exists in the hash map.*/
static struct page_entry *
struct page_entry *
page_get (void *upage)
{
struct page_entry fake_page_entry;
@@ -60,6 +66,36 @@ page_get (void *upage)
return hash_entry (e, struct page_entry, elem);
}
bool
page_load (struct page_entry *page, bool writable)
{
void *frame = frame_alloc (PAL_USER, page->upage, thread_current());
if (frame == NULL)
return false; // TODO: Try to evict a page instead.
if (!install_page (page->upage, frame, writable))
{
frame_free (frame);
return false;
}
printf ("Hi! 3\n");
file_seek (page->file, page->offset);
int read = -1;
if ((read = file_read (page->file, frame, page->read_bytes)) != (int) page->read_bytes)
{
printf ("%p, %p, %d %d\n", page->file, frame, read, page->offset);
frame_free (frame);
return false;
}
printf ("Hi! 4\n");
memset (frame + page->read_bytes, 0, page->zero_bytes);
return true;
}
/* Function to clean up a page_entry. Given the elem of that page_entry, frees
the page_entry itself. */
void

View File

@@ -29,6 +29,8 @@ bool page_less (const struct hash_elem *a_, const struct hash_elem *b_,
struct page_entry *page_insert (struct file *file, off_t ofs, void *upage,
uint32_t read_bytes, uint32_t zero_bytes,
bool writable, enum page_type type);
struct page_entry *page_get (void *upage);
bool page_load (struct page_entry *page, bool writable);
void page_cleanup (struct hash_elem *e, void *aux);
void page_set_swap (struct thread *, void *, size_t);
size_t page_get_swap (struct thread *, void *);