diff --git a/include/zephyr/llext/llext.h b/include/zephyr/llext/llext.h index b10ba2468ae..951b13b8acd 100644 --- a/include/zephyr/llext/llext.h +++ b/include/zephyr/llext/llext.h @@ -58,8 +58,11 @@ struct llext { /** Memory allocated on heap */ bool mem_on_heap[LLEXT_MEM_COUNT]; - /** Total size of the llext memory usage */ - size_t mem_size; + /** Size of each stored section */ + size_t mem_size[LLEXT_MEM_COUNT]; + + /** Total llext allocation size */ + size_t alloc_size; /* * These are all global symbols in the extension, all of them don't diff --git a/subsys/llext/llext.c b/subsys/llext/llext.c index 80d83dbb152..fc1fbf33269 100644 --- a/subsys/llext/llext.c +++ b/subsys/llext/llext.c @@ -302,6 +302,7 @@ static int llext_copy_section(struct llext_loader *ldr, struct llext *ext, if (!ldr->sects[sect_idx].sh_size) { return 0; } + ext->mem_size[mem_idx] = ldr->sects[sect_idx].sh_size; if (ldr->sects[sect_idx].sh_type != SHT_NOBITS && IS_ENABLED(CONFIG_LLEXT_STORAGE_WRITABLE)) { @@ -318,7 +319,7 @@ static int llext_copy_section(struct llext_loader *ldr, struct llext *ext, if (!ext->mem[mem_idx]) { return -ENOMEM; } - ext->mem_size += ldr->sects[sect_idx].sh_size; + ext->alloc_size += ldr->sects[sect_idx].sh_size; if (ldr->sects[sect_idx].sh_type == SHT_NOBITS) { memset(ext->mem[mem_idx], 0, ldr->sects[sect_idx].sh_size); @@ -431,7 +432,7 @@ static int llext_allocate_symtab(struct llext_loader *ldr, struct llext *ext) return -ENOMEM; } memset(sym_tab->syms, 0, syms_size); - ext->mem_size += syms_size; + ext->alloc_size += syms_size; return 0; } @@ -801,7 +802,7 @@ static int do_llext_load(struct llext_loader *ldr, struct llext *ext, memset(ldr->sect_map, 0, sect_map_sz); ldr->sect_cnt = ldr->hdr.e_shnum; - ext->mem_size += sect_map_sz; + ext->alloc_size += sect_map_sz; LOG_DBG("Finding ELF tables..."); ret = llext_find_tables(ldr); diff --git a/subsys/llext/shell.c b/subsys/llext/shell.c index 57f5b1d131b..3bc97c3be87 100644 --- a/subsys/llext/shell.c +++ b/subsys/llext/shell.c @@ -93,7 +93,7 @@ static int llext_shell_list_cb(struct llext *ext, void *arg) { struct llext_shell_list *sl = arg; - shell_print(sl->sh, "| %16s | %12d |", ext->name, ext->mem_size); + shell_print(sl->sh, "| %16s | %12d |", ext->name, ext->alloc_size); return 0; }