/* * sbrk allocator */ #include #include #include "sys.h" #include "fw.h" #define HEAP_SIZE (4 << 20) /* 4 MB */ static char __attribute__((section(".heap"))) __heap[HEAP_SIZE]; static char *cur_brk = __heap; void *_sbrk(size_t increment) { char *old_brk = cur_brk; char *new_brk = old_brk + increment; if (unlikely(new_brk > &__heap[HEAP_SIZE])) { errno = ENOMEM; return (void *)(-1); } cur_brk = new_brk; return old_brk; }