Added a bad implementation of get_free_va_range
authorKevin Klues <klueska@ros-dev.(none)>
Wed, 24 Mar 2010 07:14:54 +0000 (00:14 -0700)
committerKevin Klues <klueska@cs.berkeley.edu>
Thu, 3 Nov 2011 00:35:37 +0000 (17:35 -0700)
Terribly inefficient, but we needed some implementation.

SARAH TODO

kern/arch/i686/pmap.c

index c221f3a..dd7d7cf 100644 (file)
@@ -632,6 +632,23 @@ int get_va_perms(pde_t *pgdir, const void *SNT va)
 
 void *get_free_va_range(pde_t *pgdir, uintptr_t addr, size_t len)
 {
+       addr = ROUNDUP(MAX(addr,UMMAP_START),PGSIZE);
+       len = ROUNDUP(len,PGSIZE);
+
+       for(char* a = (char*)addr; a < (char*)USTACKBOT; a += PGSIZE)
+       {
+               for(char* b = a; b < a+len; b += PGSIZE)
+               {
+                       pte_t* pte = pgdir_walk(pgdir,b,0);
+                       if(pte && (*pte & PTE_P))
+                       {
+                               a = b;
+                               break;
+                       }
+                       if(b+PGSIZE == a+len)
+                               return a;
+               }
+       }
        return NULL;
 }