diff options
author | Damien George <damien@micropython.org> | 2020-07-27 23:52:38 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2020-08-02 22:34:09 +1000 |
commit | 9883d8e818feba112935676eb5aa4ce211d7779c (patch) | |
tree | ae254d6a502b92012dc1f962ede53f05f05153de /py/mpstate.h | |
parent | 8da40baa47ee9fe7aac228af2c0addd1f4ce3646 (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/mpstate.h')
-rw-r--r-- | py/mpstate.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/py/mpstate.h b/py/mpstate.h index 5f6cf5593..2519c77e2 100644 --- a/py/mpstate.h +++ b/py/mpstate.h @@ -167,6 +167,11 @@ typedef struct _mp_state_vm_t { mp_obj_dict_t *mp_module_builtins_override_dict; #endif + #if MICROPY_PERSISTENT_CODE_TRACK_RELOC_CODE + // An mp_obj_list_t that tracks relocated native code to prevent the GC from reclaiming them. + mp_obj_t track_reloc_code_list; + #endif + // include any root pointers defined by a port MICROPY_PORT_ROOT_POINTERS |