Branch data Line data Source code
1 : : /* 2 : : * This file is part of the MicroPython project, http://micropython.org/ 3 : : * 4 : : * The MIT License (MIT) 5 : : * 6 : : * Copyright (c) 2014 Paul Sokolovsky 7 : : * Copryight (c) 2024 Angus Gratton 8 : : * 9 : : * Permission is hereby granted, free of charge, to any person obtaining a copy 10 : : * of this software and associated documentation files (the "Software"), to deal 11 : : * in the Software without restriction, including without limitation the rights 12 : : * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 : : * copies of the Software, and to permit persons to whom the Software is 14 : : * furnished to do so, subject to the following conditions: 15 : : * 16 : : * The above copyright notice and this permission notice shall be included in 17 : : * all copies or substantial portions of the Software. 18 : : * 19 : : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 : : * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 : : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 : : * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 : : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 : : * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 : : * THE SOFTWARE. 26 : : */ 27 : : 28 : : #include "py/runtime.h" 29 : : #include "py/cstack.h" 30 : : 31 : 3414 : void mp_cstack_init_with_sp_here(size_t stack_size) { 32 : : #if __GNUC__ >= 13 33 : : #pragma GCC diagnostic push 34 : : #pragma GCC diagnostic ignored "-Wdangling-pointer" 35 : : #endif 36 : 3414 : volatile int stack_dummy; 37 : 3414 : mp_cstack_init_with_top((void *)&stack_dummy, stack_size); 38 : : #if __GNUC__ >= 13 39 : : #pragma GCC diagnostic pop 40 : : #endif 41 : 3414 : } 42 : : 43 : 10795081 : mp_uint_t mp_cstack_usage(void) { 44 : : // Assumes descending stack 45 : 10795081 : volatile int stack_dummy; 46 : 10795081 : return MP_STATE_THREAD(stack_top) - (char *)&stack_dummy; 47 : : } 48 : : 49 : : #if MICROPY_STACK_CHECK 50 : : 51 : 10457019 : void mp_cstack_check(void) { 52 [ + + ]: 10457019 : if (mp_cstack_usage() >= MP_STATE_THREAD(stack_limit)) { 53 : 23 : mp_raise_recursion_depth(); 54 : : } 55 : 10702114 : } 56 : : 57 : : #endif // MICROPY_STACK_CHECK