Skip to content
Permalink
Browse files

arch: arm: mpu: program a wide MPU stack guard for FP capable threads

For threads that appear to be FP-capable (i.e. with K_FP_REGS
option flag set), we configure a wide MPU stack guard, if we
build with stack protection enabled (CONFIG_MPU_STACK_GUARD=y).

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
  • Loading branch information...
ioannisg authored and andrewboie committed May 28, 2019
1 parent 6a9b3f5 commit 360ad9e27708373e13a425152904908cf10691a2
Showing with 12 additions and 5 deletions.
  1. +12 −5 arch/arm/core/cortex_m/mpu/arm_core_mpu.c
@@ -212,6 +212,14 @@ void z_arch_configure_dynamic_mpu_regions(struct k_thread *thread)

/* Privileged stack guard */
u32_t guard_start;
u32_t guard_size = MPU_GUARD_ALIGN_AND_SIZE;

#if defined(CONFIG_FLOAT) && defined(CONFIG_FP_SHARING)
if ((thread->base.user_options & K_FP_REGS) != 0) {
guard_size = MPU_GUARD_ALIGN_AND_SIZE_FLOAT;
}
#endif

#if defined(CONFIG_USERSPACE)
if (thread->arch.priv_stack_start) {
guard_start = thread->arch.priv_stack_start -
@@ -220,23 +228,22 @@ void z_arch_configure_dynamic_mpu_regions(struct k_thread *thread)
"Guard start: (0x%x) below privilege stacks boundary: (0x%x)",
guard_start, (u32_t)&z_priv_stacks_ram_start);
} else {
guard_start = thread->stack_info.start -
MPU_GUARD_ALIGN_AND_SIZE;
guard_start = thread->stack_info.start - guard_size;

__ASSERT((u32_t)thread->stack_obj == guard_start,
"Guard start (0x%x) not beginning at stack object (0x%x)\n",
guard_start, (u32_t)thread->stack_obj);
}
#else
guard_start = thread->stack_info.start -
MPU_GUARD_ALIGN_AND_SIZE;
guard_start = thread->stack_info.start - guard_size;
#endif /* CONFIG_USERSPACE */

__ASSERT(region_num < _MAX_DYNAMIC_MPU_REGIONS_NUM,
"Out-of-bounds error for dynamic region map.");
guard = (const struct k_mem_partition)
{
guard_start,
MPU_GUARD_ALIGN_AND_SIZE,
guard_size,
K_MEM_PARTITION_P_RO_U_NA
};
dynamic_regions[region_num] = &guard;

0 comments on commit 360ad9e

Please sign in to comment.
You can’t perform that action at this time.