Menuconfig Implementation and auto-qemu refactoring (#44)
[lunaix-os.git] / lunaix-os / kernel / mm / region.c
index f47baa749efd493fd560a9c1154200c75ff13306..d8035db4fef36d9d532206bcd95fb3b736e9ef4e 100644 (file)
@@ -1,7 +1,7 @@
-#include <lunaix/mm/page.h>
 #include <lunaix/mm/region.h>
 #include <lunaix/mm/valloc.h>
 #include <lunaix/spike.h>
+#include <lunaix/process.h>
 
 #include <sys/mm/mempart.h>
 
@@ -10,8 +10,8 @@
 struct mm_region*
 region_create(ptr_t start, ptr_t end, u32_t attr)
 {
-    assert_msg(PG_ALIGNED(start), "not page aligned");
-    assert_msg(PG_ALIGNED(end), "not page aligned");
+    assert_msg(!va_offset(start), "not page aligned");
+    assert_msg(!va_offset(end), "not page aligned");
     struct mm_region* region = valloc(sizeof(struct mm_region));
     *region =
       (struct mm_region){ .attr = attr, .start = start, .end = end - 1 };
@@ -21,12 +21,12 @@ region_create(ptr_t start, ptr_t end, u32_t attr)
 struct mm_region*
 region_create_range(ptr_t start, size_t length, u32_t attr)
 {
-    assert_msg(PG_ALIGNED(start), "not page aligned");
-    assert_msg(PG_ALIGNED(length), "not page aligned");
+    assert_msg(!va_offset(start), "not page aligned");
+    assert_msg(!va_offset(length), "not page aligned");
     struct mm_region* region = valloc(sizeof(struct mm_region));
     *region = (struct mm_region){ .attr = attr,
                                   .start = start,
-                                  .end = ROUNDUP(start + length, MEM_PAGE) };
+                                  .end = ROUNDUP(start + length, PAGE_SIZE) };
     return region;
 }
 
@@ -52,8 +52,7 @@ region_add(vm_regions_t* lead, struct mm_region* vmregion)
         return;
     }
 
-    struct mm_region *pos = (struct mm_region*)lead->next,
-                     *n = list_entry(pos->head.next, struct mm_region, head);
+    struct mm_region *pos, *n;
     ptr_t cur_end = 0;
 
     llist_for_each(pos, n, lead, head)
@@ -76,7 +75,8 @@ region_release(struct mm_region* region)
     }
 
     if (region->mfile) {
-        vfs_pclose(region->mfile, region->proc_vms->pid);
+        struct proc_mm* mm = region->proc_vms;
+        vfs_pclose(region->mfile, mm->proc->pid);
     }
 
     if (region->index) {
@@ -117,7 +117,7 @@ region_copy_mm(struct proc_mm* src, struct proc_mm* dest)
             dup->region_copied(dup);
         }
 
-        region_add(&dest->regions, dup);
+        llist_append(&dest->regions, &dup->head);
     }
 }
 
@@ -130,7 +130,7 @@ region_get(vm_regions_t* lead, unsigned long vaddr)
 
     struct mm_region *pos, *n;
 
-    vaddr = PG_ALIGN(vaddr);
+    vaddr = page_aligned(vaddr);
 
     llist_for_each(pos, n, lead, head)
     {