Lines Matching refs:elf
53 static void assign_tls_mod_id(struct ta_elf *elf) in assign_tls_mod_id() argument
57 if (elf->is_main) in assign_tls_mod_id()
59 elf->tls_mod_id = last_tls_mod_id++; in assign_tls_mod_id()
64 struct ta_elf *elf = calloc(1, sizeof(*elf)); in queue_elf_helper() local
66 if (!elf) in queue_elf_helper()
69 TAILQ_INIT(&elf->segs); in queue_elf_helper()
71 elf->uuid = *uuid; in queue_elf_helper()
72 TAILQ_INSERT_TAIL(&main_elf_queue, elf, link); in queue_elf_helper()
73 return elf; in queue_elf_helper()
78 struct ta_elf *elf = ta_elf_find_elf(uuid); in queue_elf() local
80 if (elf) in queue_elf()
83 elf = queue_elf_helper(uuid); in queue_elf()
84 if (!elf) in queue_elf()
87 return elf; in queue_elf()
92 struct ta_elf *elf = NULL; in ta_elf_find_elf() local
94 TAILQ_FOREACH(elf, &main_elf_queue, link) in ta_elf_find_elf()
95 if (!memcmp(uuid, &elf->uuid, sizeof(*uuid))) in ta_elf_find_elf()
96 return elf; in ta_elf_find_elf()
102 static TEE_Result e32_parse_ehdr(struct ta_elf *elf, Elf32_Ehdr *ehdr) in e32_parse_ehdr() argument
117 elf->is_32bit = true; in e32_parse_ehdr()
118 elf->e_entry = ehdr->e_entry; in e32_parse_ehdr()
119 elf->e_phoff = ehdr->e_phoff; in e32_parse_ehdr()
120 elf->e_shoff = ehdr->e_shoff; in e32_parse_ehdr()
121 elf->e_phnum = ehdr->e_phnum; in e32_parse_ehdr()
122 elf->e_shnum = ehdr->e_shnum; in e32_parse_ehdr()
123 elf->e_phentsize = ehdr->e_phentsize; in e32_parse_ehdr()
124 elf->e_shentsize = ehdr->e_shentsize; in e32_parse_ehdr()
130 static TEE_Result e64_parse_ehdr(struct ta_elf *elf, Elf64_Ehdr *ehdr) in e64_parse_ehdr() argument
142 elf->is_32bit = false; in e64_parse_ehdr()
143 elf->e_entry = ehdr->e_entry; in e64_parse_ehdr()
144 elf->e_phoff = ehdr->e_phoff; in e64_parse_ehdr()
145 elf->e_shoff = ehdr->e_shoff; in e64_parse_ehdr()
146 elf->e_phnum = ehdr->e_phnum; in e64_parse_ehdr()
147 elf->e_shnum = ehdr->e_shnum; in e64_parse_ehdr()
148 elf->e_phentsize = ehdr->e_phentsize; in e64_parse_ehdr()
149 elf->e_shentsize = ehdr->e_shentsize; in e64_parse_ehdr()
154 static TEE_Result e64_parse_ehdr(struct ta_elf *elf __unused, in e64_parse_ehdr()
163 static TEE_Result e32_parse_ehdr(struct ta_elf *elf __unused, in e32_parse_ehdr()
169 static TEE_Result e64_parse_ehdr(struct ta_elf *elf, Elf64_Ehdr *ehdr) in e64_parse_ehdr() argument
180 elf->is_32bit = false; in e64_parse_ehdr()
181 elf->e_entry = ehdr->e_entry; in e64_parse_ehdr()
182 elf->e_phoff = ehdr->e_phoff; in e64_parse_ehdr()
183 elf->e_shoff = ehdr->e_shoff; in e64_parse_ehdr()
184 elf->e_phnum = ehdr->e_phnum; in e64_parse_ehdr()
185 elf->e_shnum = ehdr->e_shnum; in e64_parse_ehdr()
186 elf->e_phentsize = ehdr->e_phentsize; in e64_parse_ehdr()
187 elf->e_shentsize = ehdr->e_shentsize; in e64_parse_ehdr()
193 static void check_phdr_in_range(struct ta_elf *elf, unsigned int type, in check_phdr_in_range() argument
206 if (max_addr > elf->max_addr - elf->load_addr) in check_phdr_in_range()
211 static void read_dyn(struct ta_elf *elf, vaddr_t addr, in read_dyn() argument
214 if (elf->is_32bit) { in read_dyn()
215 Elf32_Dyn *dyn = (Elf32_Dyn *)(addr + elf->load_addr); in read_dyn()
220 Elf64_Dyn *dyn = (Elf64_Dyn *)(addr + elf->load_addr); in read_dyn()
227 static void check_range(struct ta_elf *elf, const char *name, const void *ptr, in check_range() argument
232 if ((vaddr_t)ptr < elf->load_addr) in check_range()
238 if (max_addr > elf->max_addr) in check_range()
243 static void check_hashtab(struct ta_elf *elf, void *ptr, size_t num_buckets, in check_hashtab() argument
264 check_range(elf, "DT_HASH", ptr, sz); in check_hashtab()
267 static void check_gnu_hashtab(struct ta_elf *elf, void *ptr) in check_gnu_hashtab() argument
278 if (elf->gnu_hashtab_size < sizeof(*h)) in check_gnu_hashtab()
283 if (elf->is_32bit) in check_gnu_hashtab()
290 sz > elf->gnu_hashtab_size) in check_gnu_hashtab()
294 static void save_hashtab(struct ta_elf *elf) in save_hashtab() argument
299 if (elf->is_32bit) { in save_hashtab()
300 Elf32_Shdr *shdr = elf->shdr; in save_hashtab()
302 for (n = 0; n < elf->e_shnum; n++) { in save_hashtab()
304 elf->load_addr); in save_hashtab()
307 elf->hashtab = addr; in save_hashtab()
309 elf->gnu_hashtab = addr; in save_hashtab()
310 elf->gnu_hashtab_size = shdr[n].sh_size; in save_hashtab()
314 Elf64_Shdr *shdr = elf->shdr; in save_hashtab()
316 for (n = 0; n < elf->e_shnum; n++) { in save_hashtab()
318 elf->load_addr); in save_hashtab()
321 elf->hashtab = addr; in save_hashtab()
323 elf->gnu_hashtab = addr; in save_hashtab()
324 elf->gnu_hashtab_size = shdr[n].sh_size; in save_hashtab()
329 if (elf->hashtab) { in save_hashtab()
330 check_hashtab(elf, elf->hashtab, 0, 0); in save_hashtab()
331 hashtab = elf->hashtab; in save_hashtab()
332 check_hashtab(elf, elf->hashtab, hashtab[0], hashtab[1]); in save_hashtab()
334 if (elf->gnu_hashtab) in save_hashtab()
335 check_gnu_hashtab(elf, elf->gnu_hashtab); in save_hashtab()
338 static void save_soname_from_segment(struct ta_elf *elf, unsigned int type, in save_soname_from_segment() argument
351 if (elf->is_32bit) in save_soname_from_segment()
360 read_dyn(elf, addr, n, &tag, &val); in save_soname_from_segment()
362 str_tab = (char *)(val + elf->load_addr); in save_soname_from_segment()
367 read_dyn(elf, addr, n, &tag, &val); in save_soname_from_segment()
369 elf->soname = str_tab + val; in save_soname_from_segment()
375 static void save_soname(struct ta_elf *elf) in save_soname() argument
379 if (elf->is_32bit) { in save_soname()
380 Elf32_Phdr *phdr = elf->phdr; in save_soname()
382 for (n = 0; n < elf->e_phnum; n++) in save_soname()
383 save_soname_from_segment(elf, phdr[n].p_type, in save_soname()
387 Elf64_Phdr *phdr = elf->phdr; in save_soname()
389 for (n = 0; n < elf->e_phnum; n++) in save_soname()
390 save_soname_from_segment(elf, phdr[n].p_type, in save_soname()
396 static void e32_save_symtab(struct ta_elf *elf, size_t tab_idx) in e32_save_symtab() argument
398 Elf32_Shdr *shdr = elf->shdr; in e32_save_symtab()
401 elf->dynsymtab = (void *)(shdr[tab_idx].sh_addr + elf->load_addr); in e32_save_symtab()
402 if (!IS_ALIGNED_WITH_TYPE(elf->dynsymtab, Elf32_Sym)) in e32_save_symtab()
404 elf->dynsymtab); in e32_save_symtab()
405 check_range(elf, "Dynsymtab", elf->dynsymtab, shdr[tab_idx].sh_size); in e32_save_symtab()
410 elf->num_dynsyms = shdr[tab_idx].sh_size / sizeof(Elf32_Sym); in e32_save_symtab()
412 if (str_idx >= elf->e_shnum) in e32_save_symtab()
414 elf->dynstr = (void *)(shdr[str_idx].sh_addr + elf->load_addr); in e32_save_symtab()
415 check_range(elf, "Dynstr", elf->dynstr, shdr[str_idx].sh_size); in e32_save_symtab()
417 elf->dynstr_size = shdr[str_idx].sh_size; in e32_save_symtab()
420 static void e64_save_symtab(struct ta_elf *elf, size_t tab_idx) in e64_save_symtab() argument
422 Elf64_Shdr *shdr = elf->shdr; in e64_save_symtab()
425 elf->dynsymtab = (void *)(vaddr_t)(shdr[tab_idx].sh_addr + in e64_save_symtab()
426 elf->load_addr); in e64_save_symtab()
428 if (!IS_ALIGNED_WITH_TYPE(elf->dynsymtab, Elf64_Sym)) in e64_save_symtab()
430 elf->dynsymtab); in e64_save_symtab()
431 check_range(elf, ".dynsym/DYNSYM", elf->dynsymtab, in e64_save_symtab()
437 elf->num_dynsyms = shdr[tab_idx].sh_size / sizeof(Elf64_Sym); in e64_save_symtab()
439 if (str_idx >= elf->e_shnum) in e64_save_symtab()
442 elf->dynstr = (void *)(vaddr_t)(shdr[str_idx].sh_addr + elf->load_addr); in e64_save_symtab()
443 check_range(elf, ".dynstr/STRTAB", elf->dynstr, shdr[str_idx].sh_size); in e64_save_symtab()
445 elf->dynstr_size = shdr[str_idx].sh_size; in e64_save_symtab()
448 static void save_symtab(struct ta_elf *elf) in save_symtab() argument
452 if (elf->is_32bit) { in save_symtab()
453 Elf32_Shdr *shdr = elf->shdr; in save_symtab()
455 for (n = 0; n < elf->e_shnum; n++) { in save_symtab()
457 e32_save_symtab(elf, n); in save_symtab()
462 Elf64_Shdr *shdr = elf->shdr; in save_symtab()
464 for (n = 0; n < elf->e_shnum; n++) { in save_symtab()
466 e64_save_symtab(elf, n); in save_symtab()
473 save_hashtab(elf); in save_symtab()
474 save_soname(elf); in save_symtab()
477 static void init_elf(struct ta_elf *elf) in init_elf() argument
484 res = sys_open_ta_bin(&elf->uuid, &elf->handle); in init_elf()
486 err(res, "sys_open_ta_bin(%pUl)", (void *)&elf->uuid); in init_elf()
492 if (!elf->is_main) in init_elf()
494 res = sys_map_ta_bin(&va, SMALL_PAGE_SIZE, flags, elf->handle, 0, 0, 0); in init_elf()
497 elf->ehdr_addr = va; in init_elf()
498 if (!elf->is_main) { in init_elf()
499 elf->load_addr = va; in init_elf()
500 elf->max_addr = va + SMALL_PAGE_SIZE; in init_elf()
501 elf->max_offs = SMALL_PAGE_SIZE; in init_elf()
507 res = e32_parse_ehdr(elf, (void *)va); in init_elf()
509 res = e64_parse_ehdr(elf, (void *)va); in init_elf()
513 if (MUL_OVERFLOW(elf->e_phnum, elf->e_phentsize, &sz) || in init_elf()
514 ADD_OVERFLOW(sz, elf->e_phoff, &sz)) in init_elf()
520 elf->phdr = (void *)(va + elf->e_phoff); in init_elf()
533 static void add_segment(struct ta_elf *elf, size_t offset, size_t vaddr, in add_segment() argument
551 TAILQ_INSERT_TAIL(&elf->segs, seg, link); in add_segment()
554 static void parse_load_segments(struct ta_elf *elf) in parse_load_segments() argument
558 if (elf->is_32bit) { in parse_load_segments()
559 Elf32_Phdr *phdr = elf->phdr; in parse_load_segments()
561 for (n = 0; n < elf->e_phnum; n++) in parse_load_segments()
563 add_segment(elf, phdr[n].p_offset, in parse_load_segments()
568 elf->exidx_start = phdr[n].p_vaddr; in parse_load_segments()
569 elf->exidx_size = phdr[n].p_filesz; in parse_load_segments()
571 assign_tls_mod_id(elf); in parse_load_segments()
574 Elf64_Phdr *phdr = elf->phdr; in parse_load_segments()
576 for (n = 0; n < elf->e_phnum; n++) in parse_load_segments()
578 add_segment(elf, phdr[n].p_offset, in parse_load_segments()
583 elf->tls_start = phdr[n].p_vaddr; in parse_load_segments()
584 elf->tls_filesz = phdr[n].p_filesz; in parse_load_segments()
585 elf->tls_memsz = phdr[n].p_memsz; in parse_load_segments()
588 elf->prop_start = phdr[n].p_vaddr; in parse_load_segments()
589 elf->prop_align = phdr[n].p_align; in parse_load_segments()
590 elf->prop_memsz = phdr[n].p_memsz; in parse_load_segments()
595 static void copy_remapped_to(struct ta_elf *elf, const struct segment *seg) in copy_remapped_to() argument
597 uint8_t *dst = (void *)(seg->vaddr + elf->load_addr); in copy_remapped_to()
602 if (offs < elf->max_offs) { in copy_remapped_to()
603 n = MIN(elf->max_offs - offs, num_bytes); in copy_remapped_to()
604 memcpy(dst, (void *)(elf->max_addr + offs - elf->max_offs), n); in copy_remapped_to()
612 elf->handle, offs); in copy_remapped_to()
616 elf->max_offs += offs; in copy_remapped_to()
620 static void adjust_segments(struct ta_elf *elf) in adjust_segments() argument
629 TAILQ_FOREACH(seg, &elf->segs, link) { in adjust_segments()
651 seg = TAILQ_FIRST(&elf->segs); in adjust_segments()
688 TAILQ_REMOVE(&elf->segs, seg, link); in adjust_segments()
716 static void populate_segments_legacy(struct ta_elf *elf) in populate_segments_legacy() argument
722 assert(elf->is_legacy); in populate_segments_legacy()
723 TAILQ_FOREACH(seg, &elf->segs, link) { in populate_segments_legacy()
724 struct segment *last_seg = TAILQ_LAST(&elf->segs, segment_head); in populate_segments_legacy()
729 if (!elf->load_addr) in populate_segments_legacy()
732 va = seg->vaddr + elf->load_addr; in populate_segments_legacy()
743 elf->handle, seg->offset); in populate_segments_legacy()
747 if (!elf->load_addr) in populate_segments_legacy()
748 elf->load_addr = va; in populate_segments_legacy()
749 elf->max_addr = va + num_bytes; in populate_segments_legacy()
750 elf->max_offs = seg->offset + seg->filesz; in populate_segments_legacy()
780 static void populate_segments(struct ta_elf *elf) in populate_segments() argument
787 assert(!elf->is_legacy); in populate_segments()
788 TAILQ_FOREACH(seg, &elf->segs, link) { in populate_segments()
789 struct segment *last_seg = TAILQ_LAST(&elf->segs, segment_head); in populate_segments()
797 assert(elf->load_addr); in populate_segments()
798 va = rounddown(elf->load_addr + seg->vaddr); in populate_segments()
799 assert(va >= elf->max_addr); in populate_segments()
804 copy_remapped_to(elf, seg); in populate_segments()
805 elf->max_addr = va + num_bytes; in populate_segments()
813 if (offset < elf->max_offs) { in populate_segments()
834 va = elf->max_addr; in populate_segments()
843 elf->max_addr = roundup(va + num_bytes); in populate_segments()
854 if (!elf->load_addr) { in populate_segments()
863 va = vaddr + elf->load_addr; in populate_segments()
885 elf->handle, offset); in populate_segments()
893 elf->handle, offset, in populate_segments()
897 elf->handle, in populate_segments()
904 if (!elf->load_addr) in populate_segments()
905 elf->load_addr = va; in populate_segments()
906 elf->max_addr = roundup(va + memsz); in populate_segments()
907 elf->max_offs += filesz; in populate_segments()
912 static void ta_elf_add_bti(struct ta_elf *elf) in ta_elf_add_bti() argument
918 TAILQ_FOREACH(seg, &elf->segs, link) { in ta_elf_add_bti()
919 vaddr_t va = elf->load_addr + seg->vaddr; in ta_elf_add_bti()
929 static void parse_property_segment(struct ta_elf *elf) in parse_property_segment() argument
932 size_t align = elf->prop_align; in parse_property_segment()
939 if (!IS_ENABLED(CFG_TA_BTI) || !elf->prop_start) in parse_property_segment()
942 check_phdr_in_range(elf, PT_GNU_PROPERTY, elf->prop_start, in parse_property_segment()
943 elf->prop_memsz); in parse_property_segment()
945 va = elf->load_addr + elf->prop_start; in parse_property_segment()
949 if (elf->prop_memsz < sizeof(*note) + sizeof(ELF_NOTE_GNU)) in parse_property_segment()
960 if (desc_offset > elf->prop_memsz || in parse_property_segment()
961 ROUNDUP(desc_offset + note->n_descsz, align) > elf->prop_memsz) in parse_property_segment()
984 elf->bti_enabled = true; in parse_property_segment()
992 static void map_segments(struct ta_elf *elf) in map_segments() argument
996 parse_load_segments(elf); in map_segments()
997 adjust_segments(elf); in map_segments()
998 if (TAILQ_FIRST(&elf->segs)->offset < SMALL_PAGE_SIZE) { in map_segments()
1000 size_t sz = elf->max_addr - elf->load_addr; in map_segments()
1001 struct segment *seg = TAILQ_LAST(&elf->segs, segment_head); in map_segments()
1008 assert(!elf->is_main); in map_segments()
1015 res = sys_remap(elf->load_addr, &va, sz, pad_begin, in map_segments()
1018 res = sys_remap(elf->load_addr, &va, sz, 0, in map_segments()
1022 elf->ehdr_addr = va; in map_segments()
1023 elf->load_addr = va; in map_segments()
1024 elf->max_addr = va + sz; in map_segments()
1025 elf->phdr = (void *)(va + elf->e_phoff); in map_segments()
1029 static void add_deps_from_segment(struct ta_elf *elf, unsigned int type, in add_deps_from_segment() argument
1044 check_phdr_in_range(elf, type, addr, memsz); in add_deps_from_segment()
1046 if (elf->is_32bit) in add_deps_from_segment()
1055 read_dyn(elf, addr, n, &tag, &val); in add_deps_from_segment()
1057 str_tab = (char *)(val + elf->load_addr); in add_deps_from_segment()
1061 check_range(elf, ".dynstr/STRTAB", str_tab, str_tab_sz); in add_deps_from_segment()
1064 read_dyn(elf, addr, n, &tag, &val); in add_deps_from_segment()
1075 static void add_dependencies(struct ta_elf *elf) in add_dependencies() argument
1079 if (elf->is_32bit) { in add_dependencies()
1080 Elf32_Phdr *phdr = elf->phdr; in add_dependencies()
1082 for (n = 0; n < elf->e_phnum; n++) in add_dependencies()
1083 add_deps_from_segment(elf, phdr[n].p_type, in add_dependencies()
1086 Elf64_Phdr *phdr = elf->phdr; in add_dependencies()
1088 for (n = 0; n < elf->e_phnum; n++) in add_dependencies()
1089 add_deps_from_segment(elf, phdr[n].p_type, in add_dependencies()
1094 static void copy_section_headers(struct ta_elf *elf) in copy_section_headers() argument
1100 if (MUL_OVERFLOW(elf->e_shnum, elf->e_shentsize, &sz)) in copy_section_headers()
1103 elf->shdr = malloc(sz); in copy_section_headers()
1104 if (!elf->shdr) in copy_section_headers()
1112 if (elf->e_shoff < SMALL_PAGE_SIZE) { in copy_section_headers()
1113 assert(!elf->is_main); in copy_section_headers()
1114 offs = MIN(SMALL_PAGE_SIZE - elf->e_shoff, sz); in copy_section_headers()
1115 memcpy(elf->shdr, (void *)(elf->load_addr + elf->e_shoff), in copy_section_headers()
1120 res = sys_copy_from_ta_bin((uint8_t *)elf->shdr + offs, in copy_section_headers()
1121 sz - offs, elf->handle, in copy_section_headers()
1122 elf->e_shoff + offs); in copy_section_headers()
1128 static void close_handle(struct ta_elf *elf) in close_handle() argument
1130 TEE_Result res = sys_close_ta_bin(elf->handle); in close_handle()
1134 elf->handle = -1; in close_handle()
1137 static void clean_elf_load_main(struct ta_elf *elf) in clean_elf_load_main() argument
1144 res = sys_unmap(elf->ehdr_addr, SMALL_PAGE_SIZE); in clean_elf_load_main()
1148 while (!TAILQ_EMPTY(&elf->segs)) { in clean_elf_load_main()
1149 struct segment *seg = TAILQ_FIRST(&elf->segs); in clean_elf_load_main()
1153 va = rounddown(elf->load_addr + seg->vaddr); in clean_elf_load_main()
1164 TAILQ_REMOVE(&elf->segs, seg, link); in clean_elf_load_main()
1168 free(elf->shdr); in clean_elf_load_main()
1169 memset(&elf->is_32bit, 0, in clean_elf_load_main()
1170 (vaddr_t)&elf->uuid - (vaddr_t)&elf->is_32bit); in clean_elf_load_main()
1172 TAILQ_INIT(&elf->segs); in clean_elf_load_main()
1181 static void set_tls_offset(struct ta_elf *elf) in set_tls_offset() argument
1185 if (!elf->tls_start) in set_tls_offset()
1189 elf->tls_tcb_offs = next_offs; in set_tls_offset()
1190 next_offs += elf->tls_memsz; in set_tls_offset()
1193 static void set_tls_offset(struct ta_elf *elf __unused) {} in set_tls_offset()
1196 static void load_main(struct ta_elf *elf) in load_main() argument
1198 init_elf(elf); in load_main()
1199 map_segments(elf); in load_main()
1200 populate_segments(elf); in load_main()
1201 add_dependencies(elf); in load_main()
1202 copy_section_headers(elf); in load_main()
1203 save_symtab(elf); in load_main()
1204 close_handle(elf); in load_main()
1205 set_tls_offset(elf); in load_main()
1206 parse_property_segment(elf); in load_main()
1207 if (elf->bti_enabled) in load_main()
1208 ta_elf_add_bti(elf); in load_main()
1210 elf->head = (struct ta_head *)elf->load_addr; in load_main()
1211 if (elf->head->depr_entry != UINT64_MAX) { in load_main()
1227 DMSG("Reloading TA %pUl as legacy TA", (void *)&elf->uuid); in load_main()
1228 clean_elf_load_main(elf); in load_main()
1229 elf->is_legacy = true; in load_main()
1230 init_elf(elf); in load_main()
1231 map_segments(elf); in load_main()
1232 populate_segments_legacy(elf); in load_main()
1233 add_dependencies(elf); in load_main()
1234 copy_section_headers(elf); in load_main()
1235 save_symtab(elf); in load_main()
1236 close_handle(elf); in load_main()
1237 elf->head = (struct ta_head *)elf->load_addr; in load_main()
1242 if (elf->head->depr_entry == UINT64_MAX) in load_main()
1245 (void *)&elf->uuid); in load_main()
1253 struct ta_elf *elf = queue_elf(uuid); in ta_elf_load_main() local
1257 assert(elf); in ta_elf_load_main()
1258 elf->is_main = true; in ta_elf_load_main()
1260 load_main(elf); in ta_elf_load_main()
1262 *is_32bit = elf->is_32bit; in ta_elf_load_main()
1263 res = sys_map_zi(elf->head->stack_size, 0, &va, 0, 0); in ta_elf_load_main()
1267 if (elf->head->flags & ~TA_FLAGS_MASK) in ta_elf_load_main()
1269 elf->head->flags & ~TA_FLAGS_MASK); in ta_elf_load_main()
1271 *ta_flags = elf->head->flags; in ta_elf_load_main()
1272 *sp = va + elf->head->stack_size; in ta_elf_load_main()
1274 ta_stack_size = elf->head->stack_size; in ta_elf_load_main()
1279 struct ta_elf *elf = TAILQ_FIRST(&main_elf_queue); in ta_elf_finalize_load_main() local
1282 assert(elf->is_main); in ta_elf_finalize_load_main()
1284 res = ta_elf_set_init_fini_info_compat(elf->is_32bit); in ta_elf_finalize_load_main()
1287 res = ta_elf_set_elf_phdr_info(elf->is_32bit); in ta_elf_finalize_load_main()
1291 if (elf->is_legacy) in ta_elf_finalize_load_main()
1292 *entry = elf->head->depr_entry; in ta_elf_finalize_load_main()
1294 *entry = elf->e_entry + elf->load_addr; in ta_elf_finalize_load_main()
1298 void ta_elf_load_dependency(struct ta_elf *elf, bool is_32bit) in ta_elf_load_dependency() argument
1300 if (elf->is_main) in ta_elf_load_dependency()
1303 init_elf(elf); in ta_elf_load_dependency()
1304 if (elf->is_32bit != is_32bit) in ta_elf_load_dependency()
1306 (void *)&elf->uuid, elf->is_32bit ? "32" : "64", in ta_elf_load_dependency()
1309 map_segments(elf); in ta_elf_load_dependency()
1310 populate_segments(elf); in ta_elf_load_dependency()
1311 add_dependencies(elf); in ta_elf_load_dependency()
1312 copy_section_headers(elf); in ta_elf_load_dependency()
1313 save_symtab(elf); in ta_elf_load_dependency()
1314 close_handle(elf); in ta_elf_load_dependency()
1315 set_tls_offset(elf); in ta_elf_load_dependency()
1316 parse_property_segment(elf); in ta_elf_load_dependency()
1317 if (elf->bti_enabled) in ta_elf_load_dependency()
1318 ta_elf_add_bti(elf); in ta_elf_load_dependency()
1321 void ta_elf_finalize_mappings(struct ta_elf *elf) in ta_elf_finalize_mappings() argument
1326 if (!elf->is_legacy) in ta_elf_finalize_mappings()
1329 TAILQ_FOREACH(seg, &elf->segs, link) { in ta_elf_finalize_mappings()
1330 vaddr_t va = elf->load_addr + seg->vaddr; in ta_elf_finalize_mappings()
1397 struct ta_elf **elf, struct segment **seg, in get_next_in_order() argument
1407 assert(elf && seg && elf_idx); in get_next_in_order()
1408 e = *elf; in get_next_in_order()
1437 *elf = e; in get_next_in_order()
1448 struct ta_elf *elf = NULL; in ta_elf_print_mappings() local
1458 get_next_in_order(elf_queue, &elf, &seg, &elf_idx); in ta_elf_print_mappings()
1466 va = rounddown(seg->vaddr + elf->load_addr); in ta_elf_print_mappings()
1525 if (!get_next_in_order(elf_queue, &elf, &seg, &elf_idx)) in ta_elf_print_mappings()
1530 TAILQ_FOREACH(elf, elf_queue, link) { in ta_elf_print_mappings()
1533 elf_idx, (void *)&elf->uuid, 8, elf->load_addr); in ta_elf_print_mappings()
1543 struct ta_elf *elf = NULL; in find_exidx() local
1546 TAILQ_FOREACH(elf, &main_elf_queue, link) { in find_exidx()
1547 if (addr < elf->load_addr) in find_exidx()
1549 a = addr - elf->load_addr; in find_exidx()
1550 TAILQ_FOREACH(seg, &elf->segs, link) { in find_exidx()
1554 *idx_start = elf->exidx_start + elf->load_addr; in find_exidx()
1555 *idx_end = elf->exidx_start + elf->load_addr + in find_exidx()
1556 elf->exidx_size; in find_exidx()
1586 struct ta_elf *elf = NULL; in ta_elf_add_library() local
1595 for (elf = lib; elf; elf = TAILQ_NEXT(elf, link)) in ta_elf_add_library()
1596 ta_elf_load_dependency(elf, ta->is_32bit); in ta_elf_add_library()
1598 for (elf = lib; elf; elf = TAILQ_NEXT(elf, link)) { in ta_elf_add_library()
1599 ta_elf_relocate(elf); in ta_elf_add_library()
1600 ta_elf_finalize_mappings(elf); in ta_elf_add_library()
1603 for (elf = lib; elf; elf = TAILQ_NEXT(elf, link)) in ta_elf_add_library()
1605 (void *)&elf->uuid, elf->load_addr); in ta_elf_add_library()
1615 static void get_init_fini_array(struct ta_elf *elf, unsigned int type, in get_init_fini_array() argument
1629 check_phdr_in_range(elf, type, addr, memsz); in get_init_fini_array()
1631 if (elf->is_32bit) { in get_init_fini_array()
1643 read_dyn(elf, addr, n, &tag, &val); in get_init_fini_array()
1645 *init = val + elf->load_addr; in get_init_fini_array()
1647 *fini = val + elf->load_addr; in get_init_fini_array()
1656 static void elf_get_init_fini_array(struct ta_elf *elf, vaddr_t *init, in elf_get_init_fini_array() argument
1662 if (elf->is_32bit) { in elf_get_init_fini_array()
1663 Elf32_Phdr *phdr = elf->phdr; in elf_get_init_fini_array()
1665 for (n = 0; n < elf->e_phnum; n++) { in elf_get_init_fini_array()
1667 get_init_fini_array(elf, phdr[n].p_type, in elf_get_init_fini_array()
1676 Elf64_Phdr *phdr = elf->phdr; in elf_get_init_fini_array()
1678 for (n = 0; n < elf->e_phnum; n++) { in elf_get_init_fini_array()
1680 get_init_fini_array(elf, phdr[n].p_type, in elf_get_init_fini_array()
1773 static void fill_ifs(vaddr_t va, size_t idx, struct ta_elf *elf, bool is_32bit) in fill_ifs() argument
1791 elf_get_init_fini_array(elf, &init, &init_cnt, &fini, in fill_ifs()
1808 elf_get_init_fini_array(elf, &init, &init_cnt, &fini, in fill_ifs()
1829 struct ta_elf *elf = NULL; in ta_elf_set_init_fini_info_compat() local
1850 TAILQ_FOREACH(elf, &main_elf_queue, link) in ta_elf_set_init_fini_info_compat()
1861 TAILQ_FOREACH(elf, &main_elf_queue, link) { in ta_elf_set_init_fini_info_compat()
1862 fill_ifs(info_va, cnt, elf, is_32bit); in ta_elf_set_init_fini_info_compat()
1909 static void fill_elf_phdr_info(vaddr_t va, size_t idx, struct ta_elf *elf, in fill_elf_phdr_info() argument
1921 dlpi32->dlpi_addr = elf->load_addr; in fill_elf_phdr_info()
1922 if (elf->soname) in fill_elf_phdr_info()
1923 dlpi32->dlpi_name = (vaddr_t)elf->soname; in fill_elf_phdr_info()
1926 dlpi32->dlpi_phdr = (vaddr_t)elf->phdr; in fill_elf_phdr_info()
1927 dlpi32->dlpi_phnum = elf->e_phnum; in fill_elf_phdr_info()
1930 dlpi32->dlpi_tls_modid = elf->tls_mod_id; in fill_elf_phdr_info()
1931 dlpi32->dlpi_tls_data = elf->tls_start; in fill_elf_phdr_info()
1936 dlpi->dlpi_addr = elf->load_addr; in fill_elf_phdr_info()
1937 if (elf->soname) in fill_elf_phdr_info()
1938 dlpi->dlpi_name = elf->soname; in fill_elf_phdr_info()
1941 dlpi->dlpi_phdr = elf->phdr; in fill_elf_phdr_info()
1942 dlpi->dlpi_phnum = elf->e_phnum; in fill_elf_phdr_info()
1945 dlpi->dlpi_tls_modid = elf->tls_mod_id; in fill_elf_phdr_info()
1946 dlpi->dlpi_tls_data = (void *)elf->tls_start; in fill_elf_phdr_info()
1955 struct ta_elf *elf = NULL; in ta_elf_set_elf_phdr_info() local
1973 TAILQ_FOREACH(elf, &main_elf_queue, link) in ta_elf_set_elf_phdr_info()
1981 TAILQ_FOREACH(elf, &main_elf_queue, link) { in ta_elf_set_elf_phdr_info()
1982 fill_elf_phdr_info(info_va, cnt, elf, is_32bit); in ta_elf_set_elf_phdr_info()