This is the mail archive of the libc-ports@sources.redhat.com mailing list for the libc-ports project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: thread_self() and STACK_GROWS_UP


On Thu, Jun 08, 2006 at 10:12:54AM +0100, Will Newton wrote:
> The setup is done in pthread.c:
> 
>  __pthread_initial_thread_bos = (char *)
>    ((long)CURRENT_STACK_FRAME &~ (STACK_SIZE - 1));
> 
> If any stacks were put below that we would get a segfault, as the
> stack vma grows up (notionally) not down! So the code is doing the
> right thing w.r.t to STACK_GROWS_UP.

Hmm.  That finds the lowest memory address of the current stack,
roughly. So the initial stack is from __pthread_initial_thread_bos on
up.  Then THREAD_STACK_START_ADDRESS gets defined to that same place.
Then thread_segment puts stacks at:

  return (pthread_descr)(THREAD_STACK_START_ADDRESS + (seg - 1) * STACK_SIZE)
         + 1;

Not sure why I didn't see that before.

Anyway, It Seems To Me that by defining THREAD_STACK_START_ADDRESS
to point elsewhere, some address lower than the initial stack,
everything will just work.

But it also seems that you're right about the default thread_self being
wrong for the default case when stack grows up.

So, want to try THREAD_STACK_START_ADDRESS, which will uncramp your
thread sizes a little, or want me to change the default?

-- 
Daniel Jacobowitz
CodeSourcery


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]