Sat Mar 10 18:01:10 2012 UTC ()
Use correct size.


(joerg)
diff -r1.129 -r1.130 src/lib/libpthread/pthread.c
diff -r1.23 -r1.24 src/lib/libpthread/sem.c

cvs diff -r1.129 -r1.130 src/lib/libpthread/pthread.c (expand / switch to unified diff)

--- src/lib/libpthread/pthread.c 2012/03/09 12:06:44 1.129
+++ src/lib/libpthread/pthread.c 2012/03/10 18:01:10 1.130
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pthread.c,v 1.129 2012/03/09 12:06:44 drochner Exp $ */ 1/* $NetBSD: pthread.c,v 1.130 2012/03/10 18:01:10 joerg Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Nathan J. Williams and Andrew Doran. 8 * by Nathan J. Williams and Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__RCSID("$NetBSD: pthread.c,v 1.129 2012/03/09 12:06:44 drochner Exp $"); 33__RCSID("$NetBSD: pthread.c,v 1.130 2012/03/10 18:01:10 joerg Exp $");
34 34
35#define __EXPOSE_STACK 1 35#define __EXPOSE_STACK 1
36 36
37#include <sys/param.h> 37#include <sys/param.h>
38#include <sys/exec_elf.h> 38#include <sys/exec_elf.h>
39#include <sys/mman.h> 39#include <sys/mman.h>
40#include <sys/sysctl.h> 40#include <sys/sysctl.h>
41#include <sys/lwpctl.h> 41#include <sys/lwpctl.h>
42#include <sys/tls.h> 42#include <sys/tls.h>
43 43
44#include <assert.h> 44#include <assert.h>
45#include <dlfcn.h> 45#include <dlfcn.h>
46#include <err.h> 46#include <err.h>
@@ -329,27 +329,27 @@ pthread__newstack(pthread_t newthread, c @@ -329,27 +329,27 @@ pthread__newstack(pthread_t newthread, c
329 stackbase = NULL; 329 stackbase = NULL;
330 stacksize = 0; 330 stacksize = 0;
331 } 331 }
332 if (stacksize == 0) 332 if (stacksize == 0)
333 stacksize = pthread__stacksize; 333 stacksize = pthread__stacksize;
334 334
335 if (stackbase == NULL) { 335 if (stackbase == NULL) {
336 stackbase = mmap(NULL, stacksize, 336 stackbase = mmap(NULL, stacksize,
337 PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, (off_t)0); 337 PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, (off_t)0);
338 if (stackbase == MAP_FAILED) 338 if (stackbase == MAP_FAILED)
339 return ENOMEM; 339 return ENOMEM;
340 mapped_stack = true; 340 mapped_stack = true;
341 } 341 }
342 newthread->pt_stack.ss_size = pthread__stacksize - pthread__pagesize; 342 newthread->pt_stack.ss_size = stacksize - pthread__pagesize;
343 newthread->pt_stack.ss_sp = stackbase; 343 newthread->pt_stack.ss_sp = stackbase;
344#ifdef __MACHINE_STACK_GROWS_UP 344#ifdef __MACHINE_STACK_GROWS_UP
345 redzone = (char *)stackbase + newthread->pt_stack.ss_size; 345 redzone = (char *)stackbase + newthread->pt_stack.ss_size;
346#else 346#else
347 redzone = (char *)stackbase; 347 redzone = (char *)stackbase;
348#endif 348#endif
349 if (mprotect(redzone, pthread__pagesize, PROT_NONE) == -1) { 349 if (mprotect(redzone, pthread__pagesize, PROT_NONE) == -1) {
350 if (mapped_stack) 350 if (mapped_stack)
351 munmap(stackbase, pthread__stacksize); 351 munmap(stackbase, pthread__stacksize);
352 return EPERM; 352 return EPERM;
353 } 353 }
354 return 0; 354 return 0;
355} 355}

cvs diff -r1.23 -r1.24 src/lib/libpthread/Attic/sem.c (expand / switch to unified diff)

--- src/lib/libpthread/Attic/sem.c 2012/03/08 21:59:28 1.23
+++ src/lib/libpthread/Attic/sem.c 2012/03/10 18:01:10 1.24
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sem.c,v 1.23 2012/03/08 21:59:28 joerg Exp $ */ 1/* $NetBSD: sem.c,v 1.24 2012/03/10 18:01:10 joerg Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2003, 2006, 2007 The NetBSD Foundation, Inc. 4 * Copyright (c) 2003, 2006, 2007 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of Wasabi Systems, Inc, and by Andrew Doran. 8 * by Jason R. Thorpe of Wasabi Systems, Inc, and by Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -49,27 +49,27 @@ @@ -49,27 +49,27 @@
49 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
51 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE 51 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
52 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 52 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
53 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 53 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
54 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 54 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
55 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 55 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
56 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 56 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
57 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 57 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
58 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 58 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 */ 59 */
60 60
61#include <sys/cdefs.h> 61#include <sys/cdefs.h>
62__RCSID("$NetBSD: sem.c,v 1.23 2012/03/08 21:59:28 joerg Exp $"); 62__RCSID("$NetBSD: sem.c,v 1.24 2012/03/10 18:01:10 joerg Exp $");
63 63
64#include <sys/types.h> 64#include <sys/types.h>
65#include <sys/ksem.h> 65#include <sys/ksem.h>
66#include <sys/queue.h> 66#include <sys/queue.h>
67#include <stdlib.h> 67#include <stdlib.h>
68#include <errno.h> 68#include <errno.h>
69#include <fcntl.h> 69#include <fcntl.h>
70#include <semaphore.h> 70#include <semaphore.h>
71#include <stdarg.h> 71#include <stdarg.h>
72 72
73#include "pthread.h" 73#include "pthread.h"
74 74
75struct _sem_st { 75struct _sem_st {
@@ -125,40 +125,41 @@ sem_init(sem_t *sem, int pshared, unsign @@ -125,40 +125,41 @@ sem_init(sem_t *sem, int pshared, unsign
125 125
126 if ((error = sem_alloc(value, semid, sem)) != 0) { 126 if ((error = sem_alloc(value, semid, sem)) != 0) {
127 _ksem_destroy(semid); 127 _ksem_destroy(semid);
128 errno = error; 128 errno = error;
129 return (-1); 129 return (-1);
130 } 130 }
131 131
132 return (0); 132 return (0);
133} 133}
134 134
135int 135int
136sem_destroy(sem_t *sem) 136sem_destroy(sem_t *sem)
137{ 137{
 138 int error, save_errno;
138 139
139#ifdef ERRORCHECK 140#ifdef ERRORCHECK
140 if (sem == NULL || *sem == NULL || (*sem)->ksem_magic != KSEM_MAGIC) { 141 if (sem == NULL || *sem == NULL || (*sem)->ksem_magic != KSEM_MAGIC) {
141 errno = EINVAL; 142 errno = EINVAL;
142 return (-1); 143 return (-1);
143 } 144 }
144#endif 145#endif
145 146
146 if (_ksem_destroy((*sem)->ksem_semid) == -1) 147 error = _ksem_destroy((*sem)->ksem_semid);
147 return (-1); 148 save_errno = errno;
148 
149 sem_free(*sem); 149 sem_free(*sem);
 150 errno = save_errno;
150 151
151 return (0); 152 return error;
152} 153}
153 154
154sem_t * 155sem_t *
155sem_open(const char *name, int oflag, ...) 156sem_open(const char *name, int oflag, ...)
156{ 157{
157 sem_t *sem, s; 158 sem_t *sem, s;
158 intptr_t semid; 159 intptr_t semid;
159 mode_t mode; 160 mode_t mode;
160 unsigned int value; 161 unsigned int value;
161 int error; 162 int error;
162 va_list ap; 163 va_list ap;
163 164
164 mode = 0; 165 mode = 0;
@@ -208,45 +209,44 @@ sem_open(const char *name, int oflag, .. @@ -208,45 +209,44 @@ sem_open(const char *name, int oflag, ..
208 _ksem_close(semid); 209 _ksem_close(semid);
209 if (sem != NULL) { 210 if (sem != NULL) {
210 if (*sem != NULL) 211 if (*sem != NULL)
211 sem_free(*sem); 212 sem_free(*sem);
212 free(sem); 213 free(sem);
213 } 214 }
214 errno = error; 215 errno = error;
215 return (SEM_FAILED); 216 return (SEM_FAILED);
216} 217}
217 218
218int 219int
219sem_close(sem_t *sem) 220sem_close(sem_t *sem)
220{ 221{
 222 int error, save_errno;
221 223
222#ifdef ERRORCHECK 224#ifdef ERRORCHECK
223 if (sem == NULL || *sem == NULL || (*sem)->ksem_magic != KSEM_MAGIC) { 225 if (sem == NULL || *sem == NULL || (*sem)->ksem_magic != KSEM_MAGIC) {
224 errno = EINVAL; 226 errno = EINVAL;
225 return (-1); 227 return (-1);
226 } 228 }
227#endif 229#endif
228 230
229 pthread_mutex_lock(&named_sems_mtx); 231 pthread_mutex_lock(&named_sems_mtx);
230 if (_ksem_close((*sem)->ksem_semid) == -1) { 232 error = _ksem_close((*sem)->ksem_semid);
231 pthread_mutex_unlock(&named_sems_mtx); 
232 return (-1); 
233 } 
234 
235 LIST_REMOVE((*sem), ksem_list); 233 LIST_REMOVE((*sem), ksem_list);
 234 save_errno = errno;
236 pthread_mutex_unlock(&named_sems_mtx); 235 pthread_mutex_unlock(&named_sems_mtx);
237 sem_free(*sem); 236 sem_free(*sem);
238 free(sem); 237 free(sem);
239 return (0); 238 errno = save_errno;
 239 return error;
240} 240}
241 241
242int 242int
243sem_unlink(const char *name) 243sem_unlink(const char *name)
244{ 244{
245 245
246 return (_ksem_unlink(name)); 246 return (_ksem_unlink(name));
247} 247}
248 248
249int 249int
250sem_wait(sem_t *sem) 250sem_wait(sem_t *sem)
251{ 251{
252 252