1 2011-06-30 Ulrich Drepper <drepper@gmail.com>
3 * nptl-init.c (__nptl_set_robust): New function.
4 (pthread_functions): Add reference.
5 * npthreadP.h: Declare __nptl_set_robust.
6 * sysdeps/pthread/pthread-functions.h (pthread_functions): Add
8 * sysdeps/unix/sysv/linux/fork.c: Call set_robust_list syscall in
9 child if threads are used.
11 diff -Nrup a/nptl/nptl-init.c b/nptl/nptl-init.c
12 --- a/nptl/nptl-init.c 2011-12-20 00:29:54.645538691 -0700
13 +++ b/nptl/nptl-init.c 2012-01-03 10:18:38.977513783 -0700
14 @@ -69,6 +69,13 @@ extern void __libc_setup_tls (size_t tcb
22 +void __nptl_set_robust (struct pthread *);
25 static void nptl_freeres (void);
28 @@ -131,13 +138,25 @@ static const struct pthread_functions pt
29 .ptr__nptl_deallocate_tsd = __nptl_deallocate_tsd,
30 .ptr__nptl_setxid = __nptl_setxid,
31 /* For now only the stack cache needs to be freed. */
32 - .ptr_freeres = nptl_freeres
33 + .ptr_freeres = nptl_freeres,
34 + .ptr_set_robust = __nptl_set_robust
36 # define ptr_pthread_functions &pthread_functions
38 # define ptr_pthread_functions NULL
45 +__nptl_set_robust (struct pthread *self)
47 + INTERNAL_SYSCALL_DECL (err);
48 + INTERNAL_SYSCALL (set_robust_list, err, 2, &self->robust_head,
49 + sizeof (struct robust_list_head));
54 /* This function is called indirectly from the freeres code in libc. */
55 diff -Nrup a/nptl/pthreadP.h b/nptl/pthreadP.h
56 --- a/nptl/pthreadP.h 2010-05-04 05:27:23.000000000 -0600
57 +++ b/nptl/pthreadP.h 2012-01-03 10:12:35.599269269 -0700
58 @@ -555,17 +555,20 @@ extern void __pthread_cleanup_pop_restor
60 /* Old cleanup interfaces, still used in libc.so. */
61 extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer *buffer,
62 - void (*routine) (void *), void *arg);
63 + void (*routine) (void *), void *arg);
64 extern void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *buffer,
67 extern void _pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *buffer,
68 - void (*routine) (void *), void *arg);
69 + void (*routine) (void *), void *arg);
70 extern void _pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer,
74 extern void __nptl_deallocate_tsd (void) attribute_hidden;
76 extern int __nptl_setxid (struct xid_command *cmdp) attribute_hidden;
78 +extern void __nptl_set_robust (struct pthread *self);
81 extern void __free_stacks (size_t limit) attribute_hidden;
83 diff -Nrup a/nptl/sysdeps/pthread/pthread-functions.h b/nptl/sysdeps/pthread/pthread-functions.h
84 --- a/nptl/sysdeps/pthread/pthread-functions.h 2010-05-04 05:27:23.000000000 -0600
85 +++ b/nptl/sysdeps/pthread/pthread-functions.h 2012-01-03 10:12:35.639269301 -0700
86 @@ -97,6 +97,7 @@ struct pthread_functions
87 void (*ptr__nptl_deallocate_tsd) (void);
88 int (*ptr__nptl_setxid) (struct xid_command *);
89 void (*ptr_freeres) (void);
90 + void (*ptr_set_robust) (struct pthread *);
93 /* Variable in libc.so. */
94 diff -Nrup a/nptl/sysdeps/unix/sysv/linux/fork.c b/nptl/sysdeps/unix/sysv/linux/fork.c
95 --- a/nptl/sysdeps/unix/sysv/linux/fork.c 2010-05-04 05:27:23.000000000 -0600
96 +++ b/nptl/sysdeps/unix/sysv/linux/fork.c 2012-01-03 10:12:35.649269309 -0700
99 #include <bits/stdio-lock.h>
101 +#include <pthreadP.h>
104 unsigned long int *__fork_generation_pointer;
105 @@ -86,8 +87,8 @@ __libc_fork (void)
106 just go away. The unloading code works in the order of the
109 - While executing the registered handlers we are building a
110 - list of all the entries so that we can go backward later on. */
111 + While executing the registered handlers we are building a
112 + list of all the entries so that we can go backward later on. */
115 /* Execute the handler if there is one. */
116 @@ -154,6 +155,24 @@ __libc_fork (void)
117 GL(dl_cpuclock_offset) = now;
120 +#ifdef __NR_set_robust_list
121 + /* Initialize the robust mutex list which has been reset during
122 + the fork. We do not check for errors since if it fails here
123 + it failed at process start as well and noone could have used
124 + robust mutexes. We also do not have to set
125 + self->robust_head.futex_offset since we inherit the correct
126 + value from the parent. */
128 + if (__libc_pthread_functions.ptr_set_robust != NULL)
129 + PTHFCT_CALL (ptr_set_robust, (self));
131 + extern __typeof (__nptl_set_robust) __nptl_set_robust
132 + __attribute__((weak));
133 + if (__builtin_expect (__nptl_set_robust != NULL, 0))
134 + __nptl_set_robust (self);
138 /* Reset the file list. These are recursive mutexes. */
141 @@ -170,10 +189,10 @@ __libc_fork (void)
142 allp->handler->child_handler ();
144 /* Note that we do not have to wake any possible waiter.
145 - This is the only thread in the new process. The count
146 - may have been bumped up by other threads doing a fork.
147 - We reset it to 1, to avoid waiting for non-existing
148 - thread(s) to release the count. */
149 + This is the only thread in the new process. The count
150 + may have been bumped up by other threads doing a fork.
151 + We reset it to 1, to avoid waiting for non-existing
152 + thread(s) to release the count. */
153 allp->handler->refcntr = 1;
155 /* XXX We could at this point look through the object pool