brk.c 815 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  3. *
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. */
  6. #include <unistd.h>
  7. #include <sys/syscall.h>
  8. #include <errno.h>
  9. #include "sysdep.h"
  10. extern void * __curbrk attribute_hidden;
  11. extern int __init_brk (void) attribute_hidden;
  12. int brk(void * end_data_seg)
  13. {
  14. if (__init_brk () == 0) {
  15. /*
  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__ ("move.d %1,$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. : "g" (end_data_seg)
  25. : "r9", "r10");
  26. if (__curbrk == end_data_seg)
  27. return 0;
  28. __set_errno(ENOMEM);
  29. }
  30. return -1;
  31. }
  32. libc_hidden_def(brk)