brk.c 654 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. /* This must be initialized data because commons can't have aliases. */
  10. void * __curbrk = 0;
  11. int brk (void *addr)
  12. {
  13. void *newbrk;
  14. __asm__ __volatile__(
  15. "P0 = %2;\n\t"
  16. "R0 = %1;\n\t"
  17. "excpt 0;\n\t"
  18. "%0 = R0;\n\t"
  19. : "=r"(newbrk)
  20. : "r"(addr), "i" (__NR_brk): "P0" );
  21. __curbrk = newbrk;
  22. if (newbrk < addr)
  23. {
  24. __set_errno (ENOMEM);
  25. return -1;
  26. }
  27. return 0;
  28. }
  29. libc_hidden_proto(brk)
  30. libc_hidden_def(brk)