__init_brk.c 734 B

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