vfork.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. pid_t 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. #if 0
  16. /* Sigh. The vfork system call on powerpc
  17. * seems to be completely broken. So just
  18. * use fork instead */
  19. __sc_0 = __NR_vfork;
  20. __asm__ __volatile__
  21. ("sc \n\t"
  22. "mfcr %1 "
  23. : "=&r" (__sc_3), "=&r" (__sc_0)
  24. : "0" (__sc_3), "1" (__sc_0)
  25. : __syscall_clobbers);
  26. __sc_ret = __sc_3;
  27. __sc_err = __sc_0;
  28. if((__sc_err & 0x10000000) && (__sc_ret == ENOSYS))
  29. #endif
  30. {
  31. __sc_0 = __NR_fork;
  32. __asm__ __volatile__
  33. ("sc \n\t"
  34. "mfcr %1 "
  35. : "=&r" (__sc_3), "=&r" (__sc_0)
  36. : "0" (__sc_3), "1" (__sc_0)
  37. : __syscall_clobbers);
  38. __sc_ret = __sc_3;
  39. __sc_err = __sc_0;
  40. }
  41. __syscall_return (pid_t);
  42. }