diff --git a/src/library_manager/lib_manager.c b/src/library_manager/lib_manager.c index d6b0282762e8..4f6344182b88 100644 --- a/src/library_manager/lib_manager.c +++ b/src/library_manager/lib_manager.c @@ -204,9 +204,15 @@ static int lib_manager_allocate_module_instance(uint32_t module_id, uint32_t ins size_t bss_size = ctx->segment_size[SOF_MAN_SEGMENT_BSS]; void __sparse_cache *va_base = lib_manager_get_instance_bss_address(module_id, instance_id, mod); + void __sparse_cache *va_base_rodata = (void __sparse_cache *) + mod->segment[SOF_MAN_SEGMENT_RODATA].v_base_addr; + size_t st_rodata_size = ctx->segment_size[SOF_MAN_SEGMENT_RODATA]; - /* Map bss memory and clear it. */ - if (lib_manager_align_map(va_base, bss_size, SYS_MM_MEM_PERM_RW) < 0) + /* Map .bss memory if it isn't within the "RODATA" block that we've + * already mapped, and clear it. */ + if ((va_base < va_base_rodata || + (uint8_t *)va_base >= (uint8_t *)va_base_rodata + st_rodata_size) && + lib_manager_align_map(va_base, bss_size, SYS_MM_MEM_PERM_RW) < 0) return -ENOMEM; memset((__sparse_force void *)va_base, 0, bss_size); @@ -221,8 +227,15 @@ static int lib_manager_free_module_instance(uint32_t module_id, uint32_t instanc size_t bss_size = ctx->segment_size[SOF_MAN_SEGMENT_BSS]; void __sparse_cache *va_base = lib_manager_get_instance_bss_address(module_id, instance_id, mod); + void __sparse_cache *va_base_rodata = (void __sparse_cache *) + mod->segment[SOF_MAN_SEGMENT_RODATA].v_base_addr; + size_t st_rodata_size = ctx->segment_size[SOF_MAN_SEGMENT_RODATA]; + + if (va_base >= va_base_rodata && + (uint8_t *)va_base < (uint8_t *)va_base_rodata + st_rodata_size) + return 0; - /* Unmap bss memory. */ + /* Unmap .bss memory. */ return lib_manager_align_unmap(va_base, bss_size); }