Skip to content
Snippets Groups Projects
Commit 28a7ddc9 authored by Ian Martin's avatar Ian Martin
Browse files

core: save the stack_start in the thread context for mpu_stack_guard

parent b7bd6b34
No related branches found
No related tags found
No related merge requests found
...@@ -189,7 +189,7 @@ struct _thread { ...@@ -189,7 +189,7 @@ struct _thread {
msg_t *msg_array; /**< memory holding messages */ msg_t *msg_array; /**< memory holding messages */
#endif #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 */ char *stack_start; /**< thread's stack start address */
#endif #endif
#ifdef DEVELHELP #ifdef DEVELHELP
......
...@@ -29,6 +29,10 @@ ...@@ -29,6 +29,10 @@
#include "irq.h" #include "irq.h"
#include "log.h" #include "log.h"
#ifdef MODULE_MPU_STACK_GUARD
#include "mpu.h"
#endif
#ifdef MODULE_SCHEDSTATISTICS #ifdef MODULE_SCHEDSTATISTICS
#include "xtimer.h" #include "xtimer.h"
#endif #endif
...@@ -115,6 +119,16 @@ int __attribute__((used)) sched_run(void) ...@@ -115,6 +119,16 @@ int __attribute__((used)) sched_run(void)
sched_active_pid = next_thread->pid; sched_active_pid = next_thread->pid;
sched_active_thread = (volatile thread_t *) next_thread; 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"); DEBUG("sched_run: done, changed sched_active_thread.\n");
return 1; return 1;
......
...@@ -211,7 +211,7 @@ kernel_pid_t thread_create(char *stack, int stacksize, char priority, int flags, ...@@ -211,7 +211,7 @@ kernel_pid_t thread_create(char *stack, int stacksize, char priority, int flags,
cb->pid = pid; cb->pid = pid;
cb->sp = thread_stack_init(function, arg, stack, stacksize); 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; cb->stack_start = stack;
#endif #endif
......
...@@ -48,7 +48,7 @@ int main(void) ...@@ -48,7 +48,7 @@ int main(void)
#ifdef DEVELHELP #ifdef DEVELHELP
P(name); P(name);
#endif #endif
#if defined(DEVELHELP) || defined(SCHED_TEST_STACK) #if defined(DEVELHELP) || defined(SCHED_TEST_STACK) || defined(MODULE_MPU_STACK_GUARD)
P(stack_start); P(stack_start);
#endif #endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment