sbrk.c 956 B

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