sbrk.c 488 B

1234567891011121314151617181920212223242526272829
  1. /*
  2. * sbrk allocator (without disk cache integration)
  3. */
  4. #include <stddef.h>
  5. #include <errno.h>
  6. #include "sys.h"
  7. #include "common.h"
  8. extern char __heap_start[], __heap_end[];
  9. static char *cur_brk = __heap_start;
  10. void heap_init(void)
  11. {
  12. }
  13. void * __hot _sbrk(ptrdiff_t increment)
  14. {
  15. char *old_brk = cur_brk;
  16. char *new_brk = old_brk + increment;
  17. if (unlikely(new_brk > __heap_end)) {
  18. errno = ENOMEM;
  19. return (void *)(-1);
  20. }
  21. cur_brk = new_brk;
  22. return old_brk;
  23. }