brk.c 608 B

12345678910111213141516171819202122232425262728293031
  1. #include <unistd.h>
  2. #include <sys/syscall.h>
  3. #include <errno.h>
  4. #include "sysdep.h"
  5. extern void * __curbrk;
  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" (__curbrk)
  19. : "g" (end_data_seg)
  20. : "r9", "r10");
  21. if (__curbrk == end_data_seg)
  22. return 0;
  23. __set_errno(ENOMEM);
  24. }
  25. return -1;
  26. }