__init_brk.c 527 B

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