Skip to content

Commit

Permalink
llext_manager: [TMP] add debugging code
Browse files Browse the repository at this point in the history
Add debugging code for comparing memory copy operations between previous
and current situations.

Signed-off-by: Luca Burelli <[email protected]>
  • Loading branch information
pillo79 committed Feb 11, 2025
1 parent a75cf84 commit 1c0910c
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/library_manager/llext_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,31 @@ static int llext_manager_load_data_from_storage(const struct llext_loader *ldr,
return ret;
}

/* DEBUG */
size_t init_offset = 0;
const elf_shdr_t *shdr;

/* Need to copy sections within regions individually, offsets may differ */
for (i = 0, shdr = llext_section_headers(ext); i < llext_section_count(ext); i++, shdr++) {
if ((uintptr_t)shdr->sh_addr < (uintptr_t)vma ||
(uintptr_t)shdr->sh_addr >= (uintptr_t)vma + size)
continue;

if (!init_offset)
init_offset = shdr->sh_offset;

/* found a section within the region */
size_t offset = shdr->sh_offset - init_offset;

tr_info(&lib_manager_tr, "old %u: %p -> %p, %u", i,
(void *)shdr->sh_addr,
(const uint8_t *)load_base + offset, shdr->sh_size);
}

llext_get_region_info(ldr, ext, region, NULL, &region_addr, &region_size);

/* Need to copy sections within regions individually, offsets may differ */
for (i = 0; i < llext_section_count(ext); i++) {
const elf_shdr_t *shdr;
enum llext_mem s_region = LLEXT_MEM_COUNT;
size_t s_offset = 0;

Expand All @@ -100,6 +120,10 @@ static int llext_manager_load_data_from_storage(const struct llext_loader *ldr,
if (s_region != region)
continue;

tr_info(&lib_manager_tr, "%u: %p -> %p, %u", i,
(void *)shdr->sh_addr,
(const uint8_t *)region_addr + s_offset, shdr->sh_size);

ret = memcpy_s((__sparse_force void *)shdr->sh_addr, size - s_offset,
(const uint8_t *)region_addr + s_offset, shdr->sh_size);
if (ret < 0)
Expand Down

0 comments on commit 1c0910c

Please sign in to comment.