[Midnightbsd-cvs] src: thr_kern.c: Correct a timing problem when calling fork() from a
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Fri Jan 25 10:45:12 EST 2008
Log Message:
-----------
Correct a timing problem when calling fork() from a process using libpthread (kse)
Modified Files:
--------------
src/lib/libpthread/thread:
thr_kern.c (r1.3 -> r1.4)
-------------- next part --------------
Index: thr_kern.c
===================================================================
RCS file: /home/cvs/src/lib/libpthread/thread/thr_kern.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -L lib/libpthread/thread/thr_kern.c -L lib/libpthread/thread/thr_kern.c -u -r1.3 -r1.4
--- lib/libpthread/thread/thr_kern.c
+++ lib/libpthread/thread/thr_kern.c
@@ -345,6 +345,16 @@
_LCK_SET_PRIVATE2(&curthread->kse->k_lockusers[i], NULL);
}
curthread->kse->k_locklevel = 0;
+
+ /*
+ * Reinitialize the thread and signal locks so that
+ * sigaction() will work after a fork().
+ */
+ _lock_reinit(&curthread->lock, LCK_ADAPTIVE, _thr_lock_wait,
+ _thr_lock_wakeup);
+ _lock_reinit(&_thread_signal_lock, LCK_ADAPTIVE, _kse_lock_wait,
+ _kse_lock_wakeup);
+
_thr_spinlock_init();
if (__isthreaded) {
_thr_rtld_fini();
@@ -354,6 +364,19 @@
curthread->kse->k_kcb->kcb_kmbx.km_curthread = NULL;
curthread->attr.flags |= PTHREAD_SCOPE_SYSTEM;
+ /*
+ * After a fork, it is possible that an upcall occurs in
+ * the parent KSE that fork()'d before the child process
+ * is fully created and before its vm space is copied.
+ * During the upcall, the tcb is set to null or to another
+ * thread, and this is what gets copied in the child process
+ * when the vm space is cloned sometime after the upcall
+ * occurs. Note that we shouldn't have to set the kcb, but
+ * we do it for completeness.
+ */
+ _kcb_set(curthread->kse->k_kcb);
+ _tcb_set(curthread->kse->k_kcb, curthread->tcb);
+
/* After a fork(), there child should have no pending signals. */
sigemptyset(&curthread->sigpend);
More information about the Midnightbsd-cvs
mailing list