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]

thread_self() and STACK_GROWS_UP


Hi,

Is thread_self() correct for the case where STACK_GROWS_UP is defined?
It does not work correctly for me.

static inline pthread_descr thread_self (void)
{
#ifdef THREAD_SELF
 return THREAD_SELF;
#else
 char *sp = CURRENT_STACK_FRAME;
 if (sp >= __pthread_initial_thread_bos)
   return &__pthread_initial_thread;
 else if (sp >= __pthread_manager_thread_bos
          && sp < __pthread_manager_thread_tos)
   return &__pthread_manager_thread;
 else if (__pthread_nonstandard_stacks)
   return __pthread_find_self();
 else
#ifdef _STACK_GROWS_DOWN
   return (pthread_descr)(((unsigned long)sp | (STACK_SIZE-1))+1) - 1;
#else
   return (pthread_descr)((unsigned long)sp &~ (STACK_SIZE-1));
#endif
#endif
}

On our processor the address space looks like:

0x40000000 - top of user space
0x3f800000 - bottom of stack
- code, heap etc.
0x10000000 - bottom of userspace (approx.)

As such __pthread_initial_thread_bos has the lowest address of our
stacks so all stacks other than the malloced manager thread stack are
greater than __pthread_initial_thread_bos. Because of this
thread_self() will always return &__pthread_initial_thread or
&__pthread_manager_thread, which is obviously not correct.

The attached patch seems to work better for me but may not be correct.
Are there any ports other than hppa that have such an, er, interesting
stack?

Thanks,

Attachment: linuxthreads-descr-h.patch
Description: Binary data


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