vfork.c 966 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <unistd.h>
  2. #include <sys/types.h>
  3. #include <errno.h>
  4. #include <sys/syscall.h>
  5. #define __syscall_clobbers \
  6. "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12"
  7. #define __syscall_return(type) \
  8. return (__sc_err & 0x10000000 ? errno = __sc_ret, __sc_ret = -1 : 0), \
  9. (type) __sc_ret
  10. int vfork(void)
  11. {
  12. unsigned long __sc_ret, __sc_err;
  13. register unsigned long __sc_0 __asm__ ("r0");
  14. register unsigned long __sc_3 __asm__ ("r3");
  15. __sc_0 = __NR_vfork;
  16. __asm__ __volatile__
  17. ("sc \n\t"
  18. "mfcr %1 "
  19. : "=&r" (__sc_3), "=&r" (__sc_0)
  20. : "0" (__sc_3), "1" (__sc_0)
  21. : __syscall_clobbers);
  22. __sc_ret = __sc_3;
  23. __sc_err = __sc_0;
  24. if((__sc_err & 0x10000000) && (__sc_ret == ENOSYS)){
  25. __sc_0 = __NR_fork;
  26. __asm__ __volatile__
  27. ("sc \n\t"
  28. "mfcr %1 "
  29. : "=&r" (__sc_3), "=&r" (__sc_0)
  30. : "0" (__sc_3), "1" (__sc_0)
  31. : __syscall_clobbers);
  32. __sc_ret = __sc_3;
  33. __sc_err = __sc_0;
  34. }
  35. __syscall_return (pid_t);
  36. }