mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-29 11:41:21 +03:00
(change_stack_perm): Handle stacks growing up. (allocate_stack): Likewise.
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
|
/* Copyright (C) 2002,2003,2004,2005,2006,2007 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
|
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
|
||||||
|
|
||||||
@ -288,9 +288,14 @@ change_stack_perm (struct pthread *pd
|
|||||||
+ (((((pd->stackblock_size - pd->guardsize) / 2)
|
+ (((((pd->stackblock_size - pd->guardsize) / 2)
|
||||||
& pagemask) + pd->guardsize) & pagemask));
|
& pagemask) + pd->guardsize) & pagemask));
|
||||||
size_t len = pd->stackblock + pd->stackblock_size - stack;
|
size_t len = pd->stackblock + pd->stackblock_size - stack;
|
||||||
#else
|
#elif _STACK_GROWS_DOWN
|
||||||
void *stack = pd->stackblock + pd->guardsize;
|
void *stack = pd->stackblock + pd->guardsize;
|
||||||
size_t len = pd->stackblock_size - pd->guardsize;
|
size_t len = pd->stackblock_size - pd->guardsize;
|
||||||
|
#elif _STACK_GROWS_UP
|
||||||
|
void *stack = pd->stackblock;
|
||||||
|
size_t len = (uintptr_t) pd - pd->guardsize - (uintptr_t) pd->stackblock;
|
||||||
|
#else
|
||||||
|
# error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
|
||||||
#endif
|
#endif
|
||||||
if (mprotect (stack, len, PROT_READ | PROT_WRITE | PROT_EXEC) != 0)
|
if (mprotect (stack, len, PROT_READ | PROT_WRITE | PROT_EXEC) != 0)
|
||||||
return errno;
|
return errno;
|
||||||
@ -570,8 +575,10 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
|
|||||||
{
|
{
|
||||||
#ifdef NEED_SEPARATE_REGISTER_STACK
|
#ifdef NEED_SEPARATE_REGISTER_STACK
|
||||||
char *guard = mem + (((size - guardsize) / 2) & ~pagesize_m1);
|
char *guard = mem + (((size - guardsize) / 2) & ~pagesize_m1);
|
||||||
#else
|
#elif _STACK_GROWS_DOWN
|
||||||
char *guard = mem;
|
char *guard = mem;
|
||||||
|
# elif _STACK_GROWS_UP
|
||||||
|
char *guard = (char *) (((uintptr_t) pd - guardsize) & ~pagesize_m1);
|
||||||
#endif
|
#endif
|
||||||
if (mprotect (guard, guardsize, PROT_NONE) != 0)
|
if (mprotect (guard, guardsize, PROT_NONE) != 0)
|
||||||
{
|
{
|
||||||
@ -618,10 +625,14 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
|
|||||||
oldguard + pd->guardsize - guard - guardsize,
|
oldguard + pd->guardsize - guard - guardsize,
|
||||||
prot) != 0)
|
prot) != 0)
|
||||||
goto mprot_error;
|
goto mprot_error;
|
||||||
#else
|
#elif _STACK_GROWS_DOWN
|
||||||
if (mprotect ((char *) mem + guardsize, pd->guardsize - guardsize,
|
if (mprotect ((char *) mem + guardsize, pd->guardsize - guardsize,
|
||||||
prot) != 0)
|
prot) != 0)
|
||||||
goto mprot_error;
|
goto mprot_error;
|
||||||
|
#elif _STACK_GROWS_UP
|
||||||
|
if (mprotect ((char *) pd - pd->guardsize,
|
||||||
|
pd->guardsize - guardsize, prot) != 0)
|
||||||
|
goto mprot_error;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pd->guardsize = guardsize;
|
pd->guardsize = guardsize;
|
||||||
@ -661,8 +672,11 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
|
|||||||
#ifdef NEED_SEPARATE_REGISTER_STACK
|
#ifdef NEED_SEPARATE_REGISTER_STACK
|
||||||
*stack = pd->stackblock;
|
*stack = pd->stackblock;
|
||||||
*stacksize = stacktop - *stack;
|
*stacksize = stacktop - *stack;
|
||||||
#else
|
#elif _STACK_GROWS_DOWN
|
||||||
*stack = stacktop;
|
*stack = stacktop;
|
||||||
|
#elif _STACK_GROWS_UP
|
||||||
|
*stack = pd->stackblock;
|
||||||
|
assert (*stack > 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user