diff options
Diffstat (limited to 'vm/page.c')
| -rw-r--r-- | vm/page.c | 21 |
1 files changed, 17 insertions, 4 deletions
| @@ -28,7 +28,7 @@ page_table_hash (const struct hash_elem *e, void *aux UNUSED) | |||
| 28 | return hash_bytes (&pte->upage, sizeof pte->upage); | 28 | return hash_bytes (&pte->upage, sizeof pte->upage); |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | /* page table comperator needed by the hash table implementation | 31 | /* page table comperator needed by the hash table implementation. |
| 32 | returns true if A is less than B, or false if A is greater than | 32 | returns true if A is less than B, or false if A is greater than |
| 33 | or equal to B */ | 33 | or equal to B */ |
| 34 | static bool | 34 | static bool |
| @@ -55,7 +55,7 @@ page_table_entry_free (struct hash_elem *e, void *aux UNUSED) | |||
| 55 | free (pte); | 55 | free (pte); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | /* inserts a new entry into the page table | 58 | /* inserts a new entry into the page table. |
| 59 | returns false if entry is invalid or already in the table */ | 59 | returns false if entry is invalid or already in the table */ |
| 60 | static bool | 60 | static bool |
| 61 | page_table_insert (struct hash *ht, struct page_table_entry *pte) | 61 | 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) | |||
| 65 | return (hash_insert (ht, &pte->elem) == NULL); | 65 | return (hash_insert (ht, &pte->elem) == NULL); |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | /* inserts a new entry of type segment into the page table | 68 | /* inserts a new entry of type segment into the page table. |
| 69 | returns false if entry is invalid or already in the table */ | 69 | returns false if entry is invalid or already in the table */ |
| 70 | bool | 70 | bool |
| 71 | page_table_insert_segment (struct hash *ht, struct file *file, off_t ofs, | 71 | 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) | |||
| 96 | return ((e != NULL) ? hash_entry (e, struct page_table_entry, elem) : NULL); | 96 | return ((e != NULL) ? hash_entry (e, struct page_table_entry, elem) : NULL); |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | /* load the page referenced by the page table entry | 99 | /* remove an entry from the page table. returns the element or NULL if not found. |
| 100 | the caller is responsible for freeing the element! */ | ||
| 101 | struct page_table_entry * | ||
| 102 | page_table_remove (struct hash *ht, void *upage) | ||
| 103 | { | ||
| 104 | struct page_table_entry pte; | ||
| 105 | struct hash_elem *e; | ||
| 106 | |||
| 107 | pte.upage = upage; | ||
| 108 | e = hash_delete (ht, &pte.elem); | ||
| 109 | return ((e != NULL) ? hash_entry (e, struct page_table_entry, elem) : NULL); | ||
| 110 | } | ||
| 111 | |||
| 112 | /* load the page referenced by the page table entry. | ||
| 100 | returns true on success or already loaded, false otherwise */ | 113 | returns true on success or already loaded, false otherwise */ |
| 101 | bool | 114 | bool |
| 102 | page_load (struct page_table_entry *pte) | 115 | page_load (struct page_table_entry *pte) |
