Skip to content

Commit

Permalink
arm: userspace: fix initial user sp location
Browse files Browse the repository at this point in the history
The initial user stack pointer gets rounded to STACK_ALIGN_SIZE,
which can be much finer granularity than MPU regions. With
certain stack size values passed to k_thread_create(), the stack
pointer can be set past the defined region for the user thread's
stack, causing an immediate MPU fault.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
  • Loading branch information
Andrew Boie authored and andrewboie committed May 22, 2018
1 parent 9731a0c commit 99f36de
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions arch/arm/core/thread.c
Expand Up @@ -134,6 +134,12 @@ FUNC_NORETURN void _arch_user_mode_enter(k_thread_entry_t user_entry,
_current->arch.priv_stack_size =
(u32_t)CONFIG_PRIVILEGED_STACK_SIZE;

/* FIXME: Need a general API for aligning stacks so thet the initial
* user thread stack pointer doesn't overshoot the granularity of MPU
* regions, that works for ARM/NXP/QEMU.
*/
_current->stack_info.size &= ~0x1f;

_arm_userspace_enter(user_entry, p1, p2, p3,
(u32_t)_current->stack_info.start,
_current->stack_info.size);
Expand Down

0 comments on commit 99f36de

Please sign in to comment.