]>
Commit | Line | Data |
---|---|---|
3955fda5 JR |
1 | From 16be5568a0c24b9bd1ade7fa937c94b5d53b6ab1 Mon Sep 17 00:00:00 2001 |
2 | From: "H.J. Lu" <hjl.tools@gmail.com> | |
3 | Date: Sun, 15 Oct 2017 07:48:58 -0700 | |
4 | Subject: [PATCH] Define __PTHREAD_MUTEX_HAVE_PREV only if undefined [BZ | |
5 | #22298] | |
6 | ||
7 | It is incorrect to define __PTHREAD_MUTEX_HAVE_PREV to 1 only when | |
8 | __WORDSIZE == 64. For x32, __PTHREAD_MUTEX_HAVE_PREV should be 1, but | |
9 | it has __WORDSIZE == 32. This patch defines __PTHREAD_MUTEX_HAVE_PREV | |
10 | based on __WORDSIZE only if it is undefined. __PTHREAD_MUTEX_HAVE_PREV | |
11 | check is changed from "#ifdef" to "#if" to support values of 0 or 1. | |
12 | ||
13 | [BZ #22298] | |
14 | * nptl/allocatestack.c (allocate_stack): Check if | |
15 | __PTHREAD_MUTEX_HAVE_PREV is non-zero, instead if | |
16 | __PTHREAD_MUTEX_HAVE_PREV is defined. | |
17 | * nptl/descr.h (pthread): Likewise. | |
18 | * nptl/nptl-init.c (__pthread_initialize_minimal_internal): | |
19 | Likewise. | |
20 | * nptl/pthread_create.c (START_THREAD_DEFN): Likewise. | |
21 | * sysdeps/nptl/fork.c (__libc_fork): Likewise. | |
22 | * sysdeps/nptl/pthread.h (PTHREAD_MUTEX_INITIALIZER): Likewise. | |
23 | * sysdeps/nptl/bits/thread-shared-types.h | |
24 | (__PTHREAD_MUTEX_HAVE_PREV): Define only if it is undefined. | |
25 | (__pthread_internal_list): Check __pthread_internal_list instead | |
26 | of __WORDSIZE. | |
27 | (__PTHREAD_SPINS_DATA): Likewise. | |
28 | (__PTHREAD_SPINS): Likewise. | |
29 | (__pthread_mutex_s): Likewise. | |
30 | * sysdeps/x86/nptl/bits/pthreadtypes-arch.h | |
31 | (__PTHREAD_MUTEX_HAVE_PREV): Defined. | |
32 | --- | |
33 | nptl/allocatestack.c | 2 +- | |
34 | nptl/descr.h | 2 +- | |
35 | nptl/nptl-init.c | 2 +- | |
36 | nptl/pthread_create.c | 4 ++-- | |
37 | sysdeps/nptl/bits/thread-shared-types.h | 17 ++++++++++++----- | |
38 | sysdeps/nptl/fork.c | 2 +- | |
39 | sysdeps/nptl/pthread.h | 2 +- | |
40 | sysdeps/x86/nptl/bits/pthreadtypes-arch.h | 2 ++ | |
41 | 8 files changed, 21 insertions(+), 12 deletions(-) | |
42 | ||
43 | diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c | |
44 | index ad9add8..1cc7893 100644 | |
45 | --- a/nptl/allocatestack.c | |
46 | +++ b/nptl/allocatestack.c | |
47 | @@ -753,7 +753,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, | |
48 | - offsetof (pthread_mutex_t, | |
49 | __data.__list.__next)); | |
50 | pd->robust_head.list_op_pending = NULL; | |
51 | -#ifdef __PTHREAD_MUTEX_HAVE_PREV | |
52 | +#if __PTHREAD_MUTEX_HAVE_PREV | |
53 | pd->robust_prev = &pd->robust_head; | |
54 | #endif | |
55 | pd->robust_head.list = &pd->robust_head; | |
56 | diff --git a/nptl/descr.h b/nptl/descr.h | |
57 | index c5ad0c8..c83b17b 100644 | |
58 | --- a/nptl/descr.h | |
59 | +++ b/nptl/descr.h | |
60 | @@ -169,7 +169,7 @@ struct pthread | |
61 | pid_t pid_ununsed; | |
62 | ||
63 | /* List of robust mutexes the thread is holding. */ | |
64 | -#ifdef __PTHREAD_MUTEX_HAVE_PREV | |
65 | +#if __PTHREAD_MUTEX_HAVE_PREV | |
66 | void *robust_prev; | |
67 | struct robust_list_head robust_head; | |
68 | ||
69 | diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c | |
70 | index 2921607..869e926 100644 | |
71 | --- a/nptl/nptl-init.c | |
72 | +++ b/nptl/nptl-init.c | |
73 | @@ -297,7 +297,7 @@ __pthread_initialize_minimal_internal (void) | |
74 | ||
75 | /* Initialize the robust mutex data. */ | |
76 | { | |
77 | -#ifdef __PTHREAD_MUTEX_HAVE_PREV | |
78 | +#if __PTHREAD_MUTEX_HAVE_PREV | |
79 | pd->robust_prev = &pd->robust_head; | |
80 | #endif | |
81 | pd->robust_head.list = &pd->robust_head; | |
82 | diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c | |
83 | index 992331e..51ae60d 100644 | |
84 | --- a/nptl/pthread_create.c | |
85 | +++ b/nptl/pthread_create.c | |
86 | @@ -518,7 +518,7 @@ START_THREAD_DEFN | |
87 | ||
88 | #ifndef __ASSUME_SET_ROBUST_LIST | |
89 | /* If this thread has any robust mutexes locked, handle them now. */ | |
90 | -# ifdef __PTHREAD_MUTEX_HAVE_PREV | |
91 | +# if __PTHREAD_MUTEX_HAVE_PREV | |
92 | void *robust = pd->robust_head.list; | |
93 | # else | |
94 | __pthread_slist_t *robust = pd->robust_list.__next; | |
95 | @@ -536,7 +536,7 @@ START_THREAD_DEFN | |
96 | __list.__next)); | |
97 | robust = *((void **) robust); | |
98 | ||
99 | -# ifdef __PTHREAD_MUTEX_HAVE_PREV | |
100 | +# if __PTHREAD_MUTEX_HAVE_PREV | |
101 | this->__list.__prev = NULL; | |
102 | # endif | |
103 | this->__list.__next = NULL; | |
104 | diff --git a/sysdeps/nptl/bits/thread-shared-types.h b/sysdeps/nptl/bits/thread-shared-types.h | |
105 | index 68b82b6..d2c4f67 100644 | |
106 | --- a/sysdeps/nptl/bits/thread-shared-types.h | |
107 | +++ b/sysdeps/nptl/bits/thread-shared-types.h | |
108 | @@ -59,7 +59,15 @@ | |
109 | ||
110 | /* Common definition of pthread_mutex_t. */ | |
111 | ||
112 | -#if __WORDSIZE == 64 | |
113 | +#ifndef __PTHREAD_MUTEX_HAVE_PREV | |
114 | +# if __WORDSIZE == 64 | |
115 | +# define __PTHREAD_MUTEX_HAVE_PREV 1 | |
116 | +# else | |
117 | +# define __PTHREAD_MUTEX_HAVE_PREV 0 | |
118 | +# endif | |
119 | +#endif | |
120 | + | |
121 | +#if __PTHREAD_MUTEX_HAVE_PREV | |
122 | typedef struct __pthread_internal_list | |
123 | { | |
124 | struct __pthread_internal_list *__prev; | |
125 | @@ -74,7 +82,7 @@ typedef struct __pthread_internal_slist | |
126 | ||
127 | /* Lock elision support. */ | |
128 | #if __PTHREAD_MUTEX_LOCK_ELISION | |
129 | -# if __WORDSIZE == 64 | |
130 | +# if __PTHREAD_MUTEX_HAVE_PREV | |
131 | # define __PTHREAD_SPINS_DATA \ | |
132 | short __spins; \ | |
133 | short __elision | |
134 | @@ -101,17 +109,16 @@ struct __pthread_mutex_s | |
135 | int __lock __LOCK_ALIGNMENT; | |
136 | unsigned int __count; | |
137 | int __owner; | |
138 | -#if __WORDSIZE == 64 | |
139 | +#if __PTHREAD_MUTEX_HAVE_PREV | |
140 | unsigned int __nusers; | |
141 | #endif | |
142 | /* KIND must stay at this position in the structure to maintain | |
143 | binary compatibility with static initializers. */ | |
144 | int __kind; | |
145 | __PTHREAD_COMPAT_PADDING_MID | |
146 | -#if __WORDSIZE == 64 | |
147 | +#if __PTHREAD_MUTEX_HAVE_PREV | |
148 | __PTHREAD_SPINS_DATA; | |
149 | __pthread_list_t __list; | |
150 | -# define __PTHREAD_MUTEX_HAVE_PREV 1 | |
151 | #else | |
152 | unsigned int __nusers; | |
153 | __extension__ union | |
154 | diff --git a/sysdeps/nptl/fork.c b/sysdeps/nptl/fork.c | |
155 | index 4bb87e2..48676c2 100644 | |
156 | --- a/sysdeps/nptl/fork.c | |
157 | +++ b/sysdeps/nptl/fork.c | |
158 | @@ -166,7 +166,7 @@ __libc_fork (void) | |
159 | inherit the correct value from the parent. We do not need to clear | |
160 | the pending operation because it must have been zero when fork was | |
161 | called. */ | |
162 | -# ifdef __PTHREAD_MUTEX_HAVE_PREV | |
163 | +# if __PTHREAD_MUTEX_HAVE_PREV | |
164 | self->robust_prev = &self->robust_head; | |
165 | # endif | |
166 | self->robust_head.list = &self->robust_head; | |
167 | diff --git a/sysdeps/nptl/pthread.h b/sysdeps/nptl/pthread.h | |
168 | index 632ea7b..2b2b386 100644 | |
169 | --- a/sysdeps/nptl/pthread.h | |
170 | +++ b/sysdeps/nptl/pthread.h | |
171 | @@ -83,7 +83,7 @@ enum | |
172 | #endif | |
173 | ||
174 | ||
175 | -#ifdef __PTHREAD_MUTEX_HAVE_PREV | |
176 | +#if __PTHREAD_MUTEX_HAVE_PREV | |
177 | # define PTHREAD_MUTEX_INITIALIZER \ | |
178 | { { 0, 0, 0, 0, 0, __PTHREAD_SPINS, { 0, 0 } } } | |
179 | # ifdef __USE_GNU | |
180 | diff --git a/sysdeps/x86/nptl/bits/pthreadtypes-arch.h b/sysdeps/x86/nptl/bits/pthreadtypes-arch.h | |
181 | index fd86806..2446d8d 100644 | |
182 | --- a/sysdeps/x86/nptl/bits/pthreadtypes-arch.h | |
183 | +++ b/sysdeps/x86/nptl/bits/pthreadtypes-arch.h | |
184 | @@ -21,6 +21,7 @@ | |
185 | #include <bits/wordsize.h> | |
186 | ||
187 | #ifdef __x86_64__ | |
188 | +# define __PTHREAD_MUTEX_HAVE_PREV 1 | |
189 | # if __WORDSIZE == 64 | |
190 | # define __SIZEOF_PTHREAD_MUTEX_T 40 | |
191 | # define __SIZEOF_PTHREAD_ATTR_T 56 | |
192 | @@ -35,6 +36,7 @@ | |
193 | # define __SIZEOF_PTHREAD_BARRIER_T 20 | |
194 | # endif | |
195 | #else | |
196 | +# define __PTHREAD_MUTEX_HAVE_PREV 0 | |
197 | # define __SIZEOF_PTHREAD_MUTEX_T 24 | |
198 | # define __SIZEOF_PTHREAD_ATTR_T 36 | |
199 | # define __SIZEOF_PTHREAD_MUTEX_T 24 | |
200 | -- | |
201 | 2.9.3 | |
202 | ||
203 | From df44f9d02b68de45ba8c3984f47ecf1a523306ec Mon Sep 17 00:00:00 2001 | |
204 | From: "H.J. Lu" <hjl.tools@gmail.com> | |
205 | Date: Sun, 15 Oct 2017 07:23:41 -0700 | |
206 | Subject: [PATCH] x32: Verify that NPTL structures are correct [BZ #22298] | |
207 | ||
208 | Add a build-time check to verify that NPTL structures are correct. | |
209 | ||
210 | * sysdeps/x86_64/x32/nptl/Makefile: New file. | |
211 | * sysdeps/x86_64/x32/nptl/nptl-check.sym: Likewise. | |
212 | --- | |
213 | sysdeps/x86_64/x32/nptl/Makefile | 4 ++++ | |
214 | sysdeps/x86_64/x32/nptl/nptl-check.sym | 9 +++++++++ | |
215 | 2 files changed, 13 insertions(+) | |
216 | create mode 100644 sysdeps/x86_64/x32/nptl/Makefile | |
217 | create mode 100644 sysdeps/x86_64/x32/nptl/nptl-check.sym | |
218 | ||
219 | diff --git a/sysdeps/x86_64/x32/nptl/Makefile b/sysdeps/x86_64/x32/nptl/Makefile | |
220 | new file mode 100644 | |
221 | index 0000000..e780bea | |
222 | --- /dev/null | |
223 | +++ b/sysdeps/x86_64/x32/nptl/Makefile | |
224 | @@ -0,0 +1,4 @@ | |
225 | +ifeq ($(subdir),csu) | |
226 | +# Verify that NPTL structures are correct. | |
227 | +gen-as-const-headers += nptl-check.sym | |
228 | +endif | |
229 | diff --git a/sysdeps/x86_64/x32/nptl/nptl-check.sym b/sysdeps/x86_64/x32/nptl/nptl-check.sym | |
230 | new file mode 100644 | |
231 | index 0000000..8573250 | |
232 | --- /dev/null | |
233 | +++ b/sysdeps/x86_64/x32/nptl/nptl-check.sym | |
234 | @@ -0,0 +1,9 @@ | |
235 | +#include <sysdep.h> | |
236 | +#include <pthread.h> | |
237 | + | |
238 | +PREV offsetof (struct __pthread_internal_list, __prev) | |
239 | +NEXT offsetof (struct __pthread_internal_list, __next) | |
240 | + | |
241 | +#if __PTHREAD_MUTEX_HAVE_PREV != 1 | |
242 | +#error __PTHREAD_MUTEX_HAVE_PREV must be 1 | |
243 | +#endif | |
244 | -- | |
245 | 2.9.3 | |
246 |