brk.c 696 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /* consider this code LGPL - davidm */
  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 <unistd.h>
  8. #include <sys/syscall.h>
  9. #include <errno.h>
  10. /* This must be initialized data because commons can't have aliases. */
  11. void * __curbrk = 0;
  12. int brk (void *addr)
  13. {
  14. void *newbrk;
  15. __asm__ __volatile__ ("movel %2,%/d1\n\t"
  16. "moveq %1,%/d0\n\t"
  17. "trap #0\n\t"
  18. "movel %/d0,%0"
  19. :"=g" (newbrk)
  20. :"i" (__NR_brk),"g" (addr) : "%d0", "%d1");
  21. __curbrk = newbrk;
  22. if (newbrk < addr)
  23. {
  24. __set_errno (ENOMEM);
  25. return -1;
  26. }
  27. return 0;
  28. }
  29. libc_hidden_def(brk)