brk.c 462 B

123456789101112131415161718192021222324252627282930
  1. #include <unistd.h>
  2. #include <sys/syscall.h>
  3. #include <errno.h>
  4. /* This must be initialized data because commons can't have aliases. */
  5. void * __curbrk = 0;
  6. int brk (void *addr)
  7. {
  8. void *newbrk;
  9. __asm__ __volatile__(
  10. "P0 = %2;\n\t"
  11. "R0 = %1;\n\t"
  12. "excpt 0;\n\t"
  13. "%0 = R0;\n\t"
  14. : "=r"(newbrk)
  15. : "r"(addr), "i" (__NR_brk): "P0" );
  16. __curbrk = newbrk;
  17. if (newbrk < addr)
  18. {
  19. __set_errno (ENOMEM);
  20. return -1;
  21. }
  22. return 0;
  23. }