arm: cortex-m: setup TLS pointer before switching to main
The TLS global pointer is only set during context switch. So for the first switch to main thread, the TLS pointer is NULL which would cause access violation when trying to access any thread local variables in main thread. Fix it by setting it before going into main thread. Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
parent
5274aa5dc2
commit
c661765f1d
1 changed files with 13 additions and 0 deletions
|
@ -509,6 +509,19 @@ void arch_switch_to_main_thread(struct k_thread *main_thread, char *stack_ptr,
|
|||
z_arm_prepare_switch_to_main();
|
||||
|
||||
_current = main_thread;
|
||||
|
||||
#if defined(CONFIG_THREAD_LOCAL_STORAGE) && defined(CONFIG_CPU_CORTEX_M)
|
||||
/* On Cortex-M, TLS uses a global variable as pointer to
|
||||
* the thread local storage area. So this needs to point
|
||||
* to the main thread's TLS area before switching to any
|
||||
* thread for the first time, as the pointer is only set
|
||||
* during context switching.
|
||||
*/
|
||||
extern uintptr_t z_arm_tls_ptr;
|
||||
|
||||
z_arm_tls_ptr = main_thread->tls;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_INSTRUMENT_THREAD_SWITCHING
|
||||
z_thread_mark_switched_in();
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue