2
0

sbrk.c 399 B

1234567891011121314151617181920212223
  1. /*
  2. * sbrk allocator
  3. */
  4. #include <stddef.h>
  5. #include <errno.h>
  6. #include "sys.h"
  7. #include "fw.h"
  8. void *_sbrk(size_t increment)
  9. {
  10. static size_t cur_brk = (size_t)_end;
  11. size_t old_brk = cur_brk;
  12. size_t new_brk = old_brk + increment;
  13. if (unlikely(new_brk > SRAM_SIZE - STACK_SIZE)) {
  14. errno = ENOMEM;
  15. return (void *)(-1);
  16. }
  17. cur_brk = new_brk;
  18. return (void *)old_brk;
  19. }