Added dumb implementation of get_free_va_range.
authorAndrew Waterman <waterman@parcad.millennium.berkeley.edu>
Wed, 27 Jan 2010 21:27:55 +0000 (13:27 -0800)
committerAndrew Waterman <waterman@parcad.millennium.berkeley.edu>
Wed, 27 Jan 2010 21:27:55 +0000 (13:27 -0800)
Right now it just linearly scans the user's address space,
which is obviously a low-performance implementation.  But
it works...

kern/arch/sparc/pmap.c
kern/include/types.h [deleted file]
kern/src/mm.c

index a65ea76..01acaed 100644 (file)
@@ -123,8 +123,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)
 {
-       // SARAH TODO
-       assert(0);
+       addr = ROUNDUP(addr,PGSIZE);
+       len = ROUNDUP(len,PGSIZE);
+       for(char* a = (char*)addr; a < (char*)UTOP; a++)
+       {
+               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;
 }
 
 
diff --git a/kern/include/types.h b/kern/include/types.h
deleted file mode 100644 (file)
index fb343eb..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#include <
index 5aeaba4..cbda5b6 100644 (file)
@@ -27,12 +27,8 @@ void *mmap(struct proc *p, uintptr_t addr, size_t len, int prot, int flags,
         * return appropriate pointer
         * Right now, all we can do is give them the range they ask for.
         */
-       //void *tmp = get_free_va_range(p->env_pgdir, addr, len);
-       //printk("tmp = 0x%08x\n", tmp);
-       if (!addr) {
-               printk("[kernel] mmap() requires an address, since it's ghetto\n");
-               return (void*SAFE)TC(-1);
-       }
+       if (!addr)
+               addr = (uintptr_t)get_free_va_range(p->env_pgdir,UMMAP_START,len);
        // brief sanity check.  must be page aligned and not reaching too high
        if (PGOFF(addr)) {
                printk("[kernel] mmap() page align your addr.\n");