1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-29 11:41:21 +03:00

nptl: support thread stacks that grow up

Gentoo has been carrying this for all arches since 2.17.

URL: http://bugs.gentoo.org/301642
This commit is contained in:
Carlos O'Donell
2015-08-09 04:17:17 -04:00
committed by Mike Frysinger
parent 11fca9615f
commit d615a47355
4 changed files with 55 additions and 12 deletions

View File

@ -427,12 +427,25 @@ START_THREAD_DEFN
#ifdef _STACK_GROWS_DOWN
char *sp = CURRENT_STACK_FRAME;
size_t freesize = (sp - (char *) pd->stackblock) & ~pagesize_m1;
#else
# error "to do"
#endif
assert (freesize < pd->stackblock_size);
if (freesize > PTHREAD_STACK_MIN)
__madvise (pd->stackblock, freesize - PTHREAD_STACK_MIN, MADV_DONTNEED);
#else
/* Page aligned start of memory to free (higher than or equal
to current sp plus the minimum stack size). */
void *freeblock = (void*)((size_t)(CURRENT_STACK_FRAME
+ PTHREAD_STACK_MIN
+ pagesize_m1)
& ~pagesize_m1);
char *free_end = (char *) (((uintptr_t) pd - pd->guardsize) & ~pagesize_m1);
/* Is there any space to free? */
if (free_end > (char *)freeblock)
{
size_t freesize = (size_t)(free_end - (char *)freeblock);
assert (freesize < pd->stackblock_size);
__madvise (freeblock, freesize, MADV_DONTNEED);
}
#endif
/* If the thread is detached free the TCB. */
if (IS_DETACHED (pd))