Module Name:    src
Committed By:   christos
Date:           Tue Aug 23 13:01:25 UTC 2011

Modified Files:
        src/sys/kern: kern_fork.c

Log Message:
don't use lwp_setprivate in fork, but copy the private lwp member directly
because userland might have messed with the TLS register without letting
the kernel know. This fixes fork() on amd64. Thanks chuq!


To generate a diff of this commit:
cvs rdiff -u -r1.184 -r1.185 src/sys/kern/kern_fork.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_fork.c
diff -u src/sys/kern/kern_fork.c:1.184 src/sys/kern/kern_fork.c:1.185
--- src/sys/kern/kern_fork.c:1.184	Sat May 14 14:50:07 2011
+++ src/sys/kern/kern_fork.c	Tue Aug 23 09:01:25 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_fork.c,v 1.184 2011/05/14 18:50:07 rmind Exp $	*/
+/*	$NetBSD: kern_fork.c,v 1.185 2011/08/23 13:01:25 christos Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2001, 2004, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.184 2011/05/14 18:50:07 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.185 2011/08/23 13:01:25 christos Exp $");
 
 #include "opt_ktrace.h"
 
@@ -423,7 +423,14 @@
 	lwp_create(l1, p2, uaddr, (flags & FORK_PPWAIT) ? LWP_VFORK : 0,
 	    stack, stacksize, (func != NULL) ? func : child_return, arg, &l2,
 	    l1->l_class);
-	lwp_setprivate(l2, l1->l_private);
+
+	/*
+	 * Inherit l_private from the parent.
+	 * Note that we cannot use lwp_setprivate() here since that
+	 * also sets the CPU TLS register, which is incorrect if the
+	 * process has changed that without letting the kernel know.
+	 */
+	l2->l_private = l1->l_private;
 
 	/*
 	 * If emulation has a process fork hook, call it now.

Reply via email to