summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordavidxu <davidxu@FreeBSD.org>2003-09-14 22:39:44 +0000
committerdavidxu <davidxu@FreeBSD.org>2003-09-14 22:39:44 +0000
commitb622332e18b29fb3d634953210ec0be4db366373 (patch)
treee7ea22439446d401f0fb1dbd32800ea86c76308d
parent5b99feb20561244587f5f8e73a977ae420b42fdf (diff)
downloadFreeBSD-src-b622332e18b29fb3d634953210ec0be4db366373.zip
FreeBSD-src-b622332e18b29fb3d634953210ec0be4db366373.tar.gz
Respect POSIX specification, a value return from pthread_attr_getguardsize
should be a value past to pthread_attr_setguardsize, not a rounded up value. Also fix a stack size matching bug in thr_stack.c, now stack matching code uses number of pages but not bytes length to match stack size, so for example, size 512 bytes and size 513 bytes should both match 1 page stack size. Reviewed by: deischen
-rw-r--r--lib/libkse/thread/thr_attr_setguardsize.c8
-rw-r--r--lib/libkse/thread/thr_stack.c26
-rw-r--r--lib/libpthread/thread/thr_attr_setguardsize.c8
-rw-r--r--lib/libpthread/thread/thr_stack.c26
4 files changed, 36 insertions, 32 deletions
diff --git a/lib/libkse/thread/thr_attr_setguardsize.c b/lib/libkse/thread/thr_attr_setguardsize.c
index 59ec908..d56b254 100644
--- a/lib/libkse/thread/thr_attr_setguardsize.c
+++ b/lib/libkse/thread/thr_attr_setguardsize.c
@@ -45,14 +45,6 @@ _pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize)
if (attr == NULL || *attr == NULL)
ret = EINVAL;
else {
- /*
- * Round guardsize up to the nearest multiple of
- * _thr_page_size.
- */
- if (guardsize % _thr_page_size != 0)
- guardsize = ((guardsize / _thr_page_size) + 1) *
- _thr_page_size;
-
/* Save the stack size. */
(*attr)->guardsize_attr = guardsize;
ret = 0;
diff --git a/lib/libkse/thread/thr_stack.c b/lib/libkse/thread/thr_stack.c
index 530e2b9..9714593 100644
--- a/lib/libkse/thread/thr_stack.c
+++ b/lib/libkse/thread/thr_stack.c
@@ -113,6 +113,19 @@ static LIST_HEAD(, stack) mstackq = LIST_HEAD_INITIALIZER(mstackq);
*/
static void *last_stack = NULL;
+/*
+ * Round size up to the nearest multiple of
+ * _thr_page_size.
+ */
+static inline size_t
+round_up(size_t size)
+{
+ if (size % _thr_page_size != 0)
+ size = ((size / _thr_page_size) + 1) *
+ _thr_page_size;
+ return size;
+}
+
int
_thr_stack_alloc(struct pthread_attr *attr)
{
@@ -122,9 +135,6 @@ _thr_stack_alloc(struct pthread_attr *attr)
size_t stacksize;
size_t guardsize;
- stacksize = attr->stacksize_attr;
- guardsize = attr->guardsize_attr;
-
/*
* Round up stack size to nearest multiple of _thr_page_size so
* that mmap() * will work. If the stack size is not an even
@@ -132,9 +142,9 @@ _thr_stack_alloc(struct pthread_attr *attr)
* unused space above the beginning of the stack, so the stack
* sits snugly against its guard.
*/
- if ((stacksize % _thr_page_size) != 0)
- stacksize = ((stacksize / _thr_page_size) + 1) *
- _thr_page_size;
+ stacksize = round_up(attr->stacksize_attr);
+ guardsize = round_up(attr->guardsize_attr);
+
attr->stackaddr_attr = NULL;
attr->flags &= ~THR_STACK_USER;
@@ -221,8 +231,8 @@ _thr_stack_free(struct pthread_attr *attr)
&& (attr->stackaddr_attr != NULL)) {
spare_stack = (attr->stackaddr_attr + attr->stacksize_attr
- sizeof(struct stack));
- spare_stack->stacksize = attr->stacksize_attr;
- spare_stack->guardsize = attr->guardsize_attr;
+ spare_stack->stacksize = round_up(attr->stacksize_attr);
+ spare_stack->guardsize = round_up(attr->guardsize_attr);
spare_stack->stackaddr = attr->stackaddr_attr;
if (spare_stack->stacksize == THR_STACK_DEFAULT &&
diff --git a/lib/libpthread/thread/thr_attr_setguardsize.c b/lib/libpthread/thread/thr_attr_setguardsize.c
index 59ec908..d56b254 100644
--- a/lib/libpthread/thread/thr_attr_setguardsize.c
+++ b/lib/libpthread/thread/thr_attr_setguardsize.c
@@ -45,14 +45,6 @@ _pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize)
if (attr == NULL || *attr == NULL)
ret = EINVAL;
else {
- /*
- * Round guardsize up to the nearest multiple of
- * _thr_page_size.
- */
- if (guardsize % _thr_page_size != 0)
- guardsize = ((guardsize / _thr_page_size) + 1) *
- _thr_page_size;
-
/* Save the stack size. */
(*attr)->guardsize_attr = guardsize;
ret = 0;
diff --git a/lib/libpthread/thread/thr_stack.c b/lib/libpthread/thread/thr_stack.c
index 530e2b9..9714593 100644
--- a/lib/libpthread/thread/thr_stack.c
+++ b/lib/libpthread/thread/thr_stack.c
@@ -113,6 +113,19 @@ static LIST_HEAD(, stack) mstackq = LIST_HEAD_INITIALIZER(mstackq);
*/
static void *last_stack = NULL;
+/*
+ * Round size up to the nearest multiple of
+ * _thr_page_size.
+ */
+static inline size_t
+round_up(size_t size)
+{
+ if (size % _thr_page_size != 0)
+ size = ((size / _thr_page_size) + 1) *
+ _thr_page_size;
+ return size;
+}
+
int
_thr_stack_alloc(struct pthread_attr *attr)
{
@@ -122,9 +135,6 @@ _thr_stack_alloc(struct pthread_attr *attr)
size_t stacksize;
size_t guardsize;
- stacksize = attr->stacksize_attr;
- guardsize = attr->guardsize_attr;
-
/*
* Round up stack size to nearest multiple of _thr_page_size so
* that mmap() * will work. If the stack size is not an even
@@ -132,9 +142,9 @@ _thr_stack_alloc(struct pthread_attr *attr)
* unused space above the beginning of the stack, so the stack
* sits snugly against its guard.
*/
- if ((stacksize % _thr_page_size) != 0)
- stacksize = ((stacksize / _thr_page_size) + 1) *
- _thr_page_size;
+ stacksize = round_up(attr->stacksize_attr);
+ guardsize = round_up(attr->guardsize_attr);
+
attr->stackaddr_attr = NULL;
attr->flags &= ~THR_STACK_USER;
@@ -221,8 +231,8 @@ _thr_stack_free(struct pthread_attr *attr)
&& (attr->stackaddr_attr != NULL)) {
spare_stack = (attr->stackaddr_attr + attr->stacksize_attr
- sizeof(struct stack));
- spare_stack->stacksize = attr->stacksize_attr;
- spare_stack->guardsize = attr->guardsize_attr;
+ spare_stack->stacksize = round_up(attr->stacksize_attr);
+ spare_stack->guardsize = round_up(attr->guardsize_attr);
spare_stack->stackaddr = attr->stackaddr_attr;
if (spare_stack->stacksize == THR_STACK_DEFAULT &&
OpenPOWER on IntegriCloud