brk.c 621 B

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