Skip to content

Commit

Permalink
(change_stack_perm): Handle stacks growing up. (allocate_stack): Like…
Browse files Browse the repository at this point in the history
…wise.
  • Loading branch information
Ulrich Drepper committed May 7, 2007
1 parent c7fd336 commit 63e82b9
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions nptl/allocatestack.c
Original file line number Diff line number Diff line change
@@ -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.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
Expand Down Expand Up @@ -288,9 +288,14 @@ change_stack_perm (struct pthread *pd
+ (((((pd->stackblock_size - pd->guardsize) / 2)
& pagemask) + pd->guardsize) & pagemask));
size_t len = pd->stackblock + pd->stackblock_size - stack;
#else
#elif _STACK_GROWS_DOWN
void *stack = pd->stackblock + 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
if (mprotect (stack, len, PROT_READ | PROT_WRITE | PROT_EXEC) != 0)
return errno;
Expand Down Expand Up @@ -570,8 +575,10 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
{
#ifdef NEED_SEPARATE_REGISTER_STACK
char *guard = mem + (((size - guardsize) / 2) & ~pagesize_m1);
#else
#elif _STACK_GROWS_DOWN
char *guard = mem;
# elif _STACK_GROWS_UP
char *guard = (char *) (((uintptr_t) pd - guardsize) & ~pagesize_m1);
#endif
if (mprotect (guard, guardsize, PROT_NONE) != 0)
{
Expand Down Expand Up @@ -618,10 +625,14 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
oldguard + pd->guardsize - guard - guardsize,
prot) != 0)
goto mprot_error;
#else
#elif _STACK_GROWS_DOWN
if (mprotect ((char *) mem + guardsize, pd->guardsize - guardsize,
prot) != 0)
goto mprot_error;
#elif _STACK_GROWS_UP
if (mprotect ((char *) pd - pd->guardsize,
pd->guardsize - guardsize, prot) != 0)
goto mprot_error;
#endif

pd->guardsize = guardsize;
Expand Down Expand Up @@ -661,8 +672,11 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
#ifdef NEED_SEPARATE_REGISTER_STACK
*stack = pd->stackblock;
*stacksize = stacktop - *stack;
#else
#elif _STACK_GROWS_DOWN
*stack = stacktop;
#elif _STACK_GROWS_UP
*stack = pd->stackblock;
assert (*stack > 0);
#endif

return 0;
Expand Down

0 comments on commit 63e82b9

Please sign in to comment.