Skip to content

Commit 0d5478a

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 3297342 + 53b1661 commit 0d5478a

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

shared-bindings/supervisor/Runtime.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,11 @@ MP_DEFINE_CONST_FUN_OBJ_1(supervisor_runtime_get_next_stack_limit_obj, superviso
197197
STATIC mp_obj_t supervisor_runtime_set_next_stack_limit(mp_obj_t self, mp_obj_t size_obj) {
198198
mp_int_t size = mp_obj_get_int(size_obj);
199199
mp_arg_validate_int_min(size, 256, MP_QSTR_size);
200-
set_next_stack_size(size);
200+
if (!set_next_stack_size(size)) {
201+
mp_raise_msg_varg(&mp_type_AttributeError,
202+
MP_ERROR_TEXT("can't set attribute '%q'"),
203+
MP_QSTR_next_stack_limit);
204+
}
201205
return mp_const_none;
202206
}
203207
MP_DEFINE_CONST_FUN_OBJ_2(supervisor_runtime_set_next_stack_limit_obj, supervisor_runtime_set_next_stack_limit);

supervisor/shared/stack.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
extern uint32_t _estack;
3636

3737
// Requested size.
38-
static uint32_t next_stack_size = CIRCUITPY_DEFAULT_STACK_SIZE;
38+
static uint32_t next_stack_size = 0;
3939
static uint32_t current_stack_size = 0;
4040
// Actual location and size, may be larger than requested.
4141
static uint32_t *stack_limit = NULL;
@@ -49,11 +49,15 @@ static void allocate_stack(void) {
4949
stack_limit = port_stack_get_limit();
5050
stack_length = (port_stack_get_top() - stack_limit) * sizeof(uint32_t);
5151
current_stack_size = stack_length;
52+
next_stack_size = stack_length;
5253
} else {
5354
mp_uint_t regs[10];
5455
mp_uint_t sp = cpu_get_regs_and_sp(regs);
5556

5657
mp_uint_t c_size = (mp_uint_t)port_stack_get_top() - sp;
58+
if (next_stack_size == 0) {
59+
next_stack_size = CIRCUITPY_DEFAULT_STACK_SIZE;
60+
}
5761
supervisor_allocation *stack_alloc = allocate_memory(c_size + next_stack_size + EXCEPTION_STACK_SIZE, true, false);
5862
if (stack_alloc == NULL) {
5963
stack_alloc = allocate_memory(c_size + CIRCUITPY_DEFAULT_STACK_SIZE + EXCEPTION_STACK_SIZE, true, false);
@@ -103,8 +107,12 @@ size_t stack_get_length(void) {
103107
return stack_length;
104108
}
105109

106-
void set_next_stack_size(uint32_t size) {
110+
bool set_next_stack_size(uint32_t size) {
111+
if (port_has_fixed_stack()) {
112+
return false;
113+
}
107114
next_stack_size = size;
115+
return true;
108116
}
109117

110118
uint32_t get_next_stack_size(void) {

supervisor/shared/stack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void stack_resize(void);
3737
uint32_t *stack_get_bottom(void);
3838
size_t stack_get_length(void);
3939
// Next/current requested stack size.
40-
void set_next_stack_size(uint32_t size);
40+
bool set_next_stack_size(uint32_t size);
4141
uint32_t get_next_stack_size(void);
4242
uint32_t get_current_stack_size(void);
4343
bool stack_ok(void);

supervisor/stub/stack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ void stack_init(void) {
3939
void stack_resize(void) {
4040
}
4141

42-
void set_next_stack_size(uint32_t size) {
42+
bool set_next_stack_size(uint32_t size) {
4343
(void)size;
44+
return true;
4445
}
4546

4647
uint32_t get_current_stack_size(void) {

0 commit comments

Comments
 (0)