Nucleus
Barry Improved page fault handling and mmap system call 665af0a (3 years, 2 months ago)
diff --git a/memory/region.c b/memory/region.c
index bea28ca..ef43efc 100644
--- a/memory/region.c
+++ b/memory/region.c
@@ -13,9 +13,10 @@
static void vm_new(Object *);
static void vm_delete(Object *);
+static void vm_copy(Object *, Object *);
static void region_new(Object *);
static void region_delete(Object *);
-static void region_copy(Object *a, Object *b);
+static void region_copy(Object *, Object *);
/* Virtual Memory Namespace object type */
ObjectType virtualMemoryType = {
@@ -23,6 +24,7 @@ ObjectType virtualMemoryType = {
.size = sizeof(VirtualMemory),
.new = vm_new,
.delete = vm_delete,
+ .copy = vm_copy,
};
/* VMRegion object type */
@@ -135,9 +137,14 @@ find_region(uintptr_t addr)
VMRegion *region;
foreach (current->vm->regions, region) {
if (region->start <= addr && region->end > addr)
- break;
+ return region;
}
- return region;
+
+ region = current->stack;
+ if (region->start <= addr && region->end > addr)
+ return region;
+
+ return NULL;
}
/* Create a new Virtual Memory Region */
@@ -148,7 +155,7 @@ vm_create_region(void *addr, size_t len, int prot, int flags, off_t offset,
/* Create new region */
VMRegion *region = new(&vmRegionType);
region->end = (uintptr_t) addr + len;
- if (region-> end % PAGE_SIZE)
+ if (region->end % PAGE_SIZE)
region->end += PAGE_SIZE - (region->end % PAGE_SIZE);
region->start = PAGE_ADDR((uintptr_t) addr);
region->prot = prot;
@@ -190,9 +197,20 @@ vm_create_region(void *addr, size_t len, int prot, int flags, off_t offset,
}
/* Total eclipse */
if (head->start >= region->start && head->end <= region->end)
- remove(current->vm->regions, region);
+ remove(current->vm->regions, head);
}
add(current->vm->regions, region);
return region;
}
+
+/* Create a Virtual Memory Region for the stack */
+VMRegion *
+vm_create_stack(void)
+{
+ VMRegion *stack = vm_create_region((void *) 0xDFC00000, 0x400000,
+ PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, 0, NULL);
+ remove(current->vm->regions, stack);
+ return stack;
+}