From d50181b7f9062b01369b992f3545b94032a6b589 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Tue, 15 Apr 2025 13:25:20 +0300 Subject: [PATCH] fix(core): check QSTR run-time allocations only for frozen debug builds [no changelog] --- .github/workflows/core.yml | 1 + core/embed/upymod/modtrezorutils/modtrezorutils.c | 3 +++ core/mocks/generated/trezorutils.pyi | 1 + 3 files changed, 5 insertions(+) diff --git a/.github/workflows/core.yml b/.github/workflows/core.yml index 62d1b00b28..5df59ac1f9 100644 --- a/.github/workflows/core.yml +++ b/.github/workflows/core.yml @@ -202,6 +202,7 @@ jobs: - run: nix-shell --run "poetry run make -C core build_unix" - run: nix-shell --run "cd vendor/ts-tvl/tvl/server/model_config && poetry install && poetry run model_server tcp -c model_config.yml &" - run: nix-shell --run "poetry run make -C core test" + - run: nix-shell --run "poetry run core/emu.py -c true" # sanity check non-frozen emulator core_unit_rust_test: name: Rust unit tests diff --git a/core/embed/upymod/modtrezorutils/modtrezorutils.c b/core/embed/upymod/modtrezorutils/modtrezorutils.c index 6f82740cd7..389187035d 100644 --- a/core/embed/upymod/modtrezorutils/modtrezorutils.c +++ b/core/embed/upymod/modtrezorutils/modtrezorutils.c @@ -306,8 +306,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_enable_oom_dump_obj, /// def check_heap_fragmentation() -> None: /// """ /// Assert known sources for heap fragmentation. +/// Enabled only for frozen debug builds. /// """ STATIC mp_obj_t mod_trezorutils_check_heap_fragmentation(void) { +#if MICROPY_MODULE_FROZEN_MPY mp_obj_dict_t *modules = &MP_STATE_VM(mp_loaded_modules_dict); if (modules->map.alloc > MICROPY_LOADED_MODULES_DICT_SIZE) { mp_raise_msg(&mp_type_AssertionError, "sys.modules dict is reallocated"); @@ -336,6 +338,7 @@ STATIC mp_obj_t mod_trezorutils_check_heap_fragmentation(void) { " total bytes", n_pool, n_qstr, n_str_data_bytes, n_total_bytes); } +#endif // MICROPY_MODULE_FROZEN_MPY return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_check_heap_fragmentation_obj, diff --git a/core/mocks/generated/trezorutils.pyi b/core/mocks/generated/trezorutils.pyi index de6ccbb69b..2fae11f5e1 100644 --- a/core/mocks/generated/trezorutils.pyi +++ b/core/mocks/generated/trezorutils.pyi @@ -108,6 +108,7 @@ if __debug__: def check_heap_fragmentation() -> None: """ Assert known sources for heap fragmentation. + Enabled only for frozen debug builds. """