__init_brk.c 587 B

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