From e61e868b265efe2f6d51079373588d639fc54d59 Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 21 Jun 2012 18:14:58 +0200 Subject: full mmap implementation --- vm/page.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'vm/page.c') diff --git a/vm/page.c b/vm/page.c index 2853497..98120e5 100644 --- a/vm/page.c +++ b/vm/page.c @@ -28,7 +28,7 @@ page_table_hash (const struct hash_elem *e, void *aux UNUSED) return hash_bytes (&pte->upage, sizeof pte->upage); } -/* page table comperator needed by the hash table implementation +/* page table comperator needed by the hash table implementation. returns true if A is less than B, or false if A is greater than or equal to B */ static bool @@ -55,7 +55,7 @@ page_table_entry_free (struct hash_elem *e, void *aux UNUSED) free (pte); } -/* inserts a new entry into the page table +/* inserts a new entry into the page table. returns false if entry is invalid or already in the table */ static bool page_table_insert (struct hash *ht, struct page_table_entry *pte) @@ -65,7 +65,7 @@ page_table_insert (struct hash *ht, struct page_table_entry *pte) return (hash_insert (ht, &pte->elem) == NULL); } -/* inserts a new entry of type segment into the page table +/* inserts a new entry of type segment into the page table. returns false if entry is invalid or already in the table */ bool page_table_insert_segment (struct hash *ht, struct file *file, off_t ofs, @@ -96,7 +96,20 @@ page_table_fetch (struct hash *ht, void *upage) return ((e != NULL) ? hash_entry (e, struct page_table_entry, elem) : NULL); } -/* load the page referenced by the page table entry +/* remove an entry from the page table. returns the element or NULL if not found. + the caller is responsible for freeing the element! */ +struct page_table_entry * +page_table_remove (struct hash *ht, void *upage) +{ + struct page_table_entry pte; + struct hash_elem *e; + + pte.upage = upage; + e = hash_delete (ht, &pte.elem); + return ((e != NULL) ? hash_entry (e, struct page_table_entry, elem) : NULL); +} + +/* load the page referenced by the page table entry. returns true on success or already loaded, false otherwise */ bool page_load (struct page_table_entry *pte) -- cgit v1.2.3