brk.c 683 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /* brk on H8/300 by ysato */
  2. /*
  3. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  4. *
  5. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  6. */
  7. #include <errno.h>
  8. #include <unistd.h>
  9. #include <sys/syscall.h>
  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__ ("mov.l %2,er1\n\t"
  16. "mov.l %1,er0\n\t"
  17. "trapa #0\n\t"
  18. "mov.l er0,%0"
  19. : "=r" (newbrk)
  20. : "0" (__NR_brk), "g" (addr)
  21. : "er0","er1");
  22. __curbrk = newbrk;
  23. if (newbrk < addr)
  24. {
  25. __set_errno (ENOMEM);
  26. return -1;
  27. }
  28. return 0;
  29. }
  30. libc_hidden_def(brk)