summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--userprog/process.c10
-rw-r--r--vm/mmap.c8
-rw-r--r--vm/page.c6
3 files changed, 14 insertions, 10 deletions
diff --git a/userprog/process.c b/userprog/process.c
index 80e327d..bf1a706 100644
--- a/userprog/process.c
+++ b/userprog/process.c
@@ -129,6 +129,7 @@ start_process (void *aux)
129 process->parent_tid = aux_data->parent_thread->tid; 129 process->parent_tid = aux_data->parent_thread->tid;
130 thread->process = process; 130 thread->process = process;
131 131
132 /* initialize page and mmap table */
132 page_table_init (&thread->page_table); 133 page_table_init (&thread->page_table);
133 if (!mmap_table_init (&process->mmap_table)) 134 if (!mmap_table_init (&process->mmap_table))
134 goto signal; 135 goto signal;
@@ -151,10 +152,9 @@ start_process (void *aux)
151 /* If process startup failed, quit. */ 152 /* If process startup failed, quit. */
152 if (thread->process == NULL) { 153 if (thread->process == NULL) {
153 if (process != NULL) { 154 if (process != NULL) {
155 /* close/free memory mapped files and page table */
154 /* close/free memory mapped files */ 156 /* close/free memory mapped files */
155 mmap_table_free (&process->mmap_table); 157 mmap_table_free (&process->mmap_table);
156
157 /* free page table */
158 page_table_free (&thread->page_table); 158 page_table_free (&thread->page_table);
159 159
160 if (process->fd_table.fds != NULL) 160 if (process->fd_table.fds != NULL)
@@ -240,8 +240,9 @@ process_exit (void)
240 lock_release (&filesys_lock); 240 lock_release (&filesys_lock);
241 } 241 }
242 242
243 /* close/free memory mapped files */ 243 /* close/free memory mapped files and page table */
244 mmap_table_free (&proc->mmap_table); 244 mmap_table_free (&proc->mmap_table);
245 page_table_free (&thread->page_table);
245 246
246 int fd; 247 int fd;
247 for (fd = 2; fd <= proc->fd_table.fd_max; fd++) { 248 for (fd = 2; fd <= proc->fd_table.fd_max; fd++) {
@@ -265,9 +266,6 @@ process_exit (void)
265 pagedir_destroy (pd); 266 pagedir_destroy (pd);
266 } 267 }
267 268
268 /* free page table */
269 page_table_free (&thread->page_table);
270
271 /* Destroy the process structure if the parent is not alive 269 /* Destroy the process structure if the parent is not alive
272 * any more. Atomic test and set would be sufficient here. 270 * any more. Atomic test and set would be sufficient here.
273 */ 271 */
diff --git a/vm/mmap.c b/vm/mmap.c
index 0dc9190..8620513 100644
--- a/vm/mmap.c
+++ b/vm/mmap.c
@@ -1,11 +1,11 @@
1#include <string.h> 1#include <string.h>
2#include "userprog/pagedir.h"
3#include "userprog/process.h"
4#include "filesys/file.h" 2#include "filesys/file.h"
5#include "threads/thread.h" 3#include "threads/thread.h"
6#include "threads/vaddr.h" 4#include "threads/vaddr.h"
7#include "threads/malloc.h" 5#include "threads/malloc.h"
8#include "threads/palloc.h" 6#include "threads/palloc.h"
7#include "userprog/pagedir.h"
8#include "userprog/process.h"
9#include "vm/mmap.h" 9#include "vm/mmap.h"
10#include "vm/page.h" 10#include "vm/page.h"
11 11
@@ -128,8 +128,12 @@ mmap_table_remove (struct mmap_table *table, mapid_t mapid)
128 process_unlock_filesys (); 128 process_unlock_filesys ();
129 } 129 }
130 130
131 /* free page and page table entry */
131 if (pte != NULL) 132 if (pte != NULL)
133 {
134 pagedir_clear_page (thread->pagedir, pte->upage);
132 free (pte); 135 free (pte);
136 }
133 137
134 ofs += PGSIZE; 138 ofs += PGSIZE;
135 } 139 }
diff --git a/vm/page.c b/vm/page.c
index b40382f..b98c553 100644
--- a/vm/page.c
+++ b/vm/page.c
@@ -1,10 +1,11 @@
1#include <string.h> 1#include <string.h>
2#include "filesys/file.h" 2#include "filesys/file.h"
3#include "userprog/process.h"
4#include "threads/thread.h" 3#include "threads/thread.h"
5#include "threads/vaddr.h" 4#include "threads/vaddr.h"
6#include "threads/malloc.h" 5#include "threads/malloc.h"
7#include "threads/palloc.h" 6#include "threads/palloc.h"
7#include "userprog/pagedir.h"
8#include "userprog/process.h"
8#include "vm/page.h" 9#include "vm/page.h"
9 10
10static unsigned page_table_hash (const struct hash_elem *e, void *aux UNUSED); 11static unsigned page_table_hash (const struct hash_elem *e, void *aux UNUSED);
@@ -52,6 +53,7 @@ static void
52page_table_entry_free (struct hash_elem *e, void *aux UNUSED) 53page_table_entry_free (struct hash_elem *e, void *aux UNUSED)
53{ 54{
54 struct page_table_entry *pte = hash_entry (e, struct page_table_entry, elem); 55 struct page_table_entry *pte = hash_entry (e, struct page_table_entry, elem);
56 pagedir_clear_page (thread_current ()->pagedir, pte->upage);
55 free (pte); 57 free (pte);
56} 58}
57 59
@@ -97,7 +99,7 @@ page_table_fetch (struct hash *ht, void *upage)
97} 99}
98 100
99/* remove an entry from the page table. returns the element or NULL if not found. 101/* remove an entry from the page table. returns the element or NULL if not found.
100 the caller is responsible for freeing the element! */ 102 the caller is responsible for freeing the element and the associated page! */
101struct page_table_entry * 103struct page_table_entry *
102page_table_remove (struct hash *ht, void *upage) 104page_table_remove (struct hash *ht, void *upage)
103{ 105{