circuitpython/supervisor/shared/stack.c
Scott Shawcroft 7f0cc9e7b4
Add Zephyr port
This port is meant to grow to encompass all existing boards. For
now, it is a port while we transition over.

It is named `zephyr-cp` to differentiate it from the MicroPython
`zephyr` port. They are separate implementations.
2025-02-04 11:24:13 -08:00

36 lines
888 B
C

// 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
}