brk.c 738 B

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