Rewrite page allocator to support multi-page allocations.
[pintos-anon] / src / userprog / pagedir.c
index 3b634b9592823995689af4bc60ea317a302d47e4..f26496d79467aa316e5b0f13953c2c07eb6d4fa4 100644 (file)
@@ -13,7 +13,7 @@
 uint32_t *
 pagedir_create (void) 
 {
-  uint32_t *pd = palloc_get (0);
+  uint32_t *pd = palloc_get_page (0);
   memcpy (pd, base_page_dir, PGSIZE);
   return pd;
 }
@@ -28,6 +28,7 @@ pagedir_destroy (uint32_t *pd)
   if (pd == NULL)
     return;
 
+  ASSERT (pd != base_page_dir);
   for (pde = pd; pde < pd + pd_no (PHYS_BASE); pde++)
     if (*pde & PG_P) 
       {
@@ -36,10 +37,10 @@ pagedir_destroy (uint32_t *pd)
         
         for (pte = pt; pte < pt + PGSIZE / sizeof *pte; pte++)
           if (*pte & PG_P) 
-            palloc_free (pte_get_page (*pte));
-        palloc_free (pt);
+            palloc_free_page (pte_get_page (*pte));
+        palloc_free_page (pt);
       }
-  palloc_free (pd);
+  palloc_free_page (pd);
 }
 
 /* Returns the mapping of user virtual address UADDR in page
@@ -67,7 +68,7 @@ lookup_page (uint32_t *pd, void *uaddr, bool create)
     {
       if (create)
         {
-          pt = palloc_get (PAL_ZERO);
+          pt = palloc_get_page (PAL_ZERO);
           if (pt == NULL) 
             return NULL; 
       
@@ -98,7 +99,7 @@ pagedir_set_page (uint32_t *pd, void *upage, void *kpage,
   ASSERT (pg_ofs (upage) == 0);
   ASSERT (pg_ofs (kpage) == 0);
   ASSERT (upage < PHYS_BASE);
-  ASSERT (lookup_page (pd, upage, false) == NULL);
+  ASSERT (pagedir_get_page (pd, upage) == NULL);
 
   pte = lookup_page (pd, upage, true);
   if (pte != NULL)