X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/f8bd95b7a13dfe54d800e2d7ecdb0329f0798289..986ce23ace2f7875a1a561bd947f435a7594146c:/lunaix-os/kernel/mm/dmm.c diff --git a/lunaix-os/kernel/mm/dmm.c b/lunaix-os/kernel/mm/dmm.c index cc75bd9..3da8501 100644 --- a/lunaix-os/kernel/mm/dmm.c +++ b/lunaix-os/kernel/mm/dmm.c @@ -1,4 +1,5 @@ #include +#include #include #include @@ -6,6 +7,31 @@ #include #include +void +__heap_copied(struct mm_region* region) +{ + mm_index((void**)®ion->proc_vms->heap, region); +} + +int +create_heap(struct proc_mm* pvms, ptr_t addr) +{ + struct mmap_param map_param = { .pvms = pvms, + .vms_mnt = VMS_SELF, + .flags = MAP_ANON | MAP_PRIVATE, + .type = REGION_TYPE_HEAP, + .proct = PROT_READ | PROT_WRITE, + .mlen = PG_SIZE }; + int status = 0; + struct mm_region* heap; + if ((status = mem_map(NULL, &heap, addr, NULL, &map_param))) { + return status; + } + + heap->region_copied = __heap_copied; + mm_index((void**)&pvms->heap, heap); +} + __DEFINE_LXSYSCALL1(void*, sbrk, ssize_t, incr) { struct proc_mm* pvms = &__current->mm; @@ -24,6 +50,10 @@ __DEFINE_LXSYSCALL1(int, brk, void*, addr) struct proc_mm* pvms = &__current->mm; struct mm_region* heap = pvms->heap; + if (!heap) { + return DO_STATUS(create_heap(pvms, addr)); + } + assert(heap); int err = mem_adjust_inplace(&pvms->regions, heap, (ptr_t)addr); return DO_STATUS(err);