X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/f552823ca5288f68128995ed503d0cb0f974d455..48b4a227035048fdebcd32532deb7a857c6199ac:/lunaix-os/kernel/mm/dmm.c diff --git a/lunaix-os/kernel/mm/dmm.c b/lunaix-os/kernel/mm/dmm.c index ae89908..dee5d28 100644 --- a/lunaix-os/kernel/mm/dmm.c +++ b/lunaix-os/kernel/mm/dmm.c @@ -17,17 +17,36 @@ #include #include #include +#include #include + +int _syscall_sbrk(void* addr) { + heap_context_t* uheap = &__current->mm.u_heap; + mutex_lock(&uheap->lock); + int r = lxsbrk(uheap, addr); + mutex_unlock(&uheap->lock); + return r; +} + +void* _syscall_brk(size_t size) { + heap_context_t* uheap = &__current->mm.u_heap; + mutex_lock(&uheap->lock); + void* r = lxbrk(uheap, size); + mutex_unlock(&uheap->lock); + return r; +} + int dmm_init(heap_context_t* heap) { assert((uintptr_t)heap->start % BOUNDARY == 0); heap->brk = heap->start; + mutex_init(&heap->lock); - return vmm_alloc_page(heap->brk, PG_PREM_RW) != NULL; + return vmm_alloc_page(__current->pid, heap->brk, NULL, PG_PREM_RW, 0) != NULL; } int @@ -51,17 +70,16 @@ lxbrk(heap_context_t* heap, size_t size) // any invalid situations if (next >= heap->max_addr || next < current_brk) { - return NULL; + __current->k_status = LXINVLDPTR; } uintptr_t diff = PG_ALIGN(next) - PG_ALIGN(current_brk); if (diff) { // if next do require new pages to be allocated - if (!vmm_alloc_pages((void*)(PG_ALIGN(current_brk) + PG_SIZE), + if (!vmm_alloc_pages(__current->pid, (void*)(PG_ALIGN(current_brk) + PG_SIZE), diff, - PG_PREM_RW)) { - // for debugging - assert_msg(0, "unable to brk"); + PG_PREM_RW, 0)) { + __current->k_status = LXHEAPFULL; return NULL; } }