fix: extract supplemental and shared_files initialisation

This commit is contained in:
2024-12-04 11:17:46 +00:00
parent 10bfffc4b0
commit f2aba977b4
4 changed files with 28 additions and 14 deletions

View File

@@ -9,17 +9,29 @@
#include "userprog/process.h"
#include "vm/frame.h"
static unsigned page_hash (const struct hash_elem *e, void *aux UNUSED);
static bool page_less (const struct hash_elem *a_, const struct hash_elem *b_,
void *aux UNUSED);
static struct shared_page_entry *shared_page_insert (struct file *file,
void *upage, void *frame);
static struct shared_file_entry *shared_file_get (struct file *file);
static struct shared_page_entry *shared_page_get (struct file *file,
void *upage);
static unsigned shared_page_hash (const struct hash_elem *e, void *aux UNUSED);
static bool shared_page_less (const struct hash_elem *a_,
const struct hash_elem *b_, void *aux UNUSED);
/* Initialise a thread's supplemental pages table. */
bool
init_pages (struct thread *t)
{
return hash_init (&t->pages, page_hash, page_less, NULL);
}
/* Hashing function needed for the SPT table. Returns a hash for an entry,
based on its upage. */
unsigned
page_hash (const struct hash_elem *e, UNUSED void *aux)
page_hash (const struct hash_elem *e, void *aux UNUSED)
{
struct page_entry *page = hash_entry (e, struct page_entry, elem);
return hash_ptr(page->upage);
@@ -167,6 +179,15 @@ page_cleanup (struct hash_elem *e, void *aux UNUSED)
free (page);
}
/* Initialise the shared files and table and lock. */
bool
shared_files_init ()
{
lock_init (&shared_files_lock);
if (!hash_init (&shared_files, shared_file_hash, shared_file_less, NULL))
PANIC ("Failed to initialise shared_files table.");
}
/* Hashing function needed for the shared_file table. Returns a hash for an
entry based on its file pointer. */
unsigned