Add a mmap destroy function to cleanup all mmap hash table entries upon thread exit

This commit is contained in:
sBubshait
2024-12-04 15:14:02 +00:00
parent 1ce09a49a1
commit a2f46f3b72
3 changed files with 22 additions and 0 deletions

View File

@@ -33,3 +33,21 @@ mmap_less (const struct hash_elem *a_, const struct hash_elem *b_,
return a->mapping < b->mapping;
}
/* Cleans up the mmap table for the current thread. Frees the memory allocated
for the mmap entry. */
static void
mmap_cleanup (struct hash_elem *e, void *aux UNUSED)
{
struct mmap_entry *mmap = hash_entry (e, struct mmap_entry, elem);
file_close (mmap->file);
free (mmap);
}
/* Destroys the mmap table for the current thread. Frees all the memory
allocated for the mmap entries. */
void
mmap_destroy (void)
{
hash_destroy (&thread_current ()->mmap_files, mmap_cleanup);
}