brk.c 565 B

12345678910111213141516171819202122232425262728293031
  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 attribute_hidden __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. }
  24. strong_alias(__brk,brk)