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;
}
if (pd == NULL)
return;
+ ASSERT (pd != base_page_dir);
for (pde = pd; pde < pd + pd_no (PHYS_BASE); pde++)
if (*pde & PG_P)
{
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
If UADDR is unmapped, behavior varies based on CREATE:
if CREATE is true, then a new, zeroed page is created and a
pointer into it is returned,
- otherwise a null pointer is returned. */
+ otherwise a null pointer is returned.
+ Also returns a null pointer if UADDR is a kernel address. */
static uint32_t *
lookup_page (uint32_t *pd, void *uaddr, bool create)
{
uint32_t *pt, *pde;
ASSERT (pd != NULL);
- ASSERT (uaddr < PHYS_BASE);
+
+ /* Make sure it's a user address. */
+ if (uaddr >= PHYS_BASE)
+ return NULL;
/* Check for a page table for UADDR.
If one is missing, create one if requested. */
{
if (create)
{
- pt = palloc_get (PAL_ZERO);
+ pt = palloc_get_page (PAL_ZERO);
if (pt == NULL)
return NULL;
ASSERT (pg_ofs (upage) == 0);
ASSERT (pg_ofs (kpage) == 0);
- ASSERT (lookup_page (pd, upage, false) == NULL);
+ ASSERT (upage < PHYS_BASE);
+ ASSERT (pagedir_get_page (pd, upage) == NULL);
pte = lookup_page (pd, upage, true);
if (pte != NULL)