brk.c 719 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. 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__ __volatile__ ("movel %2,%/d1\n\t"
  17. "moveq %1,%/d0\n\t"
  18. "trap #0\n\t"
  19. "movel %/d0,%0"
  20. :"=g" (newbrk)
  21. :"i" (__NR_brk),"g" (addr) : "%d0", "%d1");
  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)