Allowing thread local storage for mainthread
Posted: Thu Mar 23, 2017 3:48 am
ChiBiOS threads support thread local storage between the Thread struct and the thread's stack (which typically grows down toward the Thread struct). These thread local variables are handy and worked great until I tried using it on mainthread.
Then, instant segfault panic, because the mainthread's Thread struct is located just before the system's VTimer list base!
Why can't the mainthread Thread struct be at the base of the thread's stack, as is the case with all other threads?
In chsys.c, delete the mainthread declaration and change:
to:
Are there ChiBiOS supported systems where this would not work?
Then, instant segfault panic, because the mainthread's Thread struct is located just before the system's VTimer list base!
Why can't the mainthread Thread struct be at the base of the thread's stack, as is the case with all other threads?
In chsys.c, delete the mainthread declaration and change:
Code: Select all
setcurrp(_thread_init(&mainthread, NORMALPRIO));
currp->p_stklimit = &__main_thread_stack_base__;
to:
Code: Select all
setcurrp(_thread_init((Thread *)&__main_thread_stack_base__, NORMALPRIO));
currp->p_stklimit =
&__main_thread_stack_base__ + sizeof(Thread)/sizeof(stkalign_t) + 1;
Are there ChiBiOS supported systems where this would not work?