sbrk.c 934 B

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