brk.c 501 B

123456789101112131415161718192021222324252627282930313233
  1. /* brk on H8/300 by ysato */
  2. #include <errno.h>
  3. #include <unistd.h>
  4. #include <sys/syscall.h>
  5. /* This must be initialized data because commons can't have aliases. */
  6. void *___brk_addr = 0;
  7. int brk (void *addr)
  8. {
  9. void *newbrk;
  10. asm ("mov.l %2,er1\n\t"
  11. "mov.l %1,er0\n\t"
  12. "trapa #0\n\t"
  13. "mov.l er0,%0"
  14. : "=r" (newbrk)
  15. : "0" (__NR_brk), "g" (addr)
  16. : "er0","er1");
  17. ___brk_addr = newbrk;
  18. if (newbrk < addr)
  19. {
  20. __set_errno (ENOMEM);
  21. return -1;
  22. }
  23. return 0;
  24. }