[patch] ia64 vfork() fix #2

Jan Kratochvil jan.kratochvil at redhat.com
Tue Aug 5 11:51:18 UTC 2008


Hi,

the original fix of a hang of vfork() tracing with -f was posted here:
http://sourceforge.net/mailarchive/message.php?msg_name=20080630132558.GA4346%40host0.dyn.jankratochvil.net

Unfortunately it did convert vfork() into (+/-) pthread_create() instead of
intended fork().  It brought no regressions but the fix was incomplete as
there was a race possibly causing a crash when the child waited too long:

clone(Process 944 attached (waiting for parent)
Process 944 resumed (parent 942 ready)
child_stack=0, flags=CLONE_VM|CLONE_VFORK|SIGCHLD) = 944
[pid   942] exit_group(0)               = ?
--- SIGSEGV (Segmentation fault) @ 200000000010ccb1 (58) ---
Process 944 detached

Fixed by this patch.  I hope the fix commit is OK when the original patch was
already accepted.


Sorry,
Jan
-------------- next part --------------
2008-08-05  Jan Kratochvil  <jan.kratochvil at redhat.com>

	* util.c (CLONE_VM): Define if not defined already.
	(setbpt): Clear CLONE_VM in the case we already clear CLONE_VFORK for
	SYS_clone and SYS_clone2.
	Reported by Michal Nowak.
	Fixes RH#455078.

--- util.c	18 Jul 2008 01:19:36 -0000	1.77
+++ util.c	5 Aug 2008 08:54:14 -0000
@@ -1284,6 +1284,9 @@ struct tcb *tcp;
 #ifndef CLONE_VFORK
 # define CLONE_VFORK     0x00004000
 #endif
+#ifndef CLONE_VM
+# define CLONE_VM        0x00000100
+#endif
 #ifndef CLONE_STOPPED
 # define CLONE_STOPPED   0x02000000
 #endif
@@ -1533,15 +1536,19 @@ struct tcb *tcp;
 #ifdef SYS_clone2
 	case SYS_clone2:
 #endif
-		/* ia64 calls directly `clone (CLONE_VFORK)' contrary to
-		   x86 SYS_vfork above.  Even on x86 we turn the vfork
-		   semantics into plain fork - each application must not
-		   depend on the vfork specifics according to POSIX.  We
-		   would hang waiting for the parent resume otherwise.  */
+		/* ia64 calls directly `clone (CLONE_VFORK | CLONE_VM)'
+		   contrary to x86 SYS_vfork above.  Even on x86 we turn the
+		   vfork semantics into plain fork - each application must not
+		   depend on the vfork specifics according to POSIX.  We would
+		   hang waiting for the parent resume otherwise.  We need to
+		   clear also CLONE_VM but only in the CLONE_VFORK case as
+		   otherwise we would break pthread_create.  */
+
 		if ((arg_setup (tcp, &state) < 0
 		    || set_arg0 (tcp, &state,
 				 (tcp->u_arg[arg0_index] | CLONE_PTRACE)
-				 & ~CLONE_VFORK) < 0
+				 & ~(tcp->u_arg[arg0_index] & CLONE_VFORK
+				     ? CLONE_VFORK | CLONE_VM : 0)) < 0
 		    || arg_finish_change (tcp, &state) < 0))
 		    return -1;
 		tcp->flags |= TCB_BPTSET;


More information about the Strace-devel mailing list