brk.c 672 B

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