brk.c 797 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. extern void *__curbrk;
  13. libc_hidden_proto(__curbrk)
  14. void * __curbrk = 0;
  15. libc_hidden_data_def(__curbrk)
  16. int brk (void *addr)
  17. {
  18. void *newbrk;
  19. __asm__ volatile ("movel %2,%/d1\n\t"
  20. "moveq %1,%/d0\n\t"
  21. "trap #0\n\t"
  22. "movel %/d0,%0"
  23. :"=g" (newbrk)
  24. :"i" (__NR_brk),"g" (addr) : "%d0", "%d1");
  25. __curbrk = newbrk;
  26. if (newbrk < addr)
  27. {
  28. __set_errno (ENOMEM);
  29. return -1;
  30. }
  31. return 0;
  32. }
  33. libc_hidden_def(brk)