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'
|
||||
|
||||
@@ -21,6 +21,7 @@ bool mmap_init (struct thread *t);
|
||||
struct mmap_entry *mmap_get (mapid_t mapping);
|
||||
struct mmap_entry *mmap_insert (struct file *file, void *upage);
|
||||
void mmap_unmap (struct mmap_entry *mmap);
|
||||
void mmap_umap_all (void);
|
||||
void mmap_destroy (void);
|
||||
|
||||
#endif /* vm/mmap.h */
|
||||
|
||||
@@ -59,7 +59,6 @@ page_get (void *upage)
|
||||
|
||||
struct hash_elem *e
|
||||
= hash_find (&thread_current ()->pages, &fake_page_entry.elem);
|
||||
|
||||
if (e == NULL)
|
||||
return NULL;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user