sbrk.c 910 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* From libc-5.3.12 */
  2. /*
  3. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  4. *
  5. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  6. */
  7. #include <unistd.h>
  8. #include <sys/syscall.h>
  9. #include <errno.h>
  10. #include "sysdep.h"
  11. extern void * __curbrk attribute_hidden;
  12. extern int __init_brk (void) attribute_hidden;
  13. void *
  14. sbrk(intptr_t increment)
  15. {
  16. if (__init_brk () == 0) {
  17. void * tmp = __curbrk + increment;
  18. /*
  19. * Notice that we don't need to save/restore the GOT
  20. * register since that is not call clobbered by the syscall.
  21. */
  22. __asm__ ("move.d %1,$r10\n\t"
  23. "movu.w " STR(__NR_brk) ",$r9\n\t"
  24. "break 13\n\t"
  25. "move.d $r10, %0"
  26. : "=r" (__curbrk)
  27. : "g" (tmp)
  28. : "r9", "r10");
  29. if (__curbrk == tmp)
  30. return tmp - increment;
  31. __set_errno(ENOMEM);
  32. return ((void *) -1);
  33. }
  34. return ((void *) -1);
  35. }
  36. libc_hidden_def(sbrk)