sbrk.c 716 B

123456789101112131415161718192021222324252627282930313233343536
  1. /* From libc-5.3.12 */
  2. #include <unistd.h>
  3. #include <sys/syscall.h>
  4. #include <errno.h>
  5. #include "sysdep.h"
  6. extern void * ___brk_addr;
  7. extern int __init_brk (void);
  8. void *
  9. sbrk(intptr_t increment)
  10. {
  11. if (__init_brk () == 0) {
  12. void * tmp = ___brk_addr + increment;
  13. /*
  14. * Notice that we don't need to save/restore the GOT
  15. * register since that is not call clobbered by the syscall.
  16. */
  17. asm ("move.d %1,$r10\n\t"
  18. "movu.w " STR(__NR_brk) ",$r9\n\t"
  19. "break 13\n\t"
  20. "move.d $r10, %0"
  21. : "=r" (___brk_addr)
  22. : "g" (tmp)
  23. : "r9", "r10");
  24. if (___brk_addr == tmp)
  25. return tmp - increment;
  26. __set_errno(ENOMEM);
  27. return ((void *) -1);
  28. }
  29. return ((void *) -1);
  30. }