Commit a6fa85d8 authored by Angus Gratton's avatar Angus Gratton Committed by Damien George

unix: Switch stack limit check to new cstack API.

Necessary to pass CI when testing the V2 preview APIs.

Also adds an extra coverage test for the legacy stackctrl API, to maintain
coverage and check for any regression.

This work was funded through GitHub Sponsors.
Signed-off-by: default avatarAngus Gratton <angus@redyak.com.au>
parent fbc19596
......@@ -7,6 +7,7 @@
#include "py/objint.h"
#include "py/objstr.h"
#include "py/runtime.h"
#include "py/stackctrl.h"
#include "py/gc.h"
#include "py/repl.h"
#include "py/mpz.h"
......@@ -739,6 +740,32 @@ static mp_obj_t extra_coverage(void) {
mp_printf(&mp_plat_print, "%d %d\n", mp_obj_is_int(MP_OBJ_NEW_SMALL_INT(1)), mp_obj_is_int(mp_obj_new_int_from_ll(1)));
}
// Legacy stackctrl.h API, this has been replaced by cstack.h
{
mp_printf(&mp_plat_print, "# stackctrl\n");
char *old_stack_top = MP_STATE_THREAD(stack_top);
size_t old_stack_limit = 0;
size_t new_stack_limit = SIZE_MAX;
#if MICROPY_STACK_CHECK
old_stack_limit = MP_STATE_THREAD(stack_limit);
MP_STACK_CHECK();
#endif
mp_stack_ctrl_init(); // Will set stack top incorrectly
mp_stack_set_top(old_stack_top); // ... and restore it
#if MICROPY_STACK_CHECK
mp_stack_set_limit(MP_STATE_THREAD(stack_limit));
MP_STACK_CHECK();
new_stack_limit = MP_STATE_THREAD(stack_limit);
#endif
// Nothing should have changed
mp_printf(&mp_plat_print, "%d %d\n",
old_stack_top == MP_STATE_THREAD(stack_top),
MICROPY_STACK_CHECK == 0 || old_stack_limit == new_stack_limit);
}
mp_printf(&mp_plat_print, "# end coverage.c\n");
mp_obj_streamtest_t *s = mp_obj_malloc(mp_obj_streamtest_t, &mp_type_stest_fileio);
......
......@@ -44,7 +44,7 @@
#include "py/repl.h"
#include "py/gc.h"
#include "py/objstr.h"
#include "py/stackctrl.h"
#include "py/cstack.h"
#include "py/mphal.h"
#include "py/mpthread.h"
#include "extmod/misc.h"
......@@ -468,12 +468,20 @@ int main(int argc, char **argv) {
#if MICROPY_PY_THREAD
mp_thread_init();
#endif
// Define a reasonable stack limit to detect stack overflow.
mp_uint_t stack_size = 40000 * (sizeof(void *) / 4);
#if defined(__arm__) && !defined(__thumb2__)
// ARM (non-Thumb) architectures require more stack.
stack_size *= 2;
#endif
// We should capture stack top ASAP after start, and it should be
// captured guaranteedly before any other stack variables are allocated.
// For this, actual main (renamed main_) should not be inlined into
// this function. main_() itself may have other functions inlined (with
// their own stack variables), that's why we need this main/main_ split.
mp_stack_ctrl_init();
mp_cstack_init_with_sp_here(stack_size);
return main_(argc, argv);
}
......@@ -492,14 +500,6 @@ MP_NOINLINE int main_(int argc, char **argv) {
signal(SIGPIPE, SIG_IGN);
#endif
// Define a reasonable stack limit to detect stack overflow.
mp_uint_t stack_limit = 40000 * (sizeof(void *) / 4);
#if defined(__arm__) && !defined(__thumb2__)
// ARM (non-Thumb) architectures require more stack.
stack_limit *= 2;
#endif
mp_stack_set_limit(stack_limit);
pre_process_options(argc, argv);
#if MICROPY_ENABLE_GC
......
......@@ -164,6 +164,8 @@ pop all: 1 2 4 5
1 1
0 0
1 1
# stackctrl
1 1
# end coverage.c
0123456789 b'0123456789'
7300
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment