brk.c 522 B

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