aboutsummaryrefslogtreecommitdiff
path: root/py/runtime.c
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2020-07-27 23:52:38 +1000
committerDamien George <damien@micropython.org>2020-08-02 22:34:09 +1000
commit9883d8e818feba112935676eb5aa4ce211d7779c (patch)
treeae254d6a502b92012dc1f962ede53f05f05153de /py/runtime.c
parent8da40baa47ee9fe7aac228af2c0addd1f4ce3646 (diff)
py/persistentcode: Maintain root ptr list of imported native .mpy code.
On ports where normal heap memory can contain executable code (eg ARM-based ports such as stm32), native code loaded from an .mpy file may be reclaimed by the GC because there's no reference to the very start of the native machine code block that is reachable from root pointers (only pointers to internal parts of the machine code block are reachable, but that doesn't help the GC find the memory). This commit fixes this issue by maintaining an explicit list of root pointers pointing to native code that is loaded from an .mpy file. This is not needed for all ports so is selectable by the new configuration option MICROPY_PERSISTENT_CODE_TRACK_RELOC_CODE. It's enabled by default if a port does not specify any special functions to allocate or commit executable memory. A test is included to test that native code loaded from an .mpy file does not get reclaimed by the GC. Fixes #6045. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'py/runtime.c')
-rw-r--r--py/runtime.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/py/runtime.c b/py/runtime.c
index 78da38691..38da2f453 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -106,6 +106,10 @@ void mp_init(void) {
MP_STATE_VM(mp_module_builtins_override_dict) = NULL;
#endif
+ #if MICROPY_PERSISTENT_CODE_TRACK_RELOC_CODE
+ MP_STATE_VM(track_reloc_code_list) = MP_OBJ_NULL;
+ #endif
+
#if MICROPY_PY_OS_DUPTERM
for (size_t i = 0; i < MICROPY_PY_OS_DUPTERM; ++i) {
MP_STATE_VM(dupterm_objs[i]) = MP_OBJ_NULL;