vfork.S 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (C) 2013 Synopsys, Inc. (www.synopsys.com)
  3. *
  4. * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
  5. */
  6. #include <sys/syscall.h>
  7. #include <sysdep.h>
  8. /* No legacy syscall ABI means NR_vfork is not available at all, use clone */
  9. #define _SIGNAL_H
  10. #include <bits/signum.h> /* For SIGCHLD */
  11. #define CLONE_VM 0x00000100
  12. #define CLONE_VFORK 0x00004000
  13. #define CLONE_FLAGS_FOR_VFORK (CLONE_VM|CLONE_VFORK|SIGCHLD)
  14. ENTRY(__vfork)
  15. #ifdef SAVE_PID
  16. THREAD_SELF r1 ; Get to struct pthread (just before TCB)
  17. ld r2, [r1, PTHREAD_PID]
  18. neg.f r3, r2
  19. bset.z r3, r3, 31
  20. st r3, [r1, PTHREAD_PID]
  21. #endif
  22. mov r0, CLONE_FLAGS_FOR_VFORK
  23. mov_s r1, sp
  24. mov r8, __NR_clone
  25. ARC_TRAP_INSN
  26. cmp r0, 0
  27. #ifdef RESTORE_PID
  28. bz 1f ; child continues
  29. THREAD_SELF r1 ; Get to struct pthread (just before TCB)
  30. st r2, [r1, PTHREAD_PID]
  31. 1:
  32. #endif
  33. jge [blink] ; pid >=0 return, else detour via tailcall to errno
  34. b __syscall_error
  35. END(__vfork)
  36. weak_alias(__vfork,vfork)
  37. libc_hidden_def(vfork)