sbrk.c 718 B

1234567891011121314151617181920212223242526272829303132333435
  1. /* From libc-5.3.12 */
  2. #include <unistd.h>
  3. #include <sys/syscall.h>
  4. #include <errno.h>
  5. extern void * ___brk_addr;
  6. extern int __init_brk (void);
  7. void *
  8. sbrk(ptrdiff_t increment)
  9. {
  10. if (__init_brk () == 0)
  11. {
  12. void * tmp = ___brk_addr+increment;
  13. #if defined(__PIC__) || defined (__pic__)
  14. __asm__ volatile ("pushl %%ebx\n\t"
  15. "movl %%ecx,%%ebx\n\t"
  16. "int $0x80\n\t"
  17. "popl %%ebx"
  18. :"=a" (___brk_addr)
  19. :"0" (__NR_brk),"c" (tmp));
  20. #else
  21. __asm__ volatile ("int $0x80"
  22. :"=a" (___brk_addr)
  23. :"0" (__NR_brk),"b" (tmp));
  24. #endif
  25. if (___brk_addr == tmp)
  26. return tmp-increment;
  27. __set_errno(ENOMEM);
  28. return ((void *) -1);
  29. }
  30. return ((void *) -1);
  31. }