brk.c 648 B

123456789101112131415161718192021222324252627282930313233343536
  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. "excpt 0;\n\t"
  18. : "=q0" (newbrk)
  19. : "q0" (addr), "i" (__NR_brk): "P0" );
  20. __curbrk = newbrk;
  21. if (newbrk < addr)
  22. {
  23. __set_errno (ENOMEM);
  24. return -1;
  25. }
  26. return 0;
  27. }
  28. libc_hidden_def(brk)