Lines Matching refs:ldr

42 const void *llext_loaded_sect_ptr(struct llext_loader *ldr, struct llext *ext, unsigned int sh_ndx)  in llext_loaded_sect_ptr()  argument
44 enum llext_mem mem_idx = ldr->sect_map[sh_ndx].mem_idx; in llext_loaded_sect_ptr()
50 return (const uint8_t *)ext->mem[mem_idx] + ldr->sect_map[sh_ndx].offset; in llext_loaded_sect_ptr()
57 static int llext_load_elf_data(struct llext_loader *ldr, struct llext *ext) in llext_load_elf_data() argument
63 ret = llext_seek(ldr, 0); in llext_load_elf_data()
69 ret = llext_read(ldr, &ldr->hdr, sizeof(ldr->hdr)); in llext_load_elf_data()
76 if (memcmp(ldr->hdr.e_ident, ELF_MAGIC, sizeof(ELF_MAGIC)) != 0) { in llext_load_elf_data()
77 LOG_HEXDUMP_ERR(ldr->hdr.e_ident, 16, "Invalid ELF, magic does not match"); in llext_load_elf_data()
81 switch (ldr->hdr.e_type) { in llext_load_elf_data()
91 LOG_ERR("Unsupported ELF file type %x", ldr->hdr.e_type); in llext_load_elf_data()
101 if (ldr->hdr.e_shentsize != sizeof(elf_shdr_t)) { in llext_load_elf_data()
102 LOG_ERR("Invalid section header size %d", ldr->hdr.e_shentsize); in llext_load_elf_data()
106 ext->sect_cnt = ldr->hdr.e_shnum; in llext_load_elf_data()
108 size_t sect_map_sz = ext->sect_cnt * sizeof(ldr->sect_map[0]); in llext_load_elf_data()
110 ldr->sect_map = llext_alloc(sect_map_sz); in llext_load_elf_data()
111 if (!ldr->sect_map) { in llext_load_elf_data()
116 ldr->sect_map[i].mem_idx = LLEXT_MEM_COUNT; in llext_load_elf_data()
117 ldr->sect_map[i].offset = 0; in llext_load_elf_data()
120 ext->sect_hdrs = (elf_shdr_t *)llext_peek(ldr, ldr->hdr.e_shoff); in llext_load_elf_data()
133 ret = llext_seek(ldr, ldr->hdr.e_shoff); in llext_load_elf_data()
139 ret = llext_read(ldr, ext->sect_hdrs, sect_hdrs_sz); in llext_load_elf_data()
152 static int llext_find_tables(struct llext_loader *ldr, struct llext *ext) in llext_find_tables() argument
156 memset(ldr->sects, 0, sizeof(ldr->sects)); in llext_find_tables()
178 ldr->sects[LLEXT_MEM_SYMTAB] = *shdr; in llext_find_tables()
179 ldr->sect_map[i].mem_idx = LLEXT_MEM_SYMTAB; in llext_find_tables()
183 if (ldr->hdr.e_shstrndx == i) { in llext_find_tables()
185 ldr->sects[LLEXT_MEM_SHSTRTAB] = *shdr; in llext_find_tables()
186 ldr->sect_map[i].mem_idx = LLEXT_MEM_SHSTRTAB; in llext_find_tables()
189 ldr->sects[LLEXT_MEM_STRTAB] = *shdr; in llext_find_tables()
190 ldr->sect_map[i].mem_idx = LLEXT_MEM_STRTAB; in llext_find_tables()
199 if (!ldr->sects[LLEXT_MEM_SHSTRTAB].sh_type || in llext_find_tables()
200 !ldr->sects[LLEXT_MEM_STRTAB].sh_type || in llext_find_tables()
201 !ldr->sects[LLEXT_MEM_SYMTAB].sh_type) { in llext_find_tables()
213 static int llext_map_sections(struct llext_loader *ldr, struct llext *ext, in llext_map_sections() argument
222 name = llext_string(ldr, ext, LLEXT_MEM_SHSTRTAB, shdr->sh_name); in llext_map_sections()
224 if (ldr->sect_map[i].mem_idx != LLEXT_MEM_COUNT) { in llext_map_sections()
226 i, name, ldr->sect_map[i].mem_idx); in llext_map_sections()
287 ldr->sect_map[i].mem_idx = mem_idx; in llext_map_sections()
288 elf_shdr_t *region = ldr->sects + mem_idx; in llext_map_sections()
336 if (ldr->hdr.e_type == ET_DYN) { in llext_map_sections()
371 elf_shdr_t *x = ldr->sects + i; in llext_map_sections()
372 elf_shdr_t *y = ldr->sects + j; in llext_map_sections()
398 if (ldr->hdr.e_type == ET_DYN) { in llext_map_sections()
442 enum llext_mem mem_idx = ldr->sect_map[i].mem_idx; in llext_map_sections()
445 ldr->sect_map[i].offset = shdr->sh_offset - ldr->sects[mem_idx].sh_offset; in llext_map_sections()
452 static int llext_count_export_syms(struct llext_loader *ldr, struct llext *ext) in llext_count_export_syms() argument
454 size_t ent_size = ldr->sects[LLEXT_MEM_SYMTAB].sh_entsize; in llext_count_export_syms()
455 size_t syms_size = ldr->sects[LLEXT_MEM_SYMTAB].sh_size; in llext_count_export_syms()
465 for (i = 0, pos = ldr->sects[LLEXT_MEM_SYMTAB].sh_offset; in llext_count_export_syms()
473 ret = llext_seek(ldr, pos); in llext_count_export_syms()
478 ret = llext_read(ldr, &sym, ent_size); in llext_count_export_syms()
487 name = llext_string(ldr, ext, LLEXT_MEM_STRTAB, sym.st_name); in llext_count_export_syms()
502 static int llext_allocate_symtab(struct llext_loader *ldr, struct llext *ext) in llext_allocate_symtab() argument
517 static int llext_export_symbols(struct llext_loader *ldr, struct llext *ext) in llext_export_symbols() argument
519 elf_shdr_t *shdr = ldr->sects + LLEXT_MEM_EXPORT; in llext_export_symbols()
547 static int llext_copy_symbols(struct llext_loader *ldr, struct llext *ext, in llext_copy_symbols() argument
550 size_t ent_size = ldr->sects[LLEXT_MEM_SYMTAB].sh_entsize; in llext_copy_symbols()
551 size_t syms_size = ldr->sects[LLEXT_MEM_SYMTAB].sh_size; in llext_copy_symbols()
558 for (i = 0, pos = ldr->sects[LLEXT_MEM_SYMTAB].sh_offset, j = 0; in llext_copy_symbols()
566 ret = llext_seek(ldr, pos); in llext_copy_symbols()
571 ret = llext_read(ldr, &sym, ent_size); in llext_copy_symbols()
582 const char *name = llext_string(ldr, ext, LLEXT_MEM_STRTAB, sym.st_name); in llext_copy_symbols()
594 (ldr->hdr.e_type == ET_REL ? section_addr : 0); in llext_copy_symbols()
598 base = llext_loaded_sect_ptr(ldr, ext, shndx); in llext_copy_symbols()
604 base = llext_peek(ldr, shdr->sh_offset); in llext_copy_symbols()
614 (ldr->hdr.e_type == ET_REL ? 0 : section_addr); in llext_copy_symbols()
629 int do_llext_load(struct llext_loader *ldr, struct llext *ext, in do_llext_load() argument
643 ldr->sect_map = NULL; in do_llext_load()
646 ret = llext_prepare(ldr); in do_llext_load()
652 ret = llext_load_elf_data(ldr, ext); in do_llext_load()
667 ret = llext_find_tables(ldr, ext); in do_llext_load()
674 ret = llext_copy_strings(ldr, ext); in do_llext_load()
681 ret = llext_map_sections(ldr, ext, ldr_parm); in do_llext_load()
688 ret = llext_copy_regions(ldr, ext, ldr_parm); in do_llext_load()
695 ret = llext_count_export_syms(ldr, ext); in do_llext_load()
702 ret = llext_allocate_symtab(ldr, ext); in do_llext_load()
709 ret = llext_copy_symbols(ldr, ext, ldr_parm); in do_llext_load()
717 ret = llext_link(ldr, ext, ldr_parm); in do_llext_load()
724 ret = llext_export_symbols(ldr, ext); in do_llext_load()
738 llext_free(ldr->sect_map); in do_llext_load()
739 ldr->sect_map = NULL; in do_llext_load()
767 llext_finalize(ldr); in do_llext_load()