8000 Merge pull request #3668 from jepler/esp32s2-stack-size · jepler/circuitpython@75a977f · GitHub
[go: up one dir, main page]

Skip to content

Commit 75a977f

Browse files
authored
Merge pull request adafruit#3668 from jepler/esp32s2-stack-size
esp32s2: Correct port_stack_get_top()
2 parents fd43c0a + 2d8ebfc commit 75a977f

File tree

1 file changed

+12
-1
lines changed
  • ports/esp32s2/supervisor

1 file changed

+12
-1
lines changed

ports/esp32s2/supervisor/port.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,18 @@ uint32_t *port_stack_get_limit(void) {
148148
}
149149

150150
uint32_t *port_stack_get_top(void) {
151-
return port_stack_get_limit() + CONFIG_ESP_MAIN_TASK_STACK_SIZE / (sizeof(uint32_t) / sizeof(StackType_t));
151+
// The sizeof-arithmetic is so that the pointer arithmetic is done on units
152+
// of uint32_t instead of units of StackType_t. StackType_t is an alias
153+
// for a byte sized type.
154+
//
155+
// The main stack is bigger than CONFIG_ESP_MAIN_TASK_STACK_SIZE -- an
156+
// "extra" size is added to it (TASK_EXTRA_STACK_SIZE). This total size is
157+
// available as ESP_TASK_MAIN_STACK. Presumably TASK_EXTRA_STACK_SIZE is
158+
// additional stack that can be used by the esp-idf runtime. But what's
159+
// important for us is that some very outermost stack frames, such as
160+
// pyexec_friendly_repl, could lie inside the "extra" area and be invisible
161+
// to the garbage collector.
162+
return port_stack_get_limit() + ESP_TASK_MAIN_STACK / (sizeof(uint32_t) / sizeof(StackType_t));
152163
}
153164

154165
supervisor_allocation _fixed_stack;

0 commit comments

Comments
 (0)
0