From 72fa0c1bbbb6f7d2367c9132a3cdada153a9c1b1 Mon Sep 17 00:00:00 2001 From: sBubshait Date: Wed, 4 Dec 2024 17:41:14 +0000 Subject: [PATCH] Fix Bug: Initialise the mmap table for the newly created thread rather than the current thread --- src/threads/thread.c | 2 +- src/vm/mmap.c | 6 +++--- src/vm/mmap.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/threads/thread.c b/src/threads/thread.c index 214a458..e95a40a 100644 --- a/src/threads/thread.c +++ b/src/threads/thread.c @@ -278,7 +278,7 @@ thread_create (const char *name, int priority, #endif #ifdef VM - mmap_init (); + mmap_init (t); #endif /* Prepare thread for first run by initializing its stack. diff --git a/src/vm/mmap.c b/src/vm/mmap.c index 1f78040..3d6bd79 100644 --- a/src/vm/mmap.c +++ b/src/vm/mmap.c @@ -6,11 +6,11 @@ static bool mmap_less (const struct hash_elem *a_, const struct hash_elem *b_, void *aux); static void mmap_cleanup(struct hash_elem *e, void *aux); -/* Initializes the mmap table for the current thread. Sets the counter to 0. */ +/* Initializes the mmap table for the given thread, setting the mmap counter to + 0 and initializing the hash table. */ bool -mmap_init (void) +mmap_init (struct thread *t) { - struct thread *t = thread_current (); t->mmap_counter = 0; return hash_init (&t->mmap_files, mmap_hash, mmap_less, NULL); } diff --git a/src/vm/mmap.h b/src/vm/mmap.h index c4a6208..a64210a 100644 --- a/src/vm/mmap.h +++ b/src/vm/mmap.h @@ -17,7 +17,7 @@ struct mmap_entry { struct hash_elem elem; /* An elem for the hash table. */ }; -bool mmap_init (void); +bool mmap_init (struct thread *t); struct mmap_entry *mmap_insert (struct file *file, void *upage); void mmap_destroy (void);