8000 py/persistentcode: Allow a port a custom commit function and track data. · micropython/micropython@3d7edbd · GitHub
[go: up one dir, main page]

Skip to content

Commit 3d7edbd

Browse files
committed
py/persistentcode: Allow a port a custom commit function and track data.
Allows both MICROPY_PERSISTENT_CODE_TRACK_FUN_DATA and MP_PLAT_COMMIT_EXEC to be enabled at the same time. Signed-off-by: Damien George <damien@micropython.org>
1 parent 3d19a8b commit 3d7edbd

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

py/persistentcode.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ typedef struct _bytecode_prelude_t {
7272
static int read_byte(mp_reader_t *reader);
7373
static size_t read_uint(mp_reader_t *reader);
7474

75+
#if MICROPY_EMIT_MACHINE_CODE
76+
7577
#if MICROPY_PERSISTENT_CODE_TRACK_FUN_DATA || MICROPY_PERSISTENT_CODE_TRACK_BSS_RODATA
7678

7779
// An mp_obj_list_t that tracks native text/BSS/rodata to prevent the GC from reclaiming them.
@@ -86,8 +88,6 @@ static void track_root_pointer(void *ptr) {
8688

8789
#endif
8890

89-
#if MICROPY_EMIT_MACHINE_CODE
90-
9191
typedef struct _reloc_info_t {
9292
mp_reader_t *reader;
9393
mp_module_context_t *context;
@@ -415,15 +415,17 @@ static mp_raw_code_t *load_raw_code(mp_reader_t *reader, mp_module_context_t *co
415415

416416
// Relocate and commit code to executable address space
417417
reloc_info_t ri = {reader, context, rodata, bss};
418+
#if MICROPY_PERSISTENT_CODE_TRACK_FUN_DATA
419+
if (native_scope_flags & MP_SCOPE_FLAG_VIPERRELOC) {
420+
// Track the function data memory so it's not reclaimed by the GC.
421+
track_root_pointer(fun_data);
422+
}
423+
#endif
418424
#if defined(MP_PLAT_COMMIT_EXEC)
419425
void *opt_ri = (native_scope_flags & MP_SCOPE_FLAG_VIPERRELOC) ? &ri : NULL;
420426
fun_data = MP_PLAT_COMMIT_EXEC(fun_data, fun_data_len, opt_ri);
421427
#else
422428
if (native_scope_flags & MP_SCOPE_FLAG_VIPERRELOC) {
423-
#if MICROPY_PERSISTENT_CODE_TRACK_FUN_DATA
424-
// Track the function data memory so it's not reclaimed by the GC.
425-
track_root_pointer(fun_data);
426-
#endif
427429
// Do the relocations.
428430
mp_native_relocate(&ri, fun_data, (uintptr_t)fun_data);
429431
}

py/runtime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void mp_init(void) {
123123
MP_STATE_VM(mp_module_builtins_override_dict) = NULL;
124124
#endif
125125

126-
#if MICROPY_PERSISTENT_CODE_TRACK_FUN_DATA || MICROPY_PERSISTENT_CODE_TRACK_BSS_RODATA
126+
#if MICROPY_EMIT_MACHINE_CODE && (MICROPY_PERSISTENT_CODE_TRACK_FUN_DATA || MICROPY_PERSISTENT_CODE_TRACK_BSS_RODATA)
127127
MP_STATE_VM(persistent_code_root_pointers) = MP_OBJ_NULL;
128128
#endif
129129

0 commit comments

Comments
 (0)
0