brk.c 702 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. libc_hidden_proto(brk)
  13. int brk (void *addr)
  14. {
  15. void *newbrk;
  16. asm ("mov.l %2,er1\n\t"
  17. "mov.l %1,er0\n\t"
  18. "trapa #0\n\t"
  19. "mov.l er0,%0"
  20. : "=r" (newbrk)
  21. : "0" (__NR_brk), "g" (addr)
  22. : "er0","er1");
  23. __curbrk = newbrk;
  24. if (newbrk < addr)
  25. {
  26. __set_errno (ENOMEM);
  27. return -1;
  28. }
  29. return 0;
  30. }
  31. libc_hidden_def(brk)