arch: arm: cortex-m: fix placement of ARMv7-M-related MPU workaround
The workaround for ARMv7-M architecture (which proactively decreases the available thread stack by the size of the MPU guard) needs to be placed before we calculate the pointer of the user-space local thread data, otherwise this pointer will fall beyond the boundary of the thread stack area. Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
This commit is contained in:
parent
84e54ee92e
commit
9d8111c88f
1 changed files with 10 additions and 10 deletions
|
@ -38,6 +38,16 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
|
|||
/* Offset between the top of stack and the high end of stack area. */
|
||||
u32_t top_of_stack_offset = 0U;
|
||||
|
||||
#if defined(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT) \
|
||||
&& defined(CONFIG_USERSPACE)
|
||||
/* This is required to work-around the case where the thread
|
||||
* is created without using K_THREAD_STACK_SIZEOF() macro in
|
||||
* k_thread_create(). If K_THREAD_STACK_SIZEOF() is used, the
|
||||
* Guard size has already been take out of stackSize.
|
||||
*/
|
||||
stackSize -= MPU_GUARD_ALIGN_AND_SIZE;
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_USERSPACE)
|
||||
/* Truncate the stack size to align with the MPU region granularity.
|
||||
* This is done proactively to account for the case when the thread
|
||||
|
@ -61,16 +71,6 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
|
|||
#endif /* CONFIG_THREAD_USERSPACE_LOCAL_DATA */
|
||||
#endif /* CONFIG_USERSPACE */
|
||||
|
||||
#if defined(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT) \
|
||||
&& defined(CONFIG_USERSPACE)
|
||||
/* This is required to work-around the case where the thread
|
||||
* is created without using K_THREAD_STACK_SIZEOF() macro in
|
||||
* k_thread_create(). If K_THREAD_STACK_SIZEOF() is used, the
|
||||
* Guard size has already been take out of stackSize.
|
||||
*/
|
||||
stackSize -= MPU_GUARD_ALIGN_AND_SIZE;
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_FPU) && defined(CONFIG_FPU_SHARING) \
|
||||
&& defined(CONFIG_MPU_STACK_GUARD)
|
||||
/* For a thread which intends to use the FP services, it is required to
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue