@@ -133,17 +133,19 @@ static void reset_devices(void) {
133
133
}
134
134
135
135
#if MICROPY_ENABLE_PYSTACK
136
- STATIC supervisor_allocation * allocate_pystack (void ) {
136
+ STATIC supervisor_allocation * allocate_pystack (safe_mode_t safe_mode ) {
137
137
mp_int_t pystack_size = CIRCUITPY_PYSTACK_SIZE ;
138
138
#if CIRCUITPY_OS_GETENV && CIRCUITPY_SETTABLE_PYSTACK
139
139
// Fetch value if exists from settings.toml
140
140
// Leaves size to build default on any failure
141
- (void )common_hal_os_getenv_int ("CIRCUITPY_PYSTACK_SIZE" , & pystack_size );
142
- // Check if value is valid
143
- pystack_size = pystack_size - pystack_size % sizeof (size_t ); // Round down to multiple of 4.
144
- if (pystack_size < 384 ) {
145
- serial_write_compressed (translate ("\nInvalid CIRCUITPY_PYSTACK_SIZE\n\n\r" ));
146
- pystack_size = CIRCUITPY_PYSTACK_SIZE ; // Reset
141
+ if (safe_mode == SAFE_MODE_NONE || safe_mode == SAFE_MODE_USER ) {
142
+ (void )common_hal_os_getenv_int ("CIRCUITPY_PYSTACK_SIZE" , & pystack_size );
143
+ // Check if value is valid
144
+ pystack_size = pystack_size - pystack_size % sizeof (size_t ); // Round down to multiple of 4.
145
+ if (pystack_size < 384 ) {
146
+ serial_write_compressed (translate ("\nInvalid CIRCUITPY_PYSTACK_SIZE\n\n\r" ));
147
+ pystack_size = CIRCUITPY_PYSTACK_SIZE ; // Reset
148
+ }
147
149
}
148
150
#endif
149
151
supervisor_allocation * pystack = allocate_memory (pystack_size , false, false);
@@ -427,7 +429,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) {
427
429
428
430
supervisor_allocation * pystack = NULL ;
429
431
#if MICROPY_ENABLE_PYSTACK
430
- pystack = allocate_pystack ();
432
+ pystack = allocate_pystack (safe_mode );
431
433
#endif
432
434
supervisor_allocation * heap = allocate_remaining_memory ();
433
435
start_mp (heap , pystack );
@@ -769,7 +771,7 @@ STATIC void __attribute__ ((noinline)) run_safemode_py(safe_mode_t safe_mode) {
769
771
770
772
supervisor_allocation * pystack = NULL ;
771
773
#if MICROPY_ENABLE_PYSTACK
772
- pystack = allocate_pystack ();
774
+ pystack = allocate_pystack (safe_mode );
773
775
#endif
774
776
supervisor_allocation * heap = allocate_remaining_memory ();
775
777
start_mp (heap , pystack );
@@ -806,7 +808,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
806
808
807
809
supervisor_allocation * pystack = NULL ;
808
810
#if MICROPY_ENABLE_PYSTACK
809
- pystack = allocate_pystack ();
811
+ pystack = allocate_pystack (safe_mode );
810
812
#endif
811
813
supervisor_allocation * heap = allocate_remaining_memory ();
812
814
start_mp (heap , pystack );
@@ -906,13 +908,13 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
906
908
#endif
907
909
}
908
910
909
- STATIC int run_repl (void ) {
911
+ STATIC int run_repl (safe_mode_t safe_mode ) {
910
912
int exit_code = PYEXEC_FORCED_EXIT ;
911
913
stack_resize ();
912
914
filesystem_flush ();
913
915
supervisor_allocation * pystack = NULL ;
914
916
#if MICROPY_ENABLE_PYSTACK
915
- pystack = allocate_pystack ();
917
+ pystack = allocate_pystack (safe_mode );
916
918
#endif
917
919
supervisor_allocation * heap = allocate_remaining_memory ();
918
920
start_mp (heap , pystack );
@@ -1078,7 +1080,7 @@ int __attribute__((used)) main(void) {
1078
1080
bool simulate_reset = true;
1079
1081
for (;;) {
1080
1082
if (!skip_repl ) {
1081
- exit_code = run_repl ();
1083
+ exit_code = run_repl (get_safe_mode () );
1082
1084
supervisor_set_run_reason (RUN_REASON_REPL_RELOAD );
1083
1085
}
1084
1086
if (exit_code == PYEXEC_FORCED_EXIT ) {
0 commit comments