Attachment 'hppa-nptl-2012-12-16.diff'
Download 1 diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
2 index 799dbe3..683c652 100644
3 --- a/nptl/allocatestack.c
4 +++ b/nptl/allocatestack.c
5 @@ -361,6 +361,15 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
6 if (__builtin_expect (attr->flags & ATTR_FLAG_STACKADDR, 0))
7 {
8 uintptr_t adj;
9 +#if _STACK_GROWS_DOWN
10 + char * stackaddr = (char *) attr->stackaddr;
11 +#else
12 + /* Assume the same layout as the _STACK_GROWS_DOWN case,
13 + with struct pthread at the top of the stack block.
14 + Later we adjust the guard location and stack address
15 + to match the _STACK_GROWS_UP case. */
16 + char * stackaddr = (char *) attr->stackaddr + attr->stacksize;
17 +#endif
18
19 /* If the user also specified the size of the stack make sure it
20 is large enough. */
21 @@ -370,11 +379,11 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
22
23 /* Adjust stack size for alignment of the TLS block. */
24 #if TLS_TCB_AT_TP
25 - adj = ((uintptr_t) attr->stackaddr - TLS_TCB_SIZE)
26 + adj = ((uintptr_t) stackaddr - TLS_TCB_SIZE)
27 & __static_tls_align_m1;
28 assert (size > adj + TLS_TCB_SIZE);
29 #elif TLS_DTV_AT_TP
30 - adj = ((uintptr_t) attr->stackaddr - __static_tls_size)
31 + adj = ((uintptr_t) stackaddr - __static_tls_size)
32 & __static_tls_align_m1;
33 assert (size > adj);
34 #endif
35 @@ -384,10 +393,10 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
36 the stack. It is the user's responsibility to do this if it
37 is wanted. */
38 #if TLS_TCB_AT_TP
39 - pd = (struct pthread *) ((uintptr_t) attr->stackaddr
40 + pd = (struct pthread *) ((uintptr_t) stackaddr
41 - TLS_TCB_SIZE - adj);
42 #elif TLS_DTV_AT_TP
43 - pd = (struct pthread *) (((uintptr_t) attr->stackaddr
44 + pd = (struct pthread *) (((uintptr_t) stackaddr
45 - __static_tls_size - adj)
46 - TLS_PRE_TCB_SIZE);
47 #endif
48 @@ -399,7 +408,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
49 pd->specific[0] = pd->specific_1stblock;
50
51 /* Remember the stack-related values. */
52 - pd->stackblock = (char *) attr->stackaddr - size;
53 + pd->stackblock = (char *) stackaddr - size;
54 pd->stackblock_size = size;
55
56 /* This is a user-provided stack. It will not be queued in the
57 @@ -625,7 +634,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
58 char *guard = mem + (((size - guardsize) / 2) & ~pagesize_m1);
59 #elif _STACK_GROWS_DOWN
60 char *guard = mem;
61 -# elif _STACK_GROWS_UP
62 +#elif _STACK_GROWS_UP
63 char *guard = (char *) (((uintptr_t) pd - guardsize) & ~pagesize_m1);
64 #endif
65 if (mprotect (guard, guardsize, PROT_NONE) != 0)
66 @@ -675,9 +684,13 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
67 prot) != 0)
68 goto mprot_error;
69 #elif _STACK_GROWS_UP
70 - if (mprotect ((char *) pd - pd->guardsize,
71 - pd->guardsize - guardsize, prot) != 0)
72 - goto mprot_error;
73 + char *new_guard = (char *) (((uintptr_t) pd - guardsize) & ~pagesize_m1);
74 + char *old_guard = (char *) (((uintptr_t) pd - pd->guardsize) & ~pagesize_m1);
75 + /* The guard size difference might be > 0, but once rounded
76 + to the nearest page the size difference might be zero. */
77 + if (old_guard - new_guard > 0)
78 + if (mprotect (old_guard, new_guard - old_guard, prot) != 0)
79 + goto mprot_error;
80 #endif
81
82 pd->guardsize = guardsize;
83 @@ -720,8 +733,10 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
84 #elif _STACK_GROWS_DOWN
85 *stack = stacktop;
86 #elif _STACK_GROWS_UP
87 + /* We don't use stacktop. In _STACK_GROWS_UP the start
88 + of the stack is simply stackblock (lowest address of
89 + the stored block of memory for the stack). */
90 *stack = pd->stackblock;
91 - assert (*stack > 0);
92 #endif
93
94 return 0;
95 diff --git a/nptl/pthread_attr_getstack.c b/nptl/pthread_attr_getstack.c
96 index 0ede9e7..a468435 100644
97 --- a/nptl/pthread_attr_getstack.c
98 +++ b/nptl/pthread_attr_getstack.c
99 @@ -1,4 +1,4 @@
100 -/* Copyright (C) 2002 Free Software Foundation, Inc.
101 +/* Copyright (C) 2002, 2010 Free Software Foundation, Inc.
102 This file is part of the GNU C Library.
103 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
104
105 @@ -32,7 +32,11 @@ __pthread_attr_getstack (attr, stackaddr, stacksize)
106 iattr = (struct pthread_attr *) attr;
107
108 /* Store the result. */
109 +#ifdef _STACK_GROWS_DOWN
110 *stackaddr = (char *) iattr->stackaddr - iattr->stacksize;
111 +#else
112 + *stackaddr = (char *) iattr->stackaddr;
113 +#endif
114 *stacksize = iattr->stacksize;
115
116 return 0;
117 diff --git a/nptl/pthread_attr_setstack.c b/nptl/pthread_attr_setstack.c
118 index 72eaee2..5f6a5ae 100644
119 --- a/nptl/pthread_attr_setstack.c
120 +++ b/nptl/pthread_attr_setstack.c
121 @@ -1,4 +1,4 @@
122 -/* Copyright (C) 2002, 2003, 2006 Free Software Foundation, Inc.
123 +/* Copyright (C) 2002, 2003, 2006, 2010 Free Software Foundation, Inc.
124 This file is part of the GNU C Library.
125 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
126
127 @@ -47,7 +47,11 @@ __pthread_attr_setstack (attr, stackaddr, stacksize)
128 #endif
129
130 iattr->stacksize = stacksize;
131 +#if _STACK_GROWS_DOWN
132 iattr->stackaddr = (char *) stackaddr + stacksize;
133 +#else
134 + iattr->stackaddr = (char *) stackaddr;
135 +#endif
136 iattr->flags |= ATTR_FLAG_STACKADDR;
137
138 return 0;
139 @@ -80,7 +84,11 @@ __old_pthread_attr_setstack (pthread_attr_t *attr, void *stackaddr,
140 # endif
141
142 iattr->stacksize = stacksize;
143 +#if _STACK_GROWS_DOWN
144 iattr->stackaddr = (char *) stackaddr + stacksize;
145 +#else
146 + iattr->stackaddr = (char *) stackaddr;
147 +#endif
148 iattr->flags |= ATTR_FLAG_STACKADDR;
149
150 return 0;
151 diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
152 index 197dfa7..87b64e5 100644
153 --- a/nptl/pthread_create.c
154 +++ b/nptl/pthread_create.c
155 @@ -394,13 +394,26 @@ start_thread (void *arg)
156 #ifdef _STACK_GROWS_DOWN
157 char *sp = CURRENT_STACK_FRAME;
158 size_t freesize = (sp - (char *) pd->stackblock) & ~pagesize_m1;
159 -#else
160 -# error "to do"
161 -#endif
162 assert (freesize < pd->stackblock_size);
163 if (freesize > PTHREAD_STACK_MIN)
164 __madvise (pd->stackblock, freesize - PTHREAD_STACK_MIN, MADV_DONTNEED);
165 -
166 +#else
167 + /* Page aligned start of memory to free (higher than or equal
168 + to current sp plus the minimum stack size). */
169 + void *freeblock = (void*)((size_t)(CURRENT_STACK_FRAME
170 + + PTHREAD_STACK_MIN
171 + + pagesize_m1)
172 + & ~pagesize_m1);
173 + char *free_end = (char *) (((uintptr_t) pd - pd->guardsize) & ~pagesize_m1);
174 + /* Is there any space to free? */
175 + if (free_end > (char *)freeblock)
176 + {
177 + size_t freesize = (size_t)(free_end - (char *)freeblock);
178 + assert (freesize < pd->stackblock_size);
179 + __madvise (freeblock, freesize, MADV_DONTNEED);
180 + }
181 +#endif
182 +
183 /* If the thread is detached free the TCB. */
184 if (IS_DETACHED (pd))
185 /* Free the TCB. */
186 diff --git a/nptl/pthread_getattr_np.c b/nptl/pthread_getattr_np.c
187 index 7309185..6c82221 100644
188 --- a/nptl/pthread_getattr_np.c
189 +++ b/nptl/pthread_getattr_np.c
190 @@ -60,7 +60,11 @@ pthread_getattr_np (thread_id, attr)
191 if (__builtin_expect (thread->stackblock != NULL, 1))
192 {
193 iattr->stacksize = thread->stackblock_size;
194 +#ifdef _STACK_GROWS_DOWN
195 iattr->stackaddr = (char *) thread->stackblock + iattr->stacksize;
196 +#else
197 + iattr->stackaddr = (char *) thread->stackblock;
198 +#endif
199 }
200 else
201 {
202 @@ -129,12 +133,17 @@ pthread_getattr_np (thread_id, attr)
203 stack extension request. */
204 iattr->stacksize = (iattr->stacksize
205 & -(intptr_t) GLRO(dl_pagesize));
206 -
207 +#if _STACK_GROWS_DOWN
208 /* The limit might be too high. */
209 if ((size_t) iattr->stacksize
210 > (size_t) iattr->stackaddr - last_to)
211 iattr->stacksize = (size_t) iattr->stackaddr - last_to;
212 -
213 +#else
214 + /* The limit might be too high. */
215 + if ((size_t) iattr->stacksize
216 + > to - (size_t) iattr->stackaddr)
217 + iattr->stacksize = to - (size_t) iattr->stackaddr;
218 +#endif
219 /* We succeed and no need to look further. */
220 ret = 0;
221 break;
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.- [get | view] (2012-12-16 20:57:13, 7.9 KB) [[attachment:hppa-nptl-2012-12-16.diff]]
- [get | view] (2012-12-17 15:00:54, 27.5 KB) [[attachment:s390x-test-double.out]]
- [get | view] (2012-12-17 15:00:21, 24.1 KB) [[attachment:s390x-test-float.out]]
- [get | view] (2012-12-17 15:01:17, 27.5 KB) [[attachment:s390x-test-idouble.out]]
- [get | view] (2012-12-17 15:01:52, 24.1 KB) [[attachment:s390x-test-ifloat.out]]
- [get | view] (2012-12-17 15:02:12, 55.6 KB) [[attachment:s390x-test-ildouble.out]]
- [get | view] (2012-12-17 15:02:30, 55.6 KB) [[attachment:s390x-test-ldouble.out]]
You are not allowed to attach a file to this page.