diff --git a/src/threads/thread.c b/src/threads/thread.c index c2944cc..abf50d4 100644 --- a/src/threads/thread.c +++ b/src/threads/thread.c @@ -134,6 +134,9 @@ thread_start (void) t)) PANIC ("Failed to initialise child results table for main thread."); + if (!hash_init (&shared_files, shared_file_hash, shared_file_less, NULL)) + PANIC ("Failed to initialise shared pages table."); + /* Create the idle thread. */ struct semaphore idle_started; sema_init (&idle_started, 0); diff --git a/src/vm/page.c b/src/vm/page.c index f21a3a7..d8b31c7 100644 --- a/src/vm/page.c +++ b/src/vm/page.c @@ -1,15 +1,15 @@ #include "page.h" #include -#include #include "filesys/file.h" #include "threads/malloc.h" #include "threads/palloc.h" #include "userprog/process.h" #include "vm/frame.h" -static struct hash shared_files; - static struct shared_file_entry *shared_file_get (struct file *file); +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); /* Hashing function needed for the SPT table. Returns a hash for an entry, based on its upage. */ @@ -135,14 +135,14 @@ shared_file_less (const struct hash_elem *a_, const struct hash_elem *b_, /* Hashing function needed for the shared pages table. Returns a hash for an entry based on its user virtual address (upage) pointer. */ -unsigned +static unsigned shared_page_hash (const struct hash_elem *e, void *aux UNUSED) { return hash_ptr (hash_entry (e, struct shared_page_entry, elem)->upage); } /* Less function needed for the shared pages table. */ -bool +static bool shared_page_less (const struct hash_elem *a_, const struct hash_elem *b_, void *aux UNUSED) { @@ -238,5 +238,5 @@ page_set_swap (struct thread *owner, void *upage, size_t swap_slot) size_t page_get_swap (struct thread *owner, void *upage) { - + return 0; } diff --git a/src/vm/page.h b/src/vm/page.h index 6a9ffe3..312e481 100644 --- a/src/vm/page.h +++ b/src/vm/page.h @@ -4,6 +4,8 @@ #include "threads/thread.h" #include "filesys/off_t.h" +struct hash shared_files; + enum page_type { PAGE_EXECUTABLE, PAGE_EMPTY @@ -47,6 +49,12 @@ struct page_entry *page_insert (struct file *file, off_t ofs, void *upage, 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); + +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 page_set_swap (struct thread *, void *, size_t); size_t page_get_swap (struct thread *, void *);