vfork.c 750 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <unistd.h>
  2. #include <sys/syscall.h>
  3. #include <sys/types.h>
  4. #include <errno.h>
  5. int vfork(void)
  6. {
  7. unsigned long __sc_ret, __sc_err;
  8. register unsigned long __sc_0 __asm__ ("r0");
  9. register unsigned long __sc_3 __asm__ ("r3");
  10. __sc_0 = __NR_vfork;
  11. __asm__ __volatile__
  12. ("sc \n\t"
  13. "mfcr %1 "
  14. : "=&r" (__sc_3), "=&r" (__sc_0)
  15. : "0" (__sc_3), "1" (__sc_0)
  16. : __syscall_clobbers);
  17. __sc_ret = __sc_3;
  18. __sc_err = __sc_0;
  19. if((__sc_err & 0x10000000) && (__sc_ret == ENOSYS)){
  20. __sc_0 = __NR_fork;
  21. __asm__ __volatile__
  22. ("sc \n\t"
  23. "mfcr %1 "
  24. : "=&r" (__sc_3), "=&r" (__sc_0)
  25. : "0" (__sc_3), "1" (__sc_0)
  26. : __syscall_clobbers);
  27. __sc_ret = __sc_3;
  28. __sc_err = __sc_0;
  29. }
  30. __syscall_return (pid_t);
  31. }