forked from adafruit/circuitpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
29 lines (24 loc) · 741 Bytes
/
Copy pathstack.c
File metadata and controls
29 lines (24 loc) · 741 Bytes
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
// 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) {
uint32_t *stack_limit = port_stack_get_limit();
*stack_limit = STACK_CANARY_VALUE;
}
inline bool stack_ok(void) {
uint32_t *stack_limit = port_stack_get_limit();
return *stack_limit == STACK_CANARY_VALUE;
}
inline void assert_heap_ok(void) {
if (!stack_ok()) {
reset_into_safe_mode(SAFE_MODE_STACK_OVERFLOW);
}
}