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: setting of initial bottom of stack variable in pthread.c (again)


On Mon, Aug 21, 2006 at 01:27:10PM -0700, Jay wrote:
> > The initial thread stack size _in the current code_
> > is treated as
> > alignment + 2*STACK_SIZE.  I think if the 2* were
> > missing, things
> > would still be OK; then it would be padding +
> > STACK_SIZE.  The 2
> > has been there for a long long time.
> 
> I am not understanding why it is 2*STACKSIZE.  Has
> that memory actually been allocated to the initial
> thread (I keep thinking it's really outside of the
> initial thread's space)?

What I'm trying to say is that if you read the code that's there today,
it tries to preserve alignment + 2 * STACK_SIZE for the main thread. 
If you assume that there's only supposed to be alignment + STACK_SIZE,
then the 2* is simply wrong.

I would guess someone got confused when writing it, and thought the &
rounded down rather than up here.  Or it could have been involved with
separate register stacks.  But really, I have no idea; it was too long
ago.

> You were right before in thinking that the stack limit
> had been changed.  It was right under my nose in
> pthread.c.  It changes the stack limit to STACK_SIZE. 
> The trace is attached.

Oho!  OK, now we know what's going on.

We always adjust the rlimit down in the !FLOATING_STACKS case (the
#if's make this a little hard to see).  So it's not shocking that
large mallocs get "in that stack".

But it still shouldn't break.  It looks like you're letting the
thread library allocate stacks, and it is deliberately trying
to allocate one there:

[pid  2189] old_mmap(0xbfa00000, 2097152, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xbfa00000

But why is it doing that?  thread_segment should pick
THREAD_STACK_START_ADDRESS, which should be determined by
__pthread_initial_thread_bos.  Then here's the code which
does the mmap:

      new_thread = default_new_thread;
      new_thread_bottom = (char *) (new_thread + 1) - stacksize;
      map_addr = new_thread_bottom - guardsize;
      res_addr = mmap(map_addr, stacksize + guardsize,
                      PROT_READ | PROT_WRITE | PROT_EXEC,
                      MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);

And that's supposed to map the thread at __pthread_initial_thread_bos
minus STACK_SIZE.  Which is apparently not happening for you.  So
what does it think it's mapping?

-- 
Daniel Jacobowitz
CodeSourcery


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