diff options
| author | Damien George <damien@micropython.org> | 2022-05-19 15:04:52 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2022-05-19 17:31:56 +1000 |
| commit | c70f96f1c57456031c5b3fc9bd89a564106e345b (patch) | |
| tree | ecf6cc901a779bff806810f50f14905b8531016e /ports/esp32/main.c | |
| parent | 54ab9d23e973bdd02326eba68ea89078429e5bce (diff) | |
esp32: Track allocated iRAM and free it on soft reset.
This makes sure all iRAM allocated for native code is freed on soft reset.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'ports/esp32/main.c')
| -rw-r--r-- | ports/esp32/main.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/ports/esp32/main.c b/ports/esp32/main.c index f833c9501..14b7e14c6 100644 --- a/ports/esp32/main.c +++ b/ports/esp32/main.c @@ -152,6 +152,8 @@ soft_reset: mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib)); readline_init0(); + MP_STATE_PORT(native_code_pointers) = MP_OBJ_NULL; + // initialise peripherals machine_pins_init(); #if MICROPY_PY_MACHINE_I2S @@ -194,6 +196,16 @@ soft_reset_exit: mp_thread_deinit(); #endif + // Free any native code pointers that point to iRAM. + if (MP_STATE_PORT(native_code_pointers) != MP_OBJ_NULL) { + size_t len; + mp_obj_t *items; + mp_obj_list_get(MP_STATE_PORT(native_code_pointers), &len, &items); + for (size_t i = 0; i < len; ++i) { + heap_caps_free(MP_OBJ_TO_PTR(items[i])); + } + } + gc_sweep_all(); mp_hal_stdout_tx_str("MPY: soft reboot\r\n"); @@ -243,6 +255,10 @@ void *esp_native_code_commit(void *buf, size_t len, void *reloc) { if (p == NULL) { m_malloc_fail(len); } + if (MP_STATE_PORT(native_code_pointers) == MP_OBJ_NULL) { + MP_STATE_PORT(native_code_pointers) = mp_obj_new_list(0, NULL); + } + mp_obj_list_append(MP_STATE_PORT(native_code_pointers), MP_OBJ_TO_PTR(p)); if (reloc) { mp_native_relocate(reloc, buf, (uintptr_t)p); } |
