py/persistentcode: Maintain root ptr list of imported native .mpy code.#6290
Merged
dpgeorge merged 1 commit intoAug 2, 2020
Merged
Conversation
2 tasks
dlech
reviewed
Jul 27, 2020
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 micropython#6045. Signed-off-by: Damien George <damien@micropython.org>
77b8e8e to
9883d8e
Compare
tannewt
pushed a commit
to tannewt/circuitpython
that referenced
this pull request
Feb 4, 2026
The CoreS3 SE is a variant of the CoreS3 with the camera, IMU, magnetometer, proximity sensor, and audio codec removed, paired with the M5GO Battery Bottom3 which adds 10 NeoPixels (GPIO5) and an IR transmitter (GPIO7). Based on the CoreS3 board definition with the following changes: - Board name set to "M5Stack CoreS3 SE" - NEOPIXEL pin defined (GPIO5) for M5GO Bottom3 LEDs - Camera pin definitions and data tuple removed from pins.c - NEOPIXEL and IR named pin aliases added to pins.c - ESPCAMERA support disabled in mpconfigboard.mk - Camera-related AXP2101 power rails (ALDO2/ALDO3) disabled in board.c - Camera config removed from sdkconfig - SD card CS (GPIO4) driven high before display init to mitigate shared SPI bus contention (see micropython#10536) Note: SD card does not work on any Core S3 variant in CircuitPython due to GPIO35 being shared between SPI MISO and display DC pin (upstream issues micropython#10536, micropython#6290). Tested on hardware: display, I2C (AXP2101, AW9523B, FT6336, BM8563), NeoPixels, IR pin, I2S speaker pins, Port B/C GPIOs all verified. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(This is an alternative to #6061 that is more comprehensive and robust.)
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.