Browse Source

core: save the stack_start in the thread context for mpu_stack_guard

pr/spi.typo
Ian Martin 6 years ago
parent
commit
28a7ddc9a8
  1. 2
      core/include/thread.h
  2. 14
      core/sched.c
  3. 2
      core/thread.c
  4. 2
      tests/sizeof_tcb/main.c

2
core/include/thread.h

@ -189,7 +189,7 @@ struct _thread {
msg_t *msg_array; /**< memory holding messages */
#endif
#if defined DEVELHELP || defined(SCHED_TEST_STACK)
#if defined(DEVELHELP) || defined(SCHED_TEST_STACK) || defined(MODULE_MPU_STACK_GUARD)
char *stack_start; /**< thread's stack start address */
#endif
#ifdef DEVELHELP

14
core/sched.c

@ -29,6 +29,10 @@
#include "irq.h"
#include "log.h"
#ifdef MODULE_MPU_STACK_GUARD
#include "mpu.h"
#endif
#ifdef MODULE_SCHEDSTATISTICS
#include "xtimer.h"
#endif
@ -115,6 +119,16 @@ int __attribute__((used)) sched_run(void)
sched_active_pid = next_thread->pid;
sched_active_thread = (volatile thread_t *) next_thread;
#ifdef MODULE_MPU_STACK_GUARD
mpu_configure(
1, /* MPU region 1 */
(uintptr_t)sched_active_thread->stack_start + 31, /* Base Address (rounded up) */
MPU_ATTR(1, AP_RO_RO, 0, 1, 0, 1, MPU_SIZE_32B) /* Attributes and Size */
);
mpu_enable();
#endif
DEBUG("sched_run: done, changed sched_active_thread.\n");
return 1;

2
core/thread.c

@ -211,7 +211,7 @@ kernel_pid_t thread_create(char *stack, int stacksize, char priority, int flags,
cb->pid = pid;
cb->sp = thread_stack_init(function, arg, stack, stacksize);
#if defined(DEVELHELP) || defined(SCHED_TEST_STACK)
#if defined(DEVELHELP) || defined(SCHED_TEST_STACK) || defined(MODULE_MPU_STACK_GUARD)
cb->stack_start = stack;
#endif

2
tests/sizeof_tcb/main.c

@ -48,7 +48,7 @@ int main(void)
#ifdef DEVELHELP
P(name);
#endif
#if defined(DEVELHELP) || defined(SCHED_TEST_STACK)
#if defined(DEVELHELP) || defined(SCHED_TEST_STACK) || defined(MODULE_MPU_STACK_GUARD)
P(stack_start);
#endif

Loading…
Cancel
Save