Use `z' modifier to printf size_t.
[pintos-anon] / src / threads / paging.c
index 2ae78c3c456cff3a63ae1ddf913db847864e2965..c0d89adf24bfc45b613e89effba9e63c49f64f42 100644 (file)
@@ -1,10 +1,10 @@
-#include "paging.h"
+#include "threads/paging.h"
 #include <stdbool.h>
 #include <stddef.h>
-#include "init.h"
-#include "lib.h"
-#include "mmu.h"
-#include "palloc.h"
+#include <string.h>
+#include "threads/init.h"
+#include "threads/mmu.h"
+#include "threads/palloc.h"
 
 static uint32_t *base_page_dir;
 
@@ -85,10 +85,26 @@ void
 pagedir_destroy (uint32_t *pd) 
 {
   void *kpage, *upage;
+  unsigned pde_idx;
 
+  /* Destroy user pages. */
   for (kpage = pagedir_first (pd, &upage); kpage != NULL;
        kpage = pagedir_next (pd, &upage)) 
     palloc_free (kpage);
+
+  /* Destroy page table pages. */
+  for (pde_idx = 0; pde_idx < pd_no (PHYS_BASE); pde_idx++) 
+    {
+      uint32_t pde = pd[pde_idx];
+
+      if (pde != 0) 
+        {
+          uint32_t *pt = pde_get_pt (pde);
+          palloc_free (pt);
+        }
+    }
+
+  /* Destroy page directory. */
   palloc_free (pd);
 }