fix: extract supplemental and shared_files initialisation
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
#else
|
||||
#include "tests/threads/tests.h"
|
||||
#endif
|
||||
#include "vm/page.h"
|
||||
#ifdef VM
|
||||
#include "vm/frame.h"
|
||||
#include "devices/swap.h"
|
||||
@@ -121,6 +122,7 @@ main (void)
|
||||
exception_init ();
|
||||
syscall_init ();
|
||||
#endif
|
||||
shared_files_init ();
|
||||
|
||||
/* Start thread scheduler and enable interrupts. */
|
||||
thread_start ();
|
||||
|
||||
@@ -134,10 +134,6 @@ thread_start (void)
|
||||
t))
|
||||
PANIC ("Failed to initialise child results table for main thread.");
|
||||
|
||||
/* Initialise the shared files table and lock. */
|
||||
if (!hash_init (&shared_files, shared_file_hash, shared_file_less, NULL))
|
||||
PANIC ("Failed to initialise shared pages table.");
|
||||
|
||||
lock_init (&shared_files_lock);
|
||||
|
||||
/* Create the idle thread. */
|
||||
@@ -272,7 +268,7 @@ thread_create (const char *name, int priority,
|
||||
if (!hash_init (&t->open_files, fd_hash, fd_less, NULL)
|
||||
|| !hash_init (&t->child_results, process_result_hash,
|
||||
process_result_less, t)
|
||||
|| !hash_init (&t->pages, page_hash, page_less, NULL))
|
||||
|| !init_pages (t))
|
||||
{
|
||||
palloc_free_page (t);
|
||||
free (t->result);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -43,20 +43,15 @@ struct shared_page_entry {
|
||||
struct hash_elem elem;
|
||||
};
|
||||
|
||||
unsigned page_hash (const struct hash_elem *e, void *aux);
|
||||
bool page_less (const struct hash_elem *a_, const struct hash_elem *b_,
|
||||
void *aux);
|
||||
bool init_pages (struct thread *t);
|
||||
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);
|
||||
void page_cleanup (struct hash_elem *e, void *aux);
|
||||
void page_cleanup (struct hash_elem *e, void *aux UNUSED);
|
||||
|
||||
unsigned shared_file_hash (const struct hash_elem *e, void *aux);
|
||||
bool shared_file_less (const struct hash_elem *a_, const struct hash_elem *b_,
|
||||
void *aux);
|
||||
struct shared_page_entry *shared_page_get (struct file *file, void *upage);
|
||||
void shared_files_init ();
|
||||
|
||||
void page_set_swap (struct thread *, void *, size_t);
|
||||
size_t page_get_swap (struct thread *, void *);
|
||||
|
||||
Reference in New Issue
Block a user