diff --git a/abstract-machine/klib/src/stdlib.c b/abstract-machine/klib/src/stdlib.c index 382635d..e421ca7 100644 --- a/abstract-machine/klib/src/stdlib.c +++ b/abstract-machine/klib/src/stdlib.c @@ -29,12 +29,16 @@ int atoi(const char* nptr) { return x; } +static uint8_t* ptr; void *malloc(size_t size) { // On native, malloc() will be called during initializaion of C runtime. // Therefore do not call panic() here, else it will yield a dead recursion: // panic() -> putchar() -> (glibc) -> malloc() -> panic() #if !(defined(__ISA_NATIVE__) && defined(__NATIVE_USE_KLIB__)) - panic("Not implemented"); + if (ptr == NULL) ptr = heap.start; + // assert(ptr + size <= heap.end && ptr >= heap.start); + ptr += size; + return ptr - size; #endif return NULL; }