__init_brk.c 652 B

12345678910111213141516171819202122232425262728293031323334
  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 * __curbrk = 0;
  7. extern int __init_brk (void);
  8. libc_hidden_proto(__init_brk)
  9. int
  10. __init_brk (void)
  11. {
  12. if (__curbrk == 0) {
  13. /* Notice that we don't need to save/restore the GOT
  14. * register since that is not call clobbered by the syscall.
  15. */
  16. asm ("clear.d $r10\n\t"
  17. "movu.w " STR(__NR_brk) ",$r9\n\t"
  18. "break 13\n\t"
  19. "move.d $r10, %0"
  20. : "=r" (__curbrk)
  21. :
  22. : "r9", "r10");
  23. if (__curbrk == 0) {
  24. __set_errno(ENOMEM);
  25. return -1;
  26. }
  27. }
  28. return 0;
  29. }
  30. libc_hidden_def(__init_brk)