summaryrefslogtreecommitdiff
path: root/lib/librthread
diff options
context:
space:
mode:
authorPhilip Guenthe <guenther@cvs.openbsd.org>2012-02-19 06:53:59 +0000
committerPhilip Guenthe <guenther@cvs.openbsd.org>2012-02-19 06:53:59 +0000
commite677f17adc41d650ea11426ca2d736bcf82312e0 (patch)
treeab5cca61994f8c71e59294515fa086065e171fb2 /lib/librthread
parentdfed3a791ee2ea61fe73b00b9c48349db108ee91 (diff)
Fix problems revealed by regress/lib/libpthread/stack/stack.c
Diffstat (limited to 'lib/librthread')
-rw-r--r--lib/librthread/rthread_attr.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/lib/librthread/rthread_attr.c b/lib/librthread/rthread_attr.c
index ef0c30efbf1..7bd33248b4b 100644
--- a/lib/librthread/rthread_attr.c
+++ b/lib/librthread/rthread_attr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread_attr.c,v 1.15 2012/02/19 02:07:48 guenther Exp $ */
+/* $OpenBSD: rthread_attr.c,v 1.16 2012/02/19 06:53:58 guenther Exp $ */
/*
* Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
* All Rights Reserved.
@@ -50,6 +50,12 @@ int
pthread_attr_init(pthread_attr_t *attrp)
{
pthread_attr_t attr;
+ int error;
+
+ /* make sure _rthread_attr_default has been initialized */
+ if (!_threads_ready)
+ if ((error = _rthread_init()))
+ return (error);
attr = calloc(1, sizeof(*attr));
if (!attr)
@@ -111,6 +117,7 @@ pthread_attr_getstack(const pthread_attr_t *attrp, void **stackaddr,
size_t *stacksize)
{
*stackaddr = (*attrp)->stack_addr;
+ *stacksize = (*attrp)->stack_size;
return (0);
}
@@ -144,11 +151,6 @@ pthread_attr_getstacksize(const pthread_attr_t *attrp, size_t *stacksize)
int
pthread_attr_setstacksize(pthread_attr_t *attrp, size_t stacksize)
{
- int error;
-
- if (!_threads_ready)
- if ((error = _rthread_init()))
- return (error);
if (stacksize < PTHREAD_STACK_MIN ||
stacksize > ROUND_TO_PAGE(stacksize))
return (EINVAL);
@@ -168,11 +170,6 @@ pthread_attr_getstackaddr(const pthread_attr_t *attrp, void **stackaddr)
int
pthread_attr_setstackaddr(pthread_attr_t *attrp, void *stackaddr)
{
- int error;
-
- if (!_threads_ready)
- if ((error = _rthread_init()))
- return (error);
if (stackaddr == NULL || (uintptr_t)stackaddr & (_thread_pagesize - 1))
return (EINVAL);
(*attrp)->stack_addr = stackaddr;