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
This commit is contained in:
parent
e2b2087990
commit
3a38b0df30
@ -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;
|
||||
|
@ -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 &&
|
||||
|
@ -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;
|
||||
|
@ -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 &&
|
||||
|
Loading…
Reference in New Issue
Block a user