Lines Matching refs:dso
89 struct dso *target;
110 struct dso { struct
118 struct dso *next, *prev; argument
125 struct dso *cache_dso; argument
138 struct dso *syms_next, *lazy_next; argument
152 struct dso **deps, *needed_by; argument
164 struct dso *fini_next; argument
176 struct dso **parents; argument
181 struct dso **reloc_can_search_dso_list; argument
189 struct dso *dso; member
204 static struct dso ldso;
205 static struct dso *head, *tail, *fini_head, *syms_tail, *lazy_head;
221 static struct dso *builtin_deps[2];
222 static struct dso *const no_deps[1];
223 static struct dso *builtin_ctor_queue[4];
224 static struct dso **main_ctor_queue;
246 static int do_dlclose(struct dso *p);
254 static void preload_direct_deps(struct dso *p, ns_t *namespace, struct loadtasks *tasks);
256 static void preload_deps(struct dso *p, struct loadtasks *tasks);
258 static void assign_tls(struct dso *p);
265 static void handle_relro_sharing(struct dso *p, const dl_extinfo *extinfo, ssize_t *relro_fd_offset…
273 static void dlclose_ns(struct dso *p);
287 static void init_default_namespace(struct dso *app) in init_default_namespace()
371 static void init_namespace(struct dso *app) in init_namespace()
443 static void *laddr(const struct dso *p, size_t v) in laddr()
450 static void *laddr_pg(const struct dso *p, size_t v) in laddr_pg()
610 static Sym *sysv_lookup(struct verinfo *verinfo, struct sym_info_pair s_info_p, struct dso *dso) in sysv_lookup() argument
614 Sym *syms = dso->syms; in sysv_lookup()
615 Elf_Symndx *hashtab = dso->hashtab; in sysv_lookup()
616 char *strings = dso->strings; in sysv_lookup()
618 if ((!dso->versym || (dso->versym[i] & 0x7fff) >= 0) in sysv_lookup()
620 if (!check_verinfo(dso->verdef, dso->versym, i, verinfo, dso->strings)) { in sysv_lookup()
630 dso->name, verinfo->s, verinfo->v, verinfo->use_vna_hash, verinfo->vna_hash); in sysv_lookup()
634 static Sym *gnu_lookup(struct sym_info_pair s_info_p, uint32_t *hashtab, struct dso *dso, struct ve… in gnu_lookup() argument
642 …LD_LOGD("gnu_lookup symbol not found (bloom filter), so:%{public}s s:%{public}s", dso->name, verin… in gnu_lookup()
650 if ((h1 == (h2|1)) && (!dso->versym || (dso->versym[i] & 0x7fff) >= 0) in gnu_lookup()
651 && !memcmp(verinfo->s, dso->strings + dso->syms[i].st_name, s_info_p.sym_l)) { in gnu_lookup()
652 if (!check_verinfo(dso->verdef, dso->versym, i, verinfo, dso->strings)) { in gnu_lookup()
656 return dso->syms+i; in gnu_lookup()
664 dso->name, verinfo->s, verinfo->v, verinfo->use_vna_hash, verinfo->vna_hash); in gnu_lookup()
668 static bool check_sym_accessible(struct dso *dso, ns_t *ns) in check_sym_accessible() argument
670 if (!dso || !dso->namespace || !ns) { in check_sym_accessible()
674 if (dso->namespace == ns) { in check_sym_accessible()
677 for (int i = 0; i < dso->parents_count; i++) { in check_sym_accessible()
678 if (dso->parents[i]->namespace == ns) { in check_sym_accessible()
683 …"check_sym_accessible dso name [%{public}s] ns_name [%{public}s] not accessible!", dso->name, ns->… in check_sym_accessible()
687 static int find_dso_parent(struct dso *p, struct dso *target) in find_dso_parent()
699 static void add_dso_parent(struct dso *p, struct dso *parent) in add_dso_parent()
707 p->parents = (struct dso **)internal_malloc(sizeof(struct dso *) * PARENTS_BASE_CAPACITY); in add_dso_parent()
713 struct dso ** realloced = (struct dso **)internal_realloc( in add_dso_parent()
714 p->parents, sizeof(struct dso *) * (p->parents_capacity + PARENTS_BASE_CAPACITY)); in add_dso_parent()
726 static void remove_dso_parent(struct dso *p, struct dso *parent) in remove_dso_parent()
742 static void add_reloc_can_search_dso(struct dso *p, struct dso *can_search_so) in add_reloc_can_search_dso()
747 (struct dso **)internal_malloc(sizeof(struct dso *) * RELOC_CAN_SEARCH_DSO_BASE_CAPACITY); in add_reloc_can_search_dso()
753 struct dso ** realloced = (struct dso **)internal_realloc( in add_reloc_can_search_dso()
755 sizeof(struct dso *) * (p->reloc_can_search_dso_capacity + RELOC_CAN_SEARCH_DSO_BASE_CAPACITY)); in add_reloc_can_search_dso()
767 static void free_reloc_can_search_dso(struct dso *p) in free_reloc_can_search_dso()
796 static void add_can_search_so_list_in_dso(struct dso *dso_relocating, struct dso *start_check_dso) { in add_can_search_so_list_in_dso()
797 struct dso *p = start_check_dso; in add_can_search_so_list_in_dso()
832 static inline struct symdef find_sym2(struct dso *dso, struct verinfo *verinfo, int need_def, int u… in find_sym2() argument
838 struct dso **deps = use_deps ? dso->deps : 0; in find_sym2()
839 for (; dso; dso=use_deps ? *deps++ : dso->syms_next) { in find_sym2()
841 if (ns && !check_sym_accessible(dso, ns)) { in find_sym2()
844 if ((ght = dso->ghashtab)) { in find_sym2()
846 sym = gnu_lookup(s_info_p, ght, dso, verinfo); in find_sym2()
849 sym = sysv_lookup(verinfo, s_info_p, dso); in find_sym2()
863 def.dso = dso; in find_sym2()
870 int sym_type, struct dso *dso, struct verinfo *verinfo, int need_def, struct dso *dso_relocating) in find_sym_by_saved_so_list() argument
878 struct dso *dso_searching = 0; in find_sym_by_saved_so_list()
900 def.dso = dso_searching; in find_sym_by_saved_so_list()
906 static struct symdef find_sym(struct dso *dso, const char *s, int need_def) in find_sym() argument
909 return find_sym2(dso, &verinfo, need_def, 0, NULL); in find_sym()
912 static bool get_vna_hash(struct dso *dso, int sym_index, uint32_t *vna_hash) in get_vna_hash() argument
914 if (!dso->versym || !dso->verneed) { in get_vna_hash()
918 uint16_t vsym = dso->versym[sym_index]; in get_vna_hash()
924 Verneed *verneed = dso->verneed; in get_vna_hash()
954 static void do_relocs(struct dso *dso, size_t *rel, size_t rel_size, size_t stride) in do_relocs() argument
956 unsigned char *base = dso->base; in do_relocs()
957 Sym *syms = dso->syms; in do_relocs()
958 char *strings = dso->strings; in do_relocs()
971 if (dso == &ldso) { in do_relocs()
979 if (skip_relative && IS_RELATIVE(rel[1], dso->syms)) continue; in do_relocs()
982 reloc_addr = laddr(dso, rel[0]); in do_relocs()
1005 vinfo.use_vna_hash = get_vna_hash(dso, sym_index, &vinfo.vna_hash); in do_relocs()
1006 if (dso->cache_sym_index == sym_index) { in do_relocs()
1007 def = (struct symdef){ .dso = dso->cache_dso, .sym = dso->cache_sym }; in do_relocs()
1010 ? (struct symdef){ .dso = dso, .sym = sym } in do_relocs()
1011 : dso != &ldso ? find_sym_by_saved_so_list(type, ctx, &vinfo, type==REL_PLT, dso) in do_relocs()
1012 : find_sym2(ctx, &vinfo, type==REL_PLT, 0, dso->namespace); in do_relocs()
1013 dso->cache_sym_index = sym_index; in do_relocs()
1014 dso->cache_dso = def.dso; in do_relocs()
1015 dso->cache_sym = def.sym; in do_relocs()
1020 if (dso->lazy && (type==REL_PLT || type==REL_GOT)) { in do_relocs()
1021 dso->lazy[3*dso->lazy_cnt+0] = rel[0]; in do_relocs()
1022 dso->lazy[3*dso->lazy_cnt+1] = rel[1]; in do_relocs()
1023 dso->lazy[3*dso->lazy_cnt+2] = addend; in do_relocs()
1024 dso->lazy_cnt++; in do_relocs()
1029 dso->name, name, vinfo.use_vna_hash, vinfo.vna_hash); in do_relocs()
1031 dso->name, name); in do_relocs()
1038 def.dso = dso; in do_relocs()
1041 sym_val = def.sym ? (size_t)laddr(def.dso, def.sym->st_value) : 0; in do_relocs()
1045 && def.dso->tls_id > static_tls_cnt) { in do_relocs()
1048 dso->name, name, def.dso->name); in do_relocs()
1080 *reloc_addr = def.sym ? (size_t)(def.dso->funcdescs in do_relocs()
1081 + (def.sym - def.dso->syms)) : 0; in do_relocs()
1086 reloc_addr[1] = def.sym ? (size_t)def.dso->got : 0; in do_relocs()
1089 *reloc_addr = def.dso->tls_id; in do_relocs()
1096 *reloc_addr = tls_val + def.dso->tls.offset + TPOFF_K + addend; in do_relocs()
1100 *reloc_addr = tls_val - def.dso->tls.offset + addend; in do_relocs()
1103 *reloc_addr = def.dso->tls.offset - tls_val + addend; in do_relocs()
1108 if (def.dso->tls_id > static_tls_cnt) { in do_relocs()
1113 dso->name, sym ? name : "(local)" ); in do_relocs()
1116 new->next = dso->td_index; in do_relocs()
1117 dso->td_index = new; in do_relocs()
1118 new->args[0] = def.dso->tls_id; in do_relocs()
1125 reloc_addr[1] = tls_val + def.dso->tls.offset in do_relocs()
1128 reloc_addr[1] = tls_val - def.dso->tls.offset in do_relocs()
1142 dso->name, type); in do_relocs()
1151 struct dso *p = lazy_head, *next; in redo_lazy_relocs()
1174 static void reclaim(struct dso *dso, size_t start, size_t end) in reclaim() argument
1176 if (start >= dso->relro_start && start < dso->relro_end) start = dso->relro_end; in reclaim()
1177 if (end >= dso->relro_start && end < dso->relro_end) end = dso->relro_start; in reclaim()
1179 char *base = laddr_pg(dso, start); in reclaim()
1183 static void reclaim_gaps(struct dso *dso) in reclaim_gaps() argument
1185 Phdr *ph = dso->phdr; in reclaim_gaps()
1186 size_t phcnt = dso->phnum; in reclaim_gaps()
1188 for (; phcnt--; ph=(void *)((char *)ph+dso->phentsize)) { in reclaim_gaps()
1191 reclaim(dso, ph->p_vaddr & -PAGE_SIZE, ph->p_vaddr); in reclaim_gaps()
1192 reclaim(dso, ph->p_vaddr+ph->p_memsz, in reclaim_gaps()
1225 static void unmap_library(struct dso *dso) in unmap_library() argument
1227 if (dso->loadmap) { in unmap_library()
1229 for (i=0; i<dso->loadmap->nsegs; i++) { in unmap_library()
1230 if (!dso->loadmap->segs[i].p_memsz) in unmap_library()
1233 munmap((void *)dso->loadmap->segs[i].addr, in unmap_library()
1234 dso->loadmap->segs[i].p_memsz); in unmap_library()
1236 (void)mprotect((void *)dso->loadmap->segs[i].addr, in unmap_library()
1237 dso->loadmap->segs[i].p_memsz, PROT_NONE); in unmap_library()
1240 internal_free(dso->loadmap); in unmap_library()
1241 } else if (dso->map && dso->map_len) { in unmap_library()
1243 munmap(dso->map, dso->map_len); in unmap_library()
1245 mprotect(dso->map, dso->map_len, PROT_NONE); in unmap_library()
1287 static void *map_library(int fd, struct dso *dso, struct reserved_address_params *reserved_params) in map_library() argument
1332 dso->tls.align = ph->p_align; in map_library()
1333 dso->tls.len = ph->p_filesz; in map_library()
1334 dso->tls.size = ph->p_memsz; in map_library()
1336 dso->relro_start = ph->p_vaddr & -PAGE_SIZE; in map_library()
1337 dso->relro_end = (ph->p_vaddr + ph->p_memsz) & -PAGE_SIZE; in map_library()
1360 dso->loadmap = internal_calloc(1, sizeof *dso->loadmap in map_library()
1361 + nsegs * sizeof *dso->loadmap->segs); in map_library()
1362 if (!dso->loadmap) goto error; in map_library()
1363 dso->loadmap->nsegs = nsegs; in map_library()
1373 unmap_library(dso); in map_library()
1376 dso->loadmap->segs[i].addr = (size_t)map + in map_library()
1378 dso->loadmap->segs[i].p_vaddr = ph->p_vaddr; in map_library()
1379 dso->loadmap->segs[i].p_memsz = ph->p_memsz; in map_library()
1395 map = (void *)dso->loadmap->segs[0].addr; in map_library()
1429 dso->map = map; in map_library()
1430 dso->map_len = map_len; in map_library()
1438 dso->phdr = 0; in map_library()
1439 dso->phnum = 0; in map_library()
1448 if (!dso->phdr && eh->e_phoff >= ph->p_offset in map_library()
1450 dso->phdr = (void *)(base + ph->p_vaddr in map_library()
1452 dso->phnum = eh->e_phnum; in map_library()
1453 dso->phentsize = eh->e_phentsize; in map_library()
1481 dso->base = base; in map_library()
1482 dso->dynv = laddr(dso, dyn); in map_library()
1483 if (dso->tls.size) dso->tls.image = laddr(dso, tls_image); in map_library()
1489 if (map!=MAP_FAILED) unmap_library(dso); in map_library()
1520 static int fixup_rpath(struct dso *p, char *buf, size_t buf_size) in fixup_rpath()
1597 static void decode_dyn(struct dso *p) in decode_dyn()
1621 static size_t count_syms(struct dso *p) in count_syms()
1652 static void makefuncdescs(struct dso *p) in makefuncdescs()
1707 static struct dso *search_dso_by_name(const char *name, const ns_t *ns) { in search_dso_by_name()
1710 struct dso *p = ns->ns_dsos->dsos[i]; in search_dso_by_name()
1719 static struct dso *search_dso_by_fstat(const struct stat *st, const ns_t *ns, uint64_t file_offset)… in search_dso_by_fstat()
1722 struct dso *p = ns->ns_dsos->dsos[i]; in search_dso_by_fstat()
1732 static struct dso *find_library_by_name(const char *name, const ns_t *ns, bool check_inherited) in find_library_by_name()
1738 struct dso *p = search_dso_by_name(name, ns); in find_library_by_name()
1750 static struct dso *find_library_by_fstat(const struct stat *st, const ns_t *ns, bool check_inherite… in find_library_by_fstat()
1754 struct dso *p = search_dso_by_fstat(st, ns, file_offset); in find_library_by_fstat()
1768 struct dso *load_library( in load_library()
1769 …const char *name, struct dso *needed_by, ns_t *namespace, bool check_inherited, struct reserved_ad… in load_library()
1774 struct dso *p, temp_dso = {0}; in load_library()
1986 static void load_direct_deps(struct dso *p, ns_t *namespace, struct reserved_address_params *reserv… in load_direct_deps()
1993 if (p==head) for (struct dso *q=p->next; q; q=q->next) in load_direct_deps()
2006 if (p==head) for (struct dso *q=p->next; q; q=q->next) in load_direct_deps()
2010 struct dso *dep = load_library(p->strings + p->dynv[i+1], p, namespace, true, reserved_params); in load_direct_deps()
2027 static void load_deps(struct dso *p, struct reserved_address_params *reserved_params) in load_deps()
2035 static void extend_bfs_deps(struct dso *p) in extend_bfs_deps()
2038 struct dso **tmp; in extend_bfs_deps()
2058 struct dso *dep = p->deps[i]; in extend_bfs_deps()
2102 static void add_syms(struct dso *p) in add_syms()
2110 static void revert_syms(struct dso *old_tail) in revert_syms()
2112 struct dso *p, *next; in revert_syms()
2122 static void do_mips_relocs(struct dso *p, size_t *got) in do_mips_relocs()
2169 static void do_android_relocs(struct dso *p, size_t dt_name, size_t dt_size) in do_android_relocs()
2258 static void do_relr_relocs(struct dso *dso, size_t *relr, size_t relr_size) in do_relr_relocs() argument
2260 unsigned char *base = dso->base; in do_relr_relocs()
2264 reloc_addr = laddr(dso, relr[0]); in do_relr_relocs()
2275 static void reloc_all(struct dso *p, const dl_extinfo *extinfo) in reloc_all()
2312 static void kernel_mapped_dso(struct dso *p) in kernel_mapped_dso()
2344 struct dso *p; in __libc_exit_fini()
2372 static struct dso **queue_ctors(struct dso *dso) in queue_ctors() argument
2375 struct dso *p, **queue, **stack; in queue_ctors()
2383 if (dso->bfs_built) { in queue_ctors()
2384 for (cnt=0; dso->deps[cnt]; cnt++) in queue_ctors()
2385 dso->deps[cnt]->mark = 0; in queue_ctors()
2392 if (dso==head && cnt <= countof(builtin_ctor_queue)) in queue_ctors()
2409 stack[--spos] = dso; in queue_ctors()
2410 dso->next_dep = 0; in queue_ctors()
2411 dso->mark = 1; in queue_ctors()
2434 static void do_init_fini(struct dso **queue) in do_init_fini()
2436 struct dso *p; in do_init_fini()
2508 struct dso *dtv_provider = container_of(tls_tail, struct dso, tls); in install_new_tls()
2510 struct dso *p; in install_new_tls()
2656 static struct dso app, vdso; in __dls3()
2818 ldso.deps = (struct dso **)no_deps; in __dls3()
2838 for (struct dso *q=head; q; q=q->next) { in __dls3()
2849 for (struct dso *q=head; q; q=q->next) { in __dls3()
2856 for (struct dso *p=head; p; p=p->next) { in __dls3()
2877 vdso.deps = (struct dso **)no_deps; in __dls3()
2921 for (struct dso *q=head; q; q=q->next) { in __dls3()
2951 if (find_sym(head, "malloc", 1).dso != &ldso) in __dls3()
2977 static void prepare_lazy(struct dso *p) in prepare_lazy()
2999 static void *dlopen_post(struct dso* p, int mode) { in dlopen_post()
3032 struct dso *volatile p, *orig_tail, *orig_syms_tail, *orig_lazy_head, *next; in dlopen_impl()
3038 struct dso **volatile ctor_queue = 0; in dlopen_impl()
3040 struct dso *caller; in dlopen_impl()
3080 caller = (struct dso *)addr2dso((size_t)caller_addr); in dlopen_impl()
3221 struct dso *reloc_head_so = p;
3305 struct dso *caller; in dlns_get()
3307 caller = (struct dso *)addr2dso((size_t)caller_addr); in dlns_get()
3384 struct dso *caller; in dlns_create2()
3386 caller = (struct dso *)addr2dso((size_t)caller_addr); in dlns_create2()
3429 static void dlclose_ns(struct dso *p) in dlclose_ns()
3447 struct dso *p; in __dl_invalid_handle()
3455 struct dso *p; in addr2dso()
3486 static void *do_dlsym(struct dso *p, const char *s, const char *v, void *ra) in do_dlsym()
3491 struct dso *caller = NULL; in do_dlsym()
3509 caller = (struct dso *)addr2dso((size_t)ra); in do_dlsym()
3522 return __tls_get_addr((tls_mod_off_t []){def.dso->tls_id, def.sym->st_value-DTP_OFFSET}); in do_dlsym()
3524 return def.dso->funcdescs + (def.sym - def.dso->syms); in do_dlsym()
3525 return laddr(def.dso, def.sym->st_value); in do_dlsym()
3528 static int dlclose_impl(struct dso *p) in dlclose_impl()
3531 struct dso *d; in dlclose_impl()
3640 static int do_dlclose(struct dso *p) in do_dlclose()
3655 struct dso **deps_bak = internal_malloc(deps_num*sizeof(struct dso*)); in do_dlclose()
3657 memcpy(deps_bak, p->deps, deps_num*sizeof(struct dso*)); in do_dlclose()
3681 struct dso *dso = find_dso_by_handle(p); in __dlclose() local
3682 if (dso == NULL) { in __dlclose()
3690 rc = do_dlclose(dso); in __dlclose()
3692 struct dso *t = head; in __dlclose()
3693 for (; t && t != dso; t = t->next) { in __dlclose()
3711 struct dso *p; in dladdr()
3782 struct dso *dso = find_dso_by_handle(p); in __dlsym() local
3783 if (dso == NULL) { in __dlsym()
3787 res = do_dlsym(dso, s, "", ra); in __dlsym()
3805 struct dso *dso = find_dso_by_handle(p); in __dlvsym() local
3806 if (dso == NULL) { in __dlvsym()
3810 res = do_dlsym(dso, s, v, ra); in __dlvsym()
3850 struct dso *current; in dl_iterate_phdr()
4530 struct dso *needed_by = task->needed_by; in load_library_header()
4702 alloc_size = sizeof(struct dso) + strlen(task->pathname) + 1; in load_library_header()
4805 static void preload_direct_deps(struct dso *p, ns_t *namespace, struct loadtasks *tasks) in preload_direct_deps()
4814 for (struct dso *q = p->next; q; q = q->next) { in preload_direct_deps()
4836 for (struct dso *q = p->next; q; q = q->next) { in preload_direct_deps()
4909 static void preload_deps(struct dso *p, struct loadtasks *tasks) in preload_deps()
4934 static void assign_tls(struct dso *p) in assign_tls()
4994 static int serialize_gnu_relro(int fd, struct dso *dso, ssize_t *file_offset) in serialize_gnu_relro() argument
4996 ssize_t count = dso->relro_end - dso->relro_start; in serialize_gnu_relro()
4999 ssize_t write_size = TEMP_FAILURE_RETRY(write(fd, laddr(dso, dso->relro_start + offset), count)); in serialize_gnu_relro()
5001 LD_LOGE("Error serializing relro %{public}s: failed to write GNU_RELRO", dso->name); in serialize_gnu_relro()
5008 ssize_t size = dso->relro_end - dso->relro_start; in serialize_gnu_relro()
5010 laddr(dso, dso->relro_start), in serialize_gnu_relro()
5017 LD_LOGE("Error serializing relro %{public}s: failed to map GNU_RELRO", dso->name); in serialize_gnu_relro()
5024 static int map_gnu_relro(int fd, struct dso *dso, ssize_t *file_offset) in map_gnu_relro() argument
5029 LD_LOGE("Error mapping relro %{public}s: failed to get file state", dso->name); in map_gnu_relro()
5037 LD_LOGE("Error mapping relro %{public}s: failed to map fd", dso->name); in map_gnu_relro()
5042 char *mem_base = (char *)(laddr(dso, dso->relro_start)); in map_gnu_relro()
5044 ssize_t size = dso->relro_end - dso->relro_start; in map_gnu_relro()
5047 LD_LOGE("Error mapping relro %{public}s: invalid file size", dso->name); in map_gnu_relro()
5075 LD_LOGE("Error mapping relro %{public}s: failed to map GNU_RELRO", dso->name); in map_gnu_relro()
5088 static void handle_relro_sharing(struct dso *p, const dl_extinfo *extinfo, ssize_t *relro_fd_offset) in handle_relro_sharing()