summaryrefslogtreecommitdiff
path: root/py/mpconfig.h
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/mpconfig.h
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/mpconfig.h')
-rw-r--r--py/mpconfig.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/py/mpconfig.h b/py/mpconfig.h
index 287b15aae..3d9ce8bb5 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -351,6 +351,18 @@
// Convenience definition for whether any native or inline assembler emitter is enabled
#define MICROPY_EMIT_MACHINE_CODE (MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_ASM)
+// Whether native relocatable code loaded from .mpy files is explicitly tracked
+// so that the GC cannot reclaim it. Needed on architectures that allocate
+// executable memory on the MicroPython heap and don't explicitly track this
+// data some other way.
+#ifndef MICROPY_PERSISTENT_CODE_TRACK_RELOC_CODE
+#if !MICROPY_EMIT_MACHINE_CODE || defined(MP_PLAT_ALLOC_EXEC) || defined(MP_PLAT_COMMIT_EXEC)
+#define MICROPY_PERSISTENT_CODE_TRACK_RELOC_CODE (0)
+#else
+#define MICROPY_PERSISTENT_CODE_TRACK_RELOC_CODE (1)
+#endif
+#endif
+
/*****************************************************************************/
/* Compiler configuration */