forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathstack.c
36 lines (31 loc) · 888 Bytes
/
stack.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
//
// SPDX-License-Identifier: MIT
#include "stack.h"
#include "py/mpconfig.h"
#include "py/runtime.h"
#include "supervisor/cpu.h"
#include "supervisor/port.h"
#include "supervisor/shared/safe_mode.h"
void stack_init(void) {
// Zephyr has a stack canary of its own.
#ifndef __ZEPHYR__
uint32_t *stack_limit = port_stack_get_limit();
*stack_limit = STACK_CANARY_VALUE;
#endif
}
inline bool stack_ok(void) {
#ifndef __ZEPHYR__
uint32_t *stack_limit = port_stack_get_limit();
return *stack_limit == STACK_CANARY_VALUE;
#endif
}
inline void assert_heap_ok(void) {
#ifndef __ZEPHYR__
if (!stack_ok()) {
reset_into_safe_mode(SAFE_MODE_STACK_OVERFLOW);
}
#endif
}