Update mmap to add a get helper function to find a mmap entry from its mapping

This commit is contained in:
sBubshait
2024-12-04 18:08:05 +00:00
parent 941e1e067a
commit 857cae3578
2 changed files with 16 additions and 0 deletions

View File

@@ -15,6 +15,21 @@ mmap_init (struct thread *t)
return hash_init (&t->mmap_files, mmap_hash, mmap_less, NULL);
}
struct mmap_entry *
mmap_get (mapid_t mapping)
{
struct mmap_entry fake_mmap_entry;
fake_mmap_entry.mapping = mapping;
struct hash_elem *e
= hash_find (&thread_current ()->mmap_files, &fake_mmap_entry.elem);
if (e == NULL)
return NULL;
return hash_entry (e, struct mmap_entry, elem);
}
/* Inserts a new mmap entry into the mmap table for the current thread. Upage
is the start address of the file data in the user VM. */
struct mmap_entry *

View File

@@ -18,6 +18,7 @@ struct mmap_entry {
};
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_destroy (void);