brk.c 686 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. libc_hidden_proto(brk)
  11. /* This must be initialized data because commons can't have aliases. */
  12. void *__curbrk = 0;
  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)