aboutsummaryrefslogtreecommitdiffstats
path: root/os/ports/IAR/ARMCMx/chcore_v7m.h
diff options
context:
space:
mode:
Diffstat (limited to 'os/ports/IAR/ARMCMx/chcore_v7m.h')
-rw-r--r--os/ports/IAR/ARMCMx/chcore_v7m.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/os/ports/IAR/ARMCMx/chcore_v7m.h b/os/ports/IAR/ARMCMx/chcore_v7m.h
index ba0c83f5a..ad4abf25b 100644
--- a/os/ports/IAR/ARMCMx/chcore_v7m.h
+++ b/os/ports/IAR/ARMCMx/chcore_v7m.h
@@ -225,7 +225,15 @@ struct intctx {
* @param[in] ntp the thread to be switched in
* @param[in] otp the thread to be switched out
*/
+#if !defined(CH_DBG_ENABLE_STACK_CHECK) || defined(__DOXYGEN__)
#define port_switch(ntp, otp) _port_switch(ntp, otp)
+#else
+#define port_switch(ntp, otp) { \
+ if ((void *)(__get_SP() - sizeof(struct intctx)) < (void *)(otp + 1)) \
+ chDbgPanic("stack overflow"); \
+ _port_switch(ntp, otp); \
+}
+#endif
#ifdef __cplusplus
extern "C" {