brk.c 605 B

1234567891011121314151617181920212223242526272829303132
  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 ();
  7. int brk(void * end_data_seg)
  8. {
  9. if (__init_brk () == 0)
  10. {
  11. #if defined(__PIC__) || defined (__pic__)
  12. __asm__ volatile ("pushl %%ebx\n\t"
  13. "movl %%ecx,%%ebx\n\t"
  14. "int $0x80\n\t"
  15. "popl %%ebx"
  16. :"=a" (___brk_addr)
  17. :"0" (SYS_brk),"c" (end_data_seg));
  18. #else
  19. __asm__ volatile ("int $0x80"
  20. :"=a" (___brk_addr)
  21. :"0" (SYS_brk),"b" (end_data_seg));
  22. #endif
  23. if (___brk_addr == end_data_seg)
  24. return 0;
  25. errno = ENOMEM;
  26. }
  27. return -1;
  28. }