diff --git a/core/include/sched.h b/core/include/sched.h index db9fad5463..23cfc56d75 100644 --- a/core/include/sched.h +++ b/core/include/sched.h @@ -119,6 +119,15 @@ extern "C" { */ #define PRIkernel_pid PRIi16 +#if defined(DEVELHELP) || defined(DOXYGEN) +/** + * Enables detection of stack overflows and measures stack usage when != 0 + */ +#ifndef SCHED_TEST_STACK +#define SCHED_TEST_STACK 1 +#endif /* SCHED_TEST_STACK */ +#endif /* DEVELHELP */ + /** * Unique process identifier */ diff --git a/core/include/thread.h b/core/include/thread.h index 1636953817..a2872256b9 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -193,7 +193,7 @@ struct _thread { msg_t *msg_array; /**< memory holding messages sent to this thread's message queue */ #endif -#if defined(DEVELHELP) || defined(SCHED_TEST_STACK) \ +#if defined(DEVELHELP) || IS_ACTIVE(SCHED_TEST_STACK) \ || defined(MODULE_MPU_STACK_GUARD) || defined(DOXYGEN) char *stack_start; /**< thread's stack start address */ #endif @@ -545,7 +545,7 @@ const char *thread_state_to_string(thread_status_t state); */ static inline void *thread_get_stackstart(const thread_t *thread) { -#if defined(DEVELHELP) || defined(SCHED_TEST_STACK) \ +#if defined(DEVELHELP) || IS_ACTIVE(SCHED_TEST_STACK) \ || defined(MODULE_MPU_STACK_GUARD) return thread->stack_start; #else diff --git a/core/sched.c b/core/sched.c index b6eb15c28f..0afbdea0b7 100644 --- a/core/sched.c +++ b/core/sched.c @@ -119,7 +119,7 @@ static void _unschedule(thread_t *active_thread) active_thread->status = STATUS_PENDING; } -#ifdef SCHED_TEST_STACK +#if IS_ACTIVE(SCHED_TEST_STACK) if (*((uintptr_t *)active_thread->stack_start) != (uintptr_t)active_thread->stack_start) { LOG_WARNING( diff --git a/core/thread.c b/core/thread.c index 4c56608ca3..fa2e49130b 100644 --- a/core/thread.c +++ b/core/thread.c @@ -233,7 +233,7 @@ kernel_pid_t thread_create(char *stack, int stacksize, uint8_t priority, _init_tls(thread->tls); #endif -#if defined(DEVELHELP) || defined(SCHED_TEST_STACK) +#if defined(DEVELHELP) || IS_ACTIVE(SCHED_TEST_STACK) if (flags & THREAD_CREATE_STACKTEST) { /* assign each int of the stack the value of it's address. Alignment * has been handled above, so silence -Wcast-align */ @@ -274,7 +274,7 @@ kernel_pid_t thread_create(char *stack, int stacksize, uint8_t priority, thread->pid = pid; thread->sp = thread_stack_init(function, arg, stack, stacksize); -#if defined(DEVELHELP) || defined(SCHED_TEST_STACK) || \ +#if defined(DEVELHELP) || IS_ACTIVE(SCHED_TEST_STACK) || \ defined(MODULE_MPU_STACK_GUARD) thread->stack_start = stack; #endif diff --git a/cpu/esp_common/thread_arch.c b/cpu/esp_common/thread_arch.c index f6aded6725..de04cdc247 100644 --- a/cpu/esp_common/thread_arch.c +++ b/cpu/esp_common/thread_arch.c @@ -150,7 +150,7 @@ char* thread_stack_init(thread_task_func_t task_func, void *arg, void *stack_sta sp = (uint8_t*)(((uintptr_t)(top_of_stack + 1) - XT_STK_FRMSZ - XT_CP_SIZE) & ~0xf); /* Clear whole stack with a known value to assist debugging */ - #if !defined(DEVELHELP) && !defined(SCHED_TEST_STACK) + #if !defined(DEVELHELP) && !IS_ACTIVE(SCHED_TEST_STACK) /* Unfortunately, this affects thread_measure_stack_free function */ memset(stack_start, 0, stack_size); #else diff --git a/tests/bench_sizeof_coretypes/main.c b/tests/bench_sizeof_coretypes/main.c index 099f735ac0..37221a1185 100644 --- a/tests/bench_sizeof_coretypes/main.c +++ b/tests/bench_sizeof_coretypes/main.c @@ -101,7 +101,7 @@ int main(void) P(msg_queue); P(msg_array); #endif -#if defined(DEVELHELP) || defined(SCHED_TEST_STACK) || defined(MODULE_MPU_STACK_GUARD) +#if defined(DEVELHELP) || IS_ACTIVE(SCHED_TEST_STACK) || defined(MODULE_MPU_STACK_GUARD) P(stack_start); #endif #ifdef DEVELHELP