Skip to content

Commit

Permalink
lib-manager: add support for .bss within data mapping
Browse files Browse the repository at this point in the history
If the .bss range is within the already mapped .rodata / .data
mapping, we don't need to map it separately.

Signed-off-by: Guennadi Liakhovetski <[email protected]>
  • Loading branch information
lyakh committed Dec 15, 2023
1 parent 3854e89 commit 3b05ad2
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/library_manager/lib_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down

0 comments on commit 3b05ad2

Please sign in to comment.