diff options
| author | Angus Gratton <angus@redyak.com.au> | 2024-11-06 14:27:01 +1100 |
|---|---|---|
| committer | Angus Gratton <angus@redyak.com.au> | 2024-11-06 16:08:23 +1100 |
| commit | df6b40a87fe3ddcb37cde488ba1a2060625ab737 (patch) | |
| tree | 118abf78c49cbc2bb5d35b9f2417773a348396a6 | |
| parent | 594670e44623e0635ecf45eb34b0a43f27e04101 (diff) | |
esp32: Workaround native code execution crash on ESP32-S2.
Seemingly ESP-IDF incorrectly marks RTC FAST memory region
as MALLOC_CAP_EXEC on ESP32-S2 when it isn't. This memory is
the lowest priority, so it only is returned if D/IRAM is exhausted.
Apply this workaround to treat the allocation as failed if it gives us
non-executable RAM back, rather than crashing.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
| -rw-r--r-- | ports/esp32/main.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/ports/esp32/main.c b/ports/esp32/main.c index 03dc0807a..18ef9d735 100644 --- a/ports/esp32/main.c +++ b/ports/esp32/main.c @@ -39,6 +39,7 @@ #include "esp_task.h" #include "esp_event.h" #include "esp_log.h" +#include "esp_memory_utils.h" #include "esp_psram.h" #include "py/cstack.h" @@ -237,6 +238,13 @@ void *esp_native_code_commit(void *buf, size_t len, void *reloc) { len = (len + 3) & ~3; size_t len_node = sizeof(native_code_node_t) + len; native_code_node_t *node = heap_caps_malloc(len_node, MALLOC_CAP_EXEC); + #if CONFIG_IDF_TARGET_ESP32S2 + // Workaround for ESP-IDF bug https://github.com/espressif/esp-idf/issues/14835 + if (node != NULL && !esp_ptr_executable(node)) { + free(node); + node = NULL; + } + #endif // CONFIG_IDF_TARGET_ESP32S2 if (node == NULL) { m_malloc_fail(len_node); } |
