brk.c 538 B

12345678910111213141516171819202122232425262728293031323334
  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 *__curbrk = 0;
  7. int attribute_hidden __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. __curbrk = newbrk;
  18. if (newbrk < addr)
  19. {
  20. __set_errno (ENOMEM);
  21. return -1;
  22. }
  23. return 0;
  24. }
  25. strong_alias(__brk,brk)