Added demand paging support
[akaros.git] / kern / arch / sparc / env.c
index bb7aa60..6e199d2 100644 (file)
@@ -91,13 +91,13 @@ restore_fp_state(ancillary_state_t* silly)
 
 // Flush all mapped pages in the user portion of the address space
 // TODO: only supports L3 user pages
-void
+int
 env_user_mem_walk(env_t* e, void* start, size_t len,
                   mem_walk_callback_t callback, void* arg)
 {
        pte_t *l1pt = e->env_pgdir;
 
-       assert((intptr_t)start % PGSIZE == 0 && len % PGSIZE == 0);
+       assert((uintptr_t)start % PGSIZE == 0 && len % PGSIZE == 0);
        void* end = (char*)start+len;
 
        int l1x_start = L1X(start);
@@ -125,11 +125,14 @@ env_user_mem_walk(env_t* e, void* start, size_t len,
                                        L3X(start) : 0;
                        int l3x_end = l1x == l1x_end-1 && l2x == l2x_end-1 && L3X(end) ?
                                      L3X(end) : NL3ENTRIES;
-                       for(int l3x = l3x_start; l3x < l3x_end; l3x++)
-                               if(l3pt[l3x] & PTE_PTE)
-                                       callback(e,&l3pt[l3x],PGADDR(l1x,l2x,l3x,0),arg);
+                       for(int l3x = l3x_start, ret; l3x < l3x_end; l3x++)
+                               if(!PAGE_UNMAPPED(l3pt[l3x]))
+                                       if((ret = callback(e,&l3pt[l3x],PGADDR(l1x,l2x,l3x,0),arg)))
+                                               return ret;
                }
        }
+
+       return 0;
 }
 
 void