Implement implicitly unmapping all mmapped files when a process exits. Refactor to reduce duplication
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "threads/malloc.h"
|
||||
#include "userprog/syscall.h"
|
||||
#include "userprog/pagedir.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static unsigned mmap_hash (const struct hash_elem *e, void *aux);
|
||||
static bool mmap_less (const struct hash_elem *a_, const struct hash_elem *b_,
|
||||
@@ -85,11 +86,8 @@ mmap_unmap (struct mmap_entry *mmap)
|
||||
hash_delete (&thread_current ()->pages, &page->elem);
|
||||
}
|
||||
|
||||
/* Remove the mapping from the mmap table. Close the file and free the mmap
|
||||
entry. */
|
||||
hash_delete (&thread_current ()->mmap_files, &mmap->elem);
|
||||
file_close (mmap->file);
|
||||
free(mmap);
|
||||
free (mmap);
|
||||
}
|
||||
|
||||
/* Destroys the mmap table for the current thread. Frees all the memory
|
||||
@@ -120,14 +118,13 @@ 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. */
|
||||
/* Cleans up the mmap table for the current thread. Implicitly unmaps the mmap
|
||||
entry, freeing pages and writing back to the file if necessary. */
|
||||
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);
|
||||
mmap_unmap (mmap);
|
||||
}
|
||||
|
||||
/* Updates the 'owner' thread's page table entry for virtual address 'upage'
|
||||
|
||||
Reference in New Issue
Block a user