feat: closedir(2)
[lunaix-os.git] / lunaix-os / kernel / mm / dmm.c
index ae899086d79fcd00f91bb1eb6faca4b8aa04dc04..188bb0635eebf9a5771d979c55d3e04f642a74e0 100644 (file)
@@ -1,71 +1,18 @@
-/**
- * @file dmm.c
- * @author Lunaixsky
- * @brief Dynamic memory manager for heap. This design do not incorporate any\
- * specific implementation of malloc family. The main purpose of this routines is to
- * provide handy method to initialize & grow the heap as needed by upstream implementation.
- * 
- * This is designed to be portable, so it can serve as syscalls to malloc/free in the c std lib. 
- * 
- * @version 0.2
- * @date 2022-03-3
- *
- * @copyright Copyright (c) Lunaixsky 2022
- *
- */
-
-#include <lunaix/mm/dmm.h>
-#include <lunaix/mm/vmm.h>
 #include <lunaix/mm/page.h>
+#include <lunaix/mm/vmm.h>
+#include <lunaix/status.h>
 
 #include <lunaix/spike.h>
+#include <lunaix/syscall.h>
 
-int
-dmm_init(heap_context_t* heap)
+__DEFINE_LXSYSCALL1(int, sbrk, size_t, size)
 {
-    assert((uintptr_t)heap->start % BOUNDARY == 0);
-
-    heap->brk = heap->start;
-
-    return vmm_alloc_page(heap->brk, PG_PREM_RW) != NULL;
+    // TODO mem_remap to expand heap region
+    return 0;
 }
 
-int
-lxsbrk(heap_context_t* heap, void* addr)
+__DEFINE_LXSYSCALL1(void*, brk, void*, addr)
 {
-    return lxbrk(heap, addr - heap->brk) != NULL;
-}
-
-void*
-lxbrk(heap_context_t* heap, size_t size)
-{
-    if (size == 0) {
-        return heap->brk;
-    }
-
-    void* current_brk = heap->brk;
-
-    // The upper bound of our next brk of heap given the size.
-    // This will be used to calculate the page we need to allocate.
-    void* next = current_brk + ROUNDUP(size, BOUNDARY);
-
-    // any invalid situations
-    if (next >= heap->max_addr || next < current_brk) {
-        return NULL;
-    }
-
-    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),
-                             diff,
-                             PG_PREM_RW)) {
-            // for debugging
-            assert_msg(0, "unable to brk");
-            return NULL;
-        }
-    }
-
-    heap->brk += size;
-    return current_brk;
+    // TODO mem_remap to expand heap region
+    return 0;
 }
\ No newline at end of file