summaryrefslogtreecommitdiff
path: root/supervisor/shared/stack.c
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2018-12-07 15:34:43 -0500
committerGitHub <noreply@github.com>2018-12-07 15:34:43 -0500
commit2fbaceb2b15ff7d2c368a6cf4dfc10881f5979e7 (patch)
tree60210206b73c579e74288333a3ecc4e8f233dd1b /supervisor/shared/stack.c
parent481c4954afd161448aa37d353fa577d409d880c6 (diff)
parent89ef6eef575501e736ae528f13d9979e1302be63 (diff)
Merge pull request #1294 from tannewt/stack_check4.0.0-alpha.4
Add stack validity check and raise an error when it happens.
Diffstat (limited to 'supervisor/shared/stack.c')
-rwxr-xr-xsupervisor/shared/stack.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/supervisor/shared/stack.c b/supervisor/shared/stack.c
index 6b74742eb..71e239c0a 100755
--- a/supervisor/shared/stack.c
+++ b/supervisor/shared/stack.c
@@ -27,7 +27,9 @@
#include "stack.h"
#include "py/mpconfig.h"
+#include "py/runtime.h"
#include "supervisor/cpu.h"
+#include "supervisor/shared/safe_mode.h"
extern uint32_t _estack;
@@ -50,6 +52,17 @@ void allocate_stack(void) {
} else {
current_stack_size = next_stack_size;
}
+ *stack_alloc->ptr = STACK_CANARY_VALUE;
+}
+
+inline bool stack_ok(void) {
+ return *stack_alloc->ptr == STACK_CANARY_VALUE;
+}
+
+inline void assert_heap_ok(void) {
+ if (!stack_ok()) {
+ reset_into_safe_mode(HEAP_OVERWRITTEN);
+ }
}
void stack_init(void) {
@@ -58,6 +71,7 @@ void stack_init(void) {
void stack_resize(void) {
if (next_stack_size == current_stack_size) {
+ *stack_alloc->ptr = STACK_CANARY_VALUE;
return;
}
free_memory(stack_alloc);