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()
101 static TEE_Result e32_parse_ehdr(struct ta_elf *elf, Elf32_Ehdr *ehdr) in e32_parse_ehdr() argument
116 elf->is_32bit = true; in e32_parse_ehdr()
117 elf->e_entry = ehdr->e_entry; in e32_parse_ehdr()
118 elf->e_phoff = ehdr->e_phoff; in e32_parse_ehdr()
119 elf->e_shoff = ehdr->e_shoff; in e32_parse_ehdr()
120 elf->e_phnum = ehdr->e_phnum; in e32_parse_ehdr()
121 elf->e_shnum = ehdr->e_shnum; in e32_parse_ehdr()
122 elf->e_phentsize = ehdr->e_phentsize; in e32_parse_ehdr()
123 elf->e_shentsize = ehdr->e_shentsize; in e32_parse_ehdr()
129 static TEE_Result e64_parse_ehdr(struct ta_elf *elf, Elf64_Ehdr *ehdr) in e64_parse_ehdr() argument
141 elf->is_32bit = false; in e64_parse_ehdr()
142 elf->e_entry = ehdr->e_entry; in e64_parse_ehdr()
143 elf->e_phoff = ehdr->e_phoff; in e64_parse_ehdr()
144 elf->e_shoff = ehdr->e_shoff; in e64_parse_ehdr()
145 elf->e_phnum = ehdr->e_phnum; in e64_parse_ehdr()
146 elf->e_shnum = ehdr->e_shnum; in e64_parse_ehdr()
147 elf->e_phentsize = ehdr->e_phentsize; in e64_parse_ehdr()
148 elf->e_shentsize = ehdr->e_shentsize; in e64_parse_ehdr()
153 static TEE_Result e64_parse_ehdr(struct ta_elf *elf __unused, in e64_parse_ehdr()
160 static void check_phdr_in_range(struct ta_elf *elf, unsigned int type, in check_phdr_in_range() argument
173 if (max_addr > elf->max_addr - elf->load_addr) in check_phdr_in_range()
178 static void read_dyn(struct ta_elf *elf, vaddr_t addr, in read_dyn() argument
181 if (elf->is_32bit) { in read_dyn()
182 Elf32_Dyn *dyn = (Elf32_Dyn *)(addr + elf->load_addr); in read_dyn()
187 Elf64_Dyn *dyn = (Elf64_Dyn *)(addr + elf->load_addr); in read_dyn()
194 static void save_hashtab_from_segment(struct ta_elf *elf, unsigned int type, in save_hashtab_from_segment() argument
206 check_phdr_in_range(elf, type, addr, memsz); in save_hashtab_from_segment()
208 if (elf->is_32bit) in save_hashtab_from_segment()
217 read_dyn(elf, addr, n, &tag, &val); in save_hashtab_from_segment()
219 elf->hashtab = (void *)(val + elf->load_addr); in save_hashtab_from_segment()
225 static void check_range(struct ta_elf *elf, const char *name, const void *ptr, in check_range() argument
230 if ((vaddr_t)ptr < elf->load_addr) in check_range()
236 if (max_addr > elf->max_addr) in check_range()
241 static void check_hashtab(struct ta_elf *elf, void *ptr, size_t num_buckets, in check_hashtab() argument
262 check_range(elf, "DT_HASH", ptr, sz); in check_hashtab()
265 static void save_hashtab(struct ta_elf *elf) in save_hashtab() argument
270 if (elf->is_32bit) { in save_hashtab()
271 Elf32_Phdr *phdr = elf->phdr; in save_hashtab()
273 for (n = 0; n < elf->e_phnum; n++) in save_hashtab()
274 save_hashtab_from_segment(elf, phdr[n].p_type, in save_hashtab()
278 Elf64_Phdr *phdr = elf->phdr; in save_hashtab()
280 for (n = 0; n < elf->e_phnum; n++) in save_hashtab()
281 save_hashtab_from_segment(elf, phdr[n].p_type, in save_hashtab()
286 check_hashtab(elf, elf->hashtab, 0, 0); in save_hashtab()
287 hashtab = elf->hashtab; in save_hashtab()
288 check_hashtab(elf, elf->hashtab, hashtab[0], hashtab[1]); in save_hashtab()
291 static void save_soname_from_segment(struct ta_elf *elf, unsigned int type, in save_soname_from_segment() argument
304 if (elf->is_32bit) in save_soname_from_segment()
313 read_dyn(elf, addr, n, &tag, &val); in save_soname_from_segment()
315 str_tab = (char *)(val + elf->load_addr); in save_soname_from_segment()
320 read_dyn(elf, addr, n, &tag, &val); in save_soname_from_segment()
322 elf->soname = str_tab + val; in save_soname_from_segment()
328 static void save_soname(struct ta_elf *elf) in save_soname() argument
332 if (elf->is_32bit) { in save_soname()
333 Elf32_Phdr *phdr = elf->phdr; in save_soname()
335 for (n = 0; n < elf->e_phnum; n++) in save_soname()
336 save_soname_from_segment(elf, phdr[n].p_type, in save_soname()
340 Elf64_Phdr *phdr = elf->phdr; in save_soname()
342 for (n = 0; n < elf->e_phnum; n++) in save_soname()
343 save_soname_from_segment(elf, phdr[n].p_type, in save_soname()
349 static void e32_save_symtab(struct ta_elf *elf, size_t tab_idx) in e32_save_symtab() argument
351 Elf32_Shdr *shdr = elf->shdr; in e32_save_symtab()
354 elf->dynsymtab = (void *)(shdr[tab_idx].sh_addr + elf->load_addr); in e32_save_symtab()
355 if (!IS_ALIGNED_WITH_TYPE(elf->dynsymtab, Elf32_Sym)) in e32_save_symtab()
357 elf->dynsymtab); in e32_save_symtab()
358 check_range(elf, "Dynsymtab", elf->dynsymtab, shdr[tab_idx].sh_size); in e32_save_symtab()
363 elf->num_dynsyms = shdr[tab_idx].sh_size / sizeof(Elf32_Sym); in e32_save_symtab()
365 if (str_idx >= elf->e_shnum) in e32_save_symtab()
367 elf->dynstr = (void *)(shdr[str_idx].sh_addr + elf->load_addr); in e32_save_symtab()
368 check_range(elf, "Dynstr", elf->dynstr, shdr[str_idx].sh_size); in e32_save_symtab()
370 elf->dynstr_size = shdr[str_idx].sh_size; in e32_save_symtab()
373 static void e64_save_symtab(struct ta_elf *elf, size_t tab_idx) in e64_save_symtab() argument
375 Elf64_Shdr *shdr = elf->shdr; in e64_save_symtab()
378 elf->dynsymtab = (void *)(vaddr_t)(shdr[tab_idx].sh_addr + in e64_save_symtab()
379 elf->load_addr); in e64_save_symtab()
381 if (!IS_ALIGNED_WITH_TYPE(elf->dynsymtab, Elf64_Sym)) in e64_save_symtab()
383 elf->dynsymtab); in e64_save_symtab()
384 check_range(elf, ".dynsym/DYNSYM", elf->dynsymtab, in e64_save_symtab()
390 elf->num_dynsyms = shdr[tab_idx].sh_size / sizeof(Elf64_Sym); in e64_save_symtab()
392 if (str_idx >= elf->e_shnum) in e64_save_symtab()
395 elf->dynstr = (void *)(vaddr_t)(shdr[str_idx].sh_addr + elf->load_addr); in e64_save_symtab()
396 check_range(elf, ".dynstr/STRTAB", elf->dynstr, shdr[str_idx].sh_size); in e64_save_symtab()
398 elf->dynstr_size = shdr[str_idx].sh_size; in e64_save_symtab()
401 static void save_symtab(struct ta_elf *elf) in save_symtab() argument
405 if (elf->is_32bit) { in save_symtab()
406 Elf32_Shdr *shdr = elf->shdr; in save_symtab()
408 for (n = 0; n < elf->e_shnum; n++) { in save_symtab()
410 e32_save_symtab(elf, n); in save_symtab()
415 Elf64_Shdr *shdr = elf->shdr; in save_symtab()
417 for (n = 0; n < elf->e_shnum; n++) { in save_symtab()
419 e64_save_symtab(elf, n); in save_symtab()
426 save_hashtab(elf); in save_symtab()
427 save_soname(elf); in save_symtab()
430 static void init_elf(struct ta_elf *elf) in init_elf() argument
437 res = sys_open_ta_bin(&elf->uuid, &elf->handle); in init_elf()
439 err(res, "sys_open_ta_bin(%pUl)", (void *)&elf->uuid); in init_elf()
445 if (!elf->is_main) in init_elf()
447 res = sys_map_ta_bin(&va, SMALL_PAGE_SIZE, flags, elf->handle, 0, 0, 0); in init_elf()
450 elf->ehdr_addr = va; in init_elf()
451 if (!elf->is_main) { in init_elf()
452 elf->load_addr = va; in init_elf()
453 elf->max_addr = va + SMALL_PAGE_SIZE; in init_elf()
454 elf->max_offs = SMALL_PAGE_SIZE; in init_elf()
460 res = e32_parse_ehdr(elf, (void *)va); in init_elf()
462 res = e64_parse_ehdr(elf, (void *)va); in init_elf()
466 if (MUL_OVERFLOW(elf->e_phnum, elf->e_phentsize, &sz) || in init_elf()
467 ADD_OVERFLOW(sz, elf->e_phoff, &sz)) in init_elf()
473 elf->phdr = (void *)(va + elf->e_phoff); in init_elf()
486 static void add_segment(struct ta_elf *elf, size_t offset, size_t vaddr, in add_segment() argument
504 TAILQ_INSERT_TAIL(&elf->segs, seg, link); in add_segment()
507 static void parse_load_segments(struct ta_elf *elf) in parse_load_segments() argument
511 if (elf->is_32bit) { in parse_load_segments()
512 Elf32_Phdr *phdr = elf->phdr; in parse_load_segments()
514 for (n = 0; n < elf->e_phnum; n++) in parse_load_segments()
516 add_segment(elf, phdr[n].p_offset, in parse_load_segments()
521 elf->exidx_start = phdr[n].p_vaddr; in parse_load_segments()
522 elf->exidx_size = phdr[n].p_filesz; in parse_load_segments()
524 assign_tls_mod_id(elf); in parse_load_segments()
527 Elf64_Phdr *phdr = elf->phdr; in parse_load_segments()
529 for (n = 0; n < elf->e_phnum; n++) in parse_load_segments()
531 add_segment(elf, phdr[n].p_offset, in parse_load_segments()
536 elf->tls_start = phdr[n].p_vaddr; in parse_load_segments()
537 elf->tls_filesz = phdr[n].p_filesz; in parse_load_segments()
538 elf->tls_memsz = phdr[n].p_memsz; in parse_load_segments()
541 elf->prop_start = phdr[n].p_vaddr; in parse_load_segments()
542 elf->prop_align = phdr[n].p_align; in parse_load_segments()
543 elf->prop_memsz = phdr[n].p_memsz; in parse_load_segments()
548 static void copy_remapped_to(struct ta_elf *elf, const struct segment *seg) in copy_remapped_to() argument
550 uint8_t *dst = (void *)(seg->vaddr + elf->load_addr); in copy_remapped_to()
555 if (offs < elf->max_offs) { in copy_remapped_to()
556 n = MIN(elf->max_offs - offs, num_bytes); in copy_remapped_to()
557 memcpy(dst, (void *)(elf->max_addr + offs - elf->max_offs), n); in copy_remapped_to()
565 elf->handle, offs); in copy_remapped_to()
569 elf->max_offs += offs; in copy_remapped_to()
573 static void adjust_segments(struct ta_elf *elf) in adjust_segments() argument
582 TAILQ_FOREACH(seg, &elf->segs, link) { in adjust_segments()
604 seg = TAILQ_FIRST(&elf->segs); in adjust_segments()
641 TAILQ_REMOVE(&elf->segs, seg, link); in adjust_segments()
669 static void populate_segments_legacy(struct ta_elf *elf) in populate_segments_legacy() argument
675 assert(elf->is_legacy); in populate_segments_legacy()
676 TAILQ_FOREACH(seg, &elf->segs, link) { in populate_segments_legacy()
677 struct segment *last_seg = TAILQ_LAST(&elf->segs, segment_head); in populate_segments_legacy()
682 if (!elf->load_addr) in populate_segments_legacy()
685 va = seg->vaddr + elf->load_addr; in populate_segments_legacy()
696 elf->handle, seg->offset); in populate_segments_legacy()
700 if (!elf->load_addr) in populate_segments_legacy()
701 elf->load_addr = va; in populate_segments_legacy()
702 elf->max_addr = va + num_bytes; in populate_segments_legacy()
703 elf->max_offs = seg->offset + seg->filesz; in populate_segments_legacy()
733 static void populate_segments(struct ta_elf *elf) in populate_segments() argument
740 assert(!elf->is_legacy); in populate_segments()
741 TAILQ_FOREACH(seg, &elf->segs, link) { in populate_segments()
742 struct segment *last_seg = TAILQ_LAST(&elf->segs, segment_head); in populate_segments()
750 assert(elf->load_addr); in populate_segments()
751 va = rounddown(elf->load_addr + seg->vaddr); in populate_segments()
752 assert(va >= elf->max_addr); in populate_segments()
757 copy_remapped_to(elf, seg); in populate_segments()
758 elf->max_addr = va + num_bytes; in populate_segments()
766 if (offset < elf->max_offs) { in populate_segments()
787 va = elf->max_addr; in populate_segments()
796 elf->max_addr = roundup(va + num_bytes); in populate_segments()
807 if (!elf->load_addr) { in populate_segments()
816 va = vaddr + elf->load_addr; in populate_segments()
838 elf->handle, offset); in populate_segments()
846 elf->handle, offset, in populate_segments()
850 elf->handle, in populate_segments()
857 if (!elf->load_addr) in populate_segments()
858 elf->load_addr = va; in populate_segments()
859 elf->max_addr = roundup(va + memsz); in populate_segments()
860 elf->max_offs += filesz; in populate_segments()
865 static void ta_elf_add_bti(struct ta_elf *elf) in ta_elf_add_bti() argument
871 TAILQ_FOREACH(seg, &elf->segs, link) { in ta_elf_add_bti()
872 vaddr_t va = elf->load_addr + seg->vaddr; in ta_elf_add_bti()
882 static void parse_property_segment(struct ta_elf *elf) in parse_property_segment() argument
885 size_t align = elf->prop_align; in parse_property_segment()
892 if (!IS_ENABLED(CFG_TA_BTI) || !elf->prop_start) in parse_property_segment()
895 check_phdr_in_range(elf, PT_GNU_PROPERTY, elf->prop_start, in parse_property_segment()
896 elf->prop_memsz); in parse_property_segment()
898 va = elf->load_addr + elf->prop_start; in parse_property_segment()
902 if (elf->prop_memsz < sizeof(*note) + sizeof(ELF_NOTE_GNU)) in parse_property_segment()
913 if (desc_offset > elf->prop_memsz || in parse_property_segment()
914 ROUNDUP(desc_offset + note->n_descsz, align) > elf->prop_memsz) in parse_property_segment()
937 elf->bti_enabled = true; in parse_property_segment()
945 static void map_segments(struct ta_elf *elf) in map_segments() argument
949 parse_load_segments(elf); in map_segments()
950 adjust_segments(elf); in map_segments()
951 if (TAILQ_FIRST(&elf->segs)->offset < SMALL_PAGE_SIZE) { in map_segments()
953 size_t sz = elf->max_addr - elf->load_addr; in map_segments()
954 struct segment *seg = TAILQ_LAST(&elf->segs, segment_head); in map_segments()
961 assert(!elf->is_main); in map_segments()
968 res = sys_remap(elf->load_addr, &va, sz, pad_begin, in map_segments()
971 res = sys_remap(elf->load_addr, &va, sz, 0, in map_segments()
975 elf->ehdr_addr = va; in map_segments()
976 elf->load_addr = va; in map_segments()
977 elf->max_addr = va + sz; in map_segments()
978 elf->phdr = (void *)(va + elf->e_phoff); in map_segments()
982 static void add_deps_from_segment(struct ta_elf *elf, unsigned int type, in add_deps_from_segment() argument
997 check_phdr_in_range(elf, type, addr, memsz); in add_deps_from_segment()
999 if (elf->is_32bit) in add_deps_from_segment()
1008 read_dyn(elf, addr, n, &tag, &val); in add_deps_from_segment()
1010 str_tab = (char *)(val + elf->load_addr); in add_deps_from_segment()
1014 check_range(elf, ".dynstr/STRTAB", str_tab, str_tab_sz); in add_deps_from_segment()
1017 read_dyn(elf, addr, n, &tag, &val); in add_deps_from_segment()
1028 static void add_dependencies(struct ta_elf *elf) in add_dependencies() argument
1032 if (elf->is_32bit) { in add_dependencies()
1033 Elf32_Phdr *phdr = elf->phdr; in add_dependencies()
1035 for (n = 0; n < elf->e_phnum; n++) in add_dependencies()
1036 add_deps_from_segment(elf, phdr[n].p_type, in add_dependencies()
1039 Elf64_Phdr *phdr = elf->phdr; in add_dependencies()
1041 for (n = 0; n < elf->e_phnum; n++) in add_dependencies()
1042 add_deps_from_segment(elf, phdr[n].p_type, in add_dependencies()
1047 static void copy_section_headers(struct ta_elf *elf) in copy_section_headers() argument
1053 if (MUL_OVERFLOW(elf->e_shnum, elf->e_shentsize, &sz)) in copy_section_headers()
1056 elf->shdr = malloc(sz); in copy_section_headers()
1057 if (!elf->shdr) in copy_section_headers()
1065 if (elf->e_shoff < SMALL_PAGE_SIZE) { in copy_section_headers()
1066 assert(!elf->is_main); in copy_section_headers()
1067 offs = MIN(SMALL_PAGE_SIZE - elf->e_shoff, sz); in copy_section_headers()
1068 memcpy(elf->shdr, (void *)(elf->load_addr + elf->e_shoff), in copy_section_headers()
1073 res = sys_copy_from_ta_bin((uint8_t *)elf->shdr + offs, in copy_section_headers()
1074 sz - offs, elf->handle, in copy_section_headers()
1075 elf->e_shoff + offs); in copy_section_headers()
1081 static void close_handle(struct ta_elf *elf) in close_handle() argument
1083 TEE_Result res = sys_close_ta_bin(elf->handle); in close_handle()
1087 elf->handle = -1; in close_handle()
1090 static void clean_elf_load_main(struct ta_elf *elf) in clean_elf_load_main() argument
1097 res = sys_unmap(elf->ehdr_addr, SMALL_PAGE_SIZE); in clean_elf_load_main()
1101 while (!TAILQ_EMPTY(&elf->segs)) { in clean_elf_load_main()
1102 struct segment *seg = TAILQ_FIRST(&elf->segs); in clean_elf_load_main()
1106 va = rounddown(elf->load_addr + seg->vaddr); in clean_elf_load_main()
1117 TAILQ_REMOVE(&elf->segs, seg, link); in clean_elf_load_main()
1121 free(elf->shdr); in clean_elf_load_main()
1122 memset(&elf->is_32bit, 0, in clean_elf_load_main()
1123 (vaddr_t)&elf->uuid - (vaddr_t)&elf->is_32bit); in clean_elf_load_main()
1125 TAILQ_INIT(&elf->segs); in clean_elf_load_main()
1134 static void set_tls_offset(struct ta_elf *elf) in set_tls_offset() argument
1138 if (!elf->tls_start) in set_tls_offset()
1142 elf->tls_tcb_offs = next_offs; in set_tls_offset()
1143 next_offs += elf->tls_memsz; in set_tls_offset()
1146 static void set_tls_offset(struct ta_elf *elf __unused) {} in set_tls_offset()
1149 static void load_main(struct ta_elf *elf) in load_main() argument
1151 init_elf(elf); in load_main()
1152 map_segments(elf); in load_main()
1153 populate_segments(elf); in load_main()
1154 add_dependencies(elf); in load_main()
1155 copy_section_headers(elf); in load_main()
1156 save_symtab(elf); in load_main()
1157 close_handle(elf); in load_main()
1158 set_tls_offset(elf); in load_main()
1159 parse_property_segment(elf); in load_main()
1160 if (elf->bti_enabled) in load_main()
1161 ta_elf_add_bti(elf); in load_main()
1163 elf->head = (struct ta_head *)elf->load_addr; in load_main()
1164 if (elf->head->depr_entry != UINT64_MAX) { in load_main()
1180 DMSG("Reloading TA %pUl as legacy TA", (void *)&elf->uuid); in load_main()
1181 clean_elf_load_main(elf); in load_main()
1182 elf->is_legacy = true; in load_main()
1183 init_elf(elf); in load_main()
1184 map_segments(elf); in load_main()
1185 populate_segments_legacy(elf); in load_main()
1186 add_dependencies(elf); in load_main()
1187 copy_section_headers(elf); in load_main()
1188 save_symtab(elf); in load_main()
1189 close_handle(elf); in load_main()
1190 elf->head = (struct ta_head *)elf->load_addr; in load_main()
1195 if (elf->head->depr_entry == UINT64_MAX) in load_main()
1198 (void *)&elf->uuid); in load_main()
1206 struct ta_elf *elf = queue_elf(uuid); in ta_elf_load_main() local
1210 assert(elf); in ta_elf_load_main()
1211 elf->is_main = true; in ta_elf_load_main()
1213 load_main(elf); in ta_elf_load_main()
1215 *is_32bit = elf->is_32bit; in ta_elf_load_main()
1216 res = sys_map_zi(elf->head->stack_size, 0, &va, 0, 0); in ta_elf_load_main()
1220 if (elf->head->flags & ~TA_FLAGS_MASK) in ta_elf_load_main()
1222 elf->head->flags & ~TA_FLAGS_MASK); in ta_elf_load_main()
1224 *ta_flags = elf->head->flags; in ta_elf_load_main()
1225 *sp = va + elf->head->stack_size; in ta_elf_load_main()
1227 ta_stack_size = elf->head->stack_size; in ta_elf_load_main()
1232 struct ta_elf *elf = TAILQ_FIRST(&main_elf_queue); in ta_elf_finalize_load_main() local
1235 assert(elf->is_main); in ta_elf_finalize_load_main()
1237 res = ta_elf_set_init_fini_info_compat(elf->is_32bit); in ta_elf_finalize_load_main()
1240 res = ta_elf_set_elf_phdr_info(elf->is_32bit); in ta_elf_finalize_load_main()
1244 if (elf->is_legacy) in ta_elf_finalize_load_main()
1245 *entry = elf->head->depr_entry; in ta_elf_finalize_load_main()
1247 *entry = elf->e_entry + elf->load_addr; in ta_elf_finalize_load_main()
1251 void ta_elf_load_dependency(struct ta_elf *elf, bool is_32bit) in ta_elf_load_dependency() argument
1253 if (elf->is_main) in ta_elf_load_dependency()
1256 init_elf(elf); in ta_elf_load_dependency()
1257 if (elf->is_32bit != is_32bit) in ta_elf_load_dependency()
1259 (void *)&elf->uuid, elf->is_32bit ? "32" : "64", in ta_elf_load_dependency()
1262 map_segments(elf); in ta_elf_load_dependency()
1263 populate_segments(elf); in ta_elf_load_dependency()
1264 add_dependencies(elf); in ta_elf_load_dependency()
1265 copy_section_headers(elf); in ta_elf_load_dependency()
1266 save_symtab(elf); in ta_elf_load_dependency()
1267 close_handle(elf); in ta_elf_load_dependency()
1268 set_tls_offset(elf); in ta_elf_load_dependency()
1269 parse_property_segment(elf); in ta_elf_load_dependency()
1270 if (elf->bti_enabled) in ta_elf_load_dependency()
1271 ta_elf_add_bti(elf); in ta_elf_load_dependency()
1274 void ta_elf_finalize_mappings(struct ta_elf *elf) in ta_elf_finalize_mappings() argument
1279 if (!elf->is_legacy) in ta_elf_finalize_mappings()
1282 TAILQ_FOREACH(seg, &elf->segs, link) { in ta_elf_finalize_mappings()
1283 vaddr_t va = elf->load_addr + seg->vaddr; in ta_elf_finalize_mappings()
1350 struct ta_elf **elf, struct segment **seg, in get_next_in_order() argument
1360 assert(elf && seg && elf_idx); in get_next_in_order()
1361 e = *elf; in get_next_in_order()
1390 *elf = e; in get_next_in_order()
1401 struct ta_elf *elf = NULL; in ta_elf_print_mappings() local
1411 get_next_in_order(elf_queue, &elf, &seg, &elf_idx); in ta_elf_print_mappings()
1419 va = rounddown(seg->vaddr + elf->load_addr); in ta_elf_print_mappings()
1478 if (!get_next_in_order(elf_queue, &elf, &seg, &elf_idx)) in ta_elf_print_mappings()
1483 TAILQ_FOREACH(elf, elf_queue, link) { in ta_elf_print_mappings()
1486 elf_idx, (void *)&elf->uuid, 8, elf->load_addr); in ta_elf_print_mappings()
1496 struct ta_elf *elf = NULL; in find_exidx() local
1499 TAILQ_FOREACH(elf, &main_elf_queue, link) { in find_exidx()
1500 if (addr < elf->load_addr) in find_exidx()
1502 a = addr - elf->load_addr; in find_exidx()
1503 TAILQ_FOREACH(seg, &elf->segs, link) { in find_exidx()
1507 *idx_start = elf->exidx_start + elf->load_addr; in find_exidx()
1508 *idx_end = elf->exidx_start + elf->load_addr + in find_exidx()
1509 elf->exidx_size; in find_exidx()
1539 struct ta_elf *elf = NULL; in ta_elf_add_library() local
1548 for (elf = lib; elf; elf = TAILQ_NEXT(elf, link)) in ta_elf_add_library()
1549 ta_elf_load_dependency(elf, ta->is_32bit); in ta_elf_add_library()
1551 for (elf = lib; elf; elf = TAILQ_NEXT(elf, link)) { in ta_elf_add_library()
1552 ta_elf_relocate(elf); in ta_elf_add_library()
1553 ta_elf_finalize_mappings(elf); in ta_elf_add_library()
1556 for (elf = lib; elf; elf = TAILQ_NEXT(elf, link)) in ta_elf_add_library()
1558 (void *)&elf->uuid, elf->load_addr); in ta_elf_add_library()
1568 static void get_init_fini_array(struct ta_elf *elf, unsigned int type, in get_init_fini_array() argument
1582 check_phdr_in_range(elf, type, addr, memsz); in get_init_fini_array()
1584 if (elf->is_32bit) { in get_init_fini_array()
1596 read_dyn(elf, addr, n, &tag, &val); in get_init_fini_array()
1598 *init = val + elf->load_addr; in get_init_fini_array()
1600 *fini = val + elf->load_addr; in get_init_fini_array()
1609 static void elf_get_init_fini_array(struct ta_elf *elf, vaddr_t *init, in elf_get_init_fini_array() argument
1615 if (elf->is_32bit) { in elf_get_init_fini_array()
1616 Elf32_Phdr *phdr = elf->phdr; in elf_get_init_fini_array()
1618 for (n = 0; n < elf->e_phnum; n++) { in elf_get_init_fini_array()
1620 get_init_fini_array(elf, phdr[n].p_type, in elf_get_init_fini_array()
1629 Elf64_Phdr *phdr = elf->phdr; in elf_get_init_fini_array()
1631 for (n = 0; n < elf->e_phnum; n++) { in elf_get_init_fini_array()
1633 get_init_fini_array(elf, phdr[n].p_type, in elf_get_init_fini_array()
1726 static void fill_ifs(vaddr_t va, size_t idx, struct ta_elf *elf, bool is_32bit) in fill_ifs() argument
1744 elf_get_init_fini_array(elf, &init, &init_cnt, &fini, in fill_ifs()
1761 elf_get_init_fini_array(elf, &init, &init_cnt, &fini, in fill_ifs()
1782 struct ta_elf *elf = NULL; in ta_elf_set_init_fini_info_compat() local
1803 TAILQ_FOREACH(elf, &main_elf_queue, link) in ta_elf_set_init_fini_info_compat()
1814 TAILQ_FOREACH(elf, &main_elf_queue, link) { in ta_elf_set_init_fini_info_compat()
1815 fill_ifs(info_va, cnt, elf, is_32bit); in ta_elf_set_init_fini_info_compat()
1862 static void fill_elf_phdr_info(vaddr_t va, size_t idx, struct ta_elf *elf, in fill_elf_phdr_info() argument
1874 dlpi32->dlpi_addr = elf->load_addr; in fill_elf_phdr_info()
1875 if (elf->soname) in fill_elf_phdr_info()
1876 dlpi32->dlpi_name = (vaddr_t)elf->soname; in fill_elf_phdr_info()
1879 dlpi32->dlpi_phdr = (vaddr_t)elf->phdr; in fill_elf_phdr_info()
1880 dlpi32->dlpi_phnum = elf->e_phnum; in fill_elf_phdr_info()
1883 dlpi32->dlpi_tls_modid = elf->tls_mod_id; in fill_elf_phdr_info()
1884 dlpi32->dlpi_tls_data = elf->tls_start; in fill_elf_phdr_info()
1889 dlpi->dlpi_addr = elf->load_addr; in fill_elf_phdr_info()
1890 if (elf->soname) in fill_elf_phdr_info()
1891 dlpi->dlpi_name = elf->soname; in fill_elf_phdr_info()
1894 dlpi->dlpi_phdr = elf->phdr; in fill_elf_phdr_info()
1895 dlpi->dlpi_phnum = elf->e_phnum; in fill_elf_phdr_info()
1898 dlpi->dlpi_tls_modid = elf->tls_mod_id; in fill_elf_phdr_info()
1899 dlpi->dlpi_tls_data = (void *)elf->tls_start; in fill_elf_phdr_info()
1908 struct ta_elf *elf = NULL; in ta_elf_set_elf_phdr_info() local
1926 TAILQ_FOREACH(elf, &main_elf_queue, link) in ta_elf_set_elf_phdr_info()
1934 TAILQ_FOREACH(elf, &main_elf_queue, link) { in ta_elf_set_elf_phdr_info()
1935 fill_elf_phdr_info(info_va, cnt, elf, is_32bit); in ta_elf_set_elf_phdr_info()