From 6f8326cacd08bf7d1966743086855fc36574bf74 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Thu, 30 Jun 2011 20:41:34 -0400 Subject: Fix robust mutex handling after fork --- nptl/sysdeps/pthread/pthread-functions.h | 3 ++- nptl/sysdeps/unix/sysv/linux/fork.c | 33 +++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 8 deletions(-) (limited to 'nptl/sysdeps') diff --git a/nptl/sysdeps/pthread/pthread-functions.h b/nptl/sysdeps/pthread/pthread-functions.h index 0c404fc..15a4dff 100644 --- a/nptl/sysdeps/pthread/pthread-functions.h +++ b/nptl/sysdeps/pthread/pthread-functions.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. +/* Copyright (C) 2003, 2004, 2005, 2006, 2007, 2011 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 2003. @@ -97,6 +97,7 @@ struct pthread_functions void (*ptr__nptl_deallocate_tsd) (void); int (*ptr__nptl_setxid) (struct xid_command *); void (*ptr_freeres) (void); + void (*ptr_set_robust) (struct pthread *); }; /* Variable in libc.so. */ diff --git a/nptl/sysdeps/unix/sysv/linux/fork.c b/nptl/sysdeps/unix/sysv/linux/fork.c index 524d72c..80fb147 100644 --- a/nptl/sysdeps/unix/sysv/linux/fork.c +++ b/nptl/sysdeps/unix/sysv/linux/fork.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2002, 2003, 2007, 2008 Free Software Foundation, Inc. +/* Copyright (C) 2002, 2003, 2007, 2008, 2011 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 2002. @@ -29,6 +29,7 @@ #include #include #include +#include unsigned long int *__fork_generation_pointer; @@ -86,8 +87,8 @@ __libc_fork (void) just go away. The unloading code works in the order of the list. - While executing the registered handlers we are building a - list of all the entries so that we can go backward later on. */ + While executing the registered handlers we are building a + list of all the entries so that we can go backward later on. */ while (1) { /* Execute the handler if there is one. */ @@ -154,6 +155,24 @@ __libc_fork (void) GL(dl_cpuclock_offset) = now; #endif +#ifdef __NR_set_robust_list + /* Initialize the robust mutex list which has been reset during + the fork. We do not check for errors since if it fails here + it failed at process start as well and noone could have used + robust mutexes. We also do not have to set + self->robust_head.futex_offset since we inherit the correct + value from the parent. */ +# ifdef SHARED + if (__builtin_expect (__libc_pthread_functions_init, 0)) + PTHFCT_CALL (ptr_set_robust, (self)); +# else + extern __typeof (__nptl_set_robust) __nptl_set_robust + __attribute__((weak)); + if (__builtin_expect (__nptl_set_robust != NULL, 0)) + __nptl_set_robust (self); +# endif +#endif + /* Reset the file list. These are recursive mutexes. */ fresetlockfiles (); @@ -170,10 +189,10 @@ __libc_fork (void) allp->handler->child_handler (); /* Note that we do not have to wake any possible waiter. - This is the only thread in the new process. The count - may have been bumped up by other threads doing a fork. - We reset it to 1, to avoid waiting for non-existing - thread(s) to release the count. */ + This is the only thread in the new process. The count + may have been bumped up by other threads doing a fork. + We reset it to 1, to avoid waiting for non-existing + thread(s) to release the count. */ allp->handler->refcntr = 1; /* XXX We could at this point look through the object pool -- cgit v1.1