sbrk.c 928 B

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