diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2006-05-10 03:26:51 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2006-05-10 03:26:51 +0000 |
commit | cf97ee05053b2ae65d1e6e63ec2e13c62fcca5d2 (patch) | |
tree | 05d3c5fdb0726887a76e0dc95b073fc8bdcb08d1 /libexec/ld.so | |
parent | b32f8986c8d688b879c13a31e66a7debe5502d64 (diff) |
pretty this up; ok drahn
Diffstat (limited to 'libexec/ld.so')
-rw-r--r-- | libexec/ld.so/dl_prebind.c | 155 | ||||
-rw-r--r-- | libexec/ld.so/dl_prebind.h | 20 | ||||
-rw-r--r-- | libexec/ld.so/library_mquery.c | 11 |
3 files changed, 82 insertions, 104 deletions
diff --git a/libexec/ld.so/dl_prebind.c b/libexec/ld.so/dl_prebind.c index 888fd59d220..be27aee4521 100644 --- a/libexec/ld.so/dl_prebind.c +++ b/libexec/ld.so/dl_prebind.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dl_prebind.c,v 1.6 2006/05/08 20:37:01 deraadt Exp $ */ +/* $OpenBSD: dl_prebind.c,v 1.7 2006/05/10 03:26:50 deraadt Exp $ */ /* * Copyright (c) 2006 Dale Rahn <drahn@dalerahn.com> * @@ -55,17 +55,15 @@ char *prebind_bind_now = "prebind"; struct prebind_footer * _dl_prebind_data_to_footer(void *prebind_data) { - u_int32_t *poffset; - u_int32_t offset; - char *c; + u_int32_t *poffset, offset; struct prebind_footer *footer; + char *c; poffset = prebind_data; c = prebind_data; offset = *poffset; c += offset; footer = (void *)c; - return footer; } @@ -110,11 +108,11 @@ void * prebind_load_fd(int fd, const char *name) { struct prebind_footer footer; - void *prebind_data; struct nameidx *nameidx; + void *prebind_data; char *nametab; - int idx; ssize_t len; + int idx; if (_dl_prog_prebind_map == NULL || _dl_prebind_match_failed) return 0; @@ -122,7 +120,7 @@ prebind_load_fd(int fd, const char *name) _dl_lseek(fd, -(off_t)sizeof(struct prebind_footer), SEEK_END); len = _dl_read(fd, (void *)&footer, sizeof(struct prebind_footer)); - if (len != sizeof(struct prebind_footer) || + if (len != sizeof(struct prebind_footer) || footer.bind_id[0] != BIND_ID0 || footer.bind_id[1] != BIND_ID1 || footer.bind_id[2] != BIND_ID2 || @@ -144,18 +142,18 @@ prebind_load_fd(int fd, const char *name) * to look thru the list to find ourselves */ for (idx = 0; idx < prog_footer->numlibs; idx++) { - if (_dl_strcmp( nametab + nameidx[idx].name, name) == 0) + if (_dl_strcmp(nametab + nameidx[idx].name, name) == 0) break; } if (idx == prog_footer->numlibs) { _dl_prebind_match_failed = 1; /* not found */ } else if (footer.id0 != nameidx[idx].id0 || - footer.id1 != nameidx[idx].id1) { + footer.id1 != nameidx[idx].id1) { _dl_prebind_match_failed = 1; DL_DEB(("prebind match id0 %d pid0 %d id1 %d pid1 %d\n", - footer.id0, nameidx[idx].id0, - footer.id1, nameidx[idx].id1)); + footer.id0, nameidx[idx].id0, + footer.id1, nameidx[idx].id1)); } if (_dl_prebind_match_failed == 1) { @@ -171,24 +169,16 @@ elf_object_t **objarray; void prebind_symcache(elf_object_t *object, int plt) { - void *prebind_map; + u_int32_t *fixupidx, *fixupcnt, *libmap, *idxtolib; + u_int32_t *poffset, offset, symcache_cnt; struct symcachetab *symcachetab; + struct prebind_footer *footer; + int i = 0, cur_obj = -1, idx; + void *prebind_map; struct nameidx *nameidx; - u_int32_t *fixupidx; - char *nametab; + char *nametab, *c; struct fixup *fixup; - u_int32_t *fixupcnt; - u_int32_t *libmap; - u_int32_t *idxtolib; elf_object_t *obj; - struct prebind_footer *footer; - char *c; - int i = 0; - int cur_obj = -1; - int idx; - u_int32_t *poffset; - u_int32_t offset; - u_int32_t symcache_cnt; struct symcachetab *s; @@ -223,7 +213,6 @@ prebind_symcache(elf_object_t *object, int plt) } } - poffset = (u_int32_t *)object->prebind_data; c = object->prebind_data; offset = *poffset; @@ -244,7 +233,7 @@ prebind_symcache(elf_object_t *object, int plt) nametab = prebind_map + footer->nametab_idx; libmap = _dl_prog_prebind_map + prog_footer->libmap_idx; - idxtolib = _dl_prog_prebind_map + libmap[cur_obj]; + idxtolib = _dl_prog_prebind_map + libmap[cur_obj]; for (i = 0; i < symcache_cnt; i++) { struct elf_object *tobj; @@ -257,25 +246,22 @@ prebind_symcache(elf_object_t *object, int plt) else idx = idxtolib[s->obj_idx]; - if (idx == -1) /* somehow an invalid object ref happend */ + if (idx == -1) /* somehow an invalid object ref happend */ continue; #if 0 DL_DEB(("%s:", object->load_name)); DL_DEB(("symidx %d: obj %d %d sym %d flags %x\n", - s->idx, s->obj_idx, idx, - s->sym_idx, - SYM_SEARCH_ALL|SYM_WARNNOTFOUND|plt)); + s->idx, s->obj_idx, idx, s->sym_idx, + SYM_SEARCH_ALL|SYM_WARNNOTFOUND|plt)); #endif - tobj = objarray[idx]; + tobj = objarray[idx]; sym = tobj->dyn.symtab + s->sym_idx; str = tobj->dyn.strtab + sym->st_name; #ifdef DEBUG2 DL_DEB(("symidx %d: obj %d %s sym %d %s flags %d %x\n", - s->idx, s->obj_idx, tobj->load_name, - s->sym_idx, str, - SYM_SEARCH_ALL|SYM_WARNNOTFOUND|plt, - object->load_addr + sym->st_value - )); + s->idx, s->obj_idx, tobj->load_name, + s->sym_idx, str, SYM_SEARCH_ALL|SYM_WARNNOTFOUND|plt, + object->load_addr + sym->st_value)); #endif _dl_symcache[s->idx].obj = tobj; _dl_symcache[s->idx].sym = sym; @@ -297,19 +283,16 @@ prebind_symcache(elf_object_t *object, int plt) f = &(fixup[i]); #if 0 DL_DEB(("symidx %d: obj %d sym %d flags %x\n", - f->sym, f->targobj_idx, - f->sym_idx, f->flags)); + f->sym, f->targobj_idx, f->sym_idx, f->flags)); #endif - tobj = objarray[f->targobj_idx]; + tobj = objarray[f->targobj_idx]; sym = tobj->dyn.symtab + f->sym_idx; str = tobj->dyn.strtab + sym->st_name; #ifdef DEBUG2 DL_DEB(("symidx %d: obj %d %s sym %d %s flags %d %x\n", - f->sym, f->targobj_idx, tobj->load_name, - f->sym_idx, str, - SYM_SEARCH_ALL|SYM_WARNNOTFOUND|plt, - object->load_addr + sym->st_value - )); + f->sym, f->targobj_idx, tobj->load_name, + f->sym_idx, str, SYM_SEARCH_ALL|SYM_WARNNOTFOUND|plt, + object->load_addr + sym->st_value)); #endif _dl_symcache[f->sym].obj = tobj; _dl_symcache[f->sym].sym = sym; @@ -335,20 +318,17 @@ prebind_symcache(elf_object_t *object, int plt) f = &(fixup[i]); #if 0 DL_DEB(("symidx %d: obj %d sym %d flags %x\n", - f->sym, f->targobj_idx, - f->sym_idx, - SYM_SEARCH_ALL|SYM_WARNNOTFOUND|plt)); + f->sym, f->targobj_idx, f->sym_idx, + SYM_SEARCH_ALL|SYM_WARNNOTFOUND|plt)); #endif - tobj = objarray[f->targobj_idx]; + tobj = objarray[f->targobj_idx]; sym = tobj->dyn.symtab + f->sym_idx; str = tobj->dyn.strtab + sym->st_name; #ifdef DEBUG2 DL_DEB(("symidx %d: obj %d %s sym %d %s flags %d %x\n", - f->sym, f->targobj_idx, tobj->load_name, - f->sym_idx, str, - SYM_SEARCH_ALL|SYM_WARNNOTFOUND|plt, - object->load_addr + sym->st_value - )); + f->sym, f->targobj_idx, tobj->load_name, + f->sym_idx, str, SYM_SEARCH_ALL|SYM_WARNNOTFOUND|plt, + object->load_addr + sym->st_value)); #endif _dl_symcache[f->sym].obj = tobj; _dl_symcache[f->sym].sym = sym; @@ -367,7 +347,7 @@ prebind_free(elf_object_t *object) if (object->prebind_data == NULL) return; #ifdef DEBUG1 - DL_DEB(("prebind_free for %s %p\n", object->load_name, + DL_DEB(("prebind_free for %s %p\n", object->load_name, object->prebind_data)); #endif if (object->prebind_data != 0) { @@ -378,9 +358,8 @@ prebind_free(elf_object_t *object) #endif _dl_munmap((void *)ELF_TRUNC((long)object->prebind_data, _dl_pagesz), - ELF_ROUND((long)object->prebind_data+footer->prebind_size - ,_dl_pagesz) - - ELF_TRUNC((long)object->prebind_data, _dl_pagesz)); + ELF_ROUND((long)object->prebind_data+footer->prebind_size, + _dl_pagesz) - ELF_TRUNC((long)object->prebind_data, _dl_pagesz)); object->prebind_data = NULL; _dl_prog_prebind_map = NULL; @@ -393,15 +372,15 @@ prebind_free(elf_object_t *object) int validate_errs; struct timeval beforetp; + void _dl_prebind_pre_resolve() { + struct prebind_footer *footer; elf_object_t *object; struct nameidx *nameidx; - char *nametab; + char *nametab, *name; int idx; - char *name; - struct prebind_footer *footer; if (_dl_prog_prebind_map != NULL) { nameidx = _dl_prog_prebind_map + prog_footer->nameidx_idx; @@ -428,7 +407,7 @@ _dl_prebind_pre_resolve() break; } name = object->load_name; - if (_dl_strcmp( nametab + nameidx[idx].name, name) + if (_dl_strcmp(nametab + nameidx[idx].name, name) != 0) { DL_DEB(("invalid prebind name %s\n", object->load_name)); @@ -480,7 +459,7 @@ _dl_prebind_post_resolve() if (validate_errs) { _dl_printf("validate_errs %d\n", validate_errs); _dl_exit(20); - } else { + } else { _dl_exit(0); } } @@ -490,13 +469,12 @@ void prebind_validate(elf_object_t *req_obj, unsigned int symidx, int flags, const Elf_Sym *ref_sym) { - const Elf_Sym *sym; - const char *symn; + const Elf_Sym *sym, **this; const elf_object_t *sobj; + const char *symn; Elf_Addr ret; - const Elf_Sym **this; - /* Dont verify non-matching flags*/ + /* Don't verify non-matching flags*/ sym = req_obj->dyn.symtab; sym += symidx; @@ -509,17 +487,17 @@ prebind_validate(elf_object_t *req_obj, unsigned int symidx, int flags, if (_dl_symcache[symidx].sym != *this || _dl_symcache[symidx].obj != sobj) { _dl_printf("symbol %d mismatch on sym %s req_obj %s,\n" - "should be obj %s is obj %s\n", - symidx, - symn, req_obj->load_name, sobj->load_name, _dl_symcache[symidx].obj->load_name); + "should be obj %s is obj %s\n", + symidx, symn, req_obj->load_name, sobj->load_name, + _dl_symcache[symidx].obj->load_name); if (req_obj == sobj) _dl_printf("obj %p %p\n", _dl_symcache[symidx].obj, sobj); sym = _dl_symcache[symidx].obj->dyn.symtab; sym += symidx; symn = _dl_symcache[symidx].obj->dyn.strtab + sym->st_name; - _dl_printf("obj %s name %s\n", - _dl_symcache[symidx].obj->load_name, - symn); + _dl_printf("obj %s name %s\n", + _dl_symcache[symidx].obj->load_name, + symn); } } @@ -527,21 +505,23 @@ prebind_validate(elf_object_t *req_obj, unsigned int symidx, int flags, void prebind_dump_symcache(struct symcachetab *symcachetab, u_int32_t cnt) { - int i; struct symcachetab *s; + int i; + _dl_printf("cache: cnt %d\n", cnt); for (i = 0; i < cnt; i++) { s = &(symcachetab[i]); _dl_printf("symidx %d: obj %d sym %d\n", - s->idx, s->obj_idx, s->sym_idx); + s->idx, s->obj_idx, s->sym_idx); } } void prebind_dump_nameidx(struct nameidx *nameidx, u_int32_t numlibs, char *nametab) { - int i; struct nameidx *n; + int i; + _dl_printf("libs:\n"); for (i = 0; i < numlibs; i++) { _dl_printf("lib %d offset %d id0 %d, id1 %d\n", i, @@ -557,8 +537,9 @@ prebind_dump_nameidx(struct nameidx *nameidx, u_int32_t numlibs, char *nametab) void prebind_dump_fixup(struct fixup *fixup, u_int32_t numfixups) { - int i; struct fixup *f; + int i; + _dl_printf("fixup: %d\n", numfixups); for (i = 0; i < numfixups; i++) { f = &(fixup[i]); @@ -573,6 +554,7 @@ void prebind_dump_libmap(u_int32_t *libmap, u_int32_t numlibs) { int i; + for (i = 0; i < numlibs; i++) { //_dl_printf("lib%d off %d %s\n", i, libmap[i], strtab+libmap[i]); _dl_printf("lib%d off %d\n", i, libmap[i]); @@ -596,25 +578,22 @@ dl_dump_footer(struct prebind_footer *footer) // _dl_printf("orig_size %lld\n", (long long)footer->orig_size); _dl_printf("version %d\n", footer->prebind_version); _dl_printf("bind_id %c%c%c%c\n", footer->bind_id[0], - footer->bind_id[1], footer->bind_id[2], footer->bind_id[3]); + footer->bind_id[1], footer->bind_id[2], footer->bind_id[3]); } void dump_prelink(Elf_Addr base, u_long size) { - int i; - char *id; + u_int32_t *fixupidx, *fixupcnt, *libmap; struct symcachetab *symcachetab; - struct nameidx *nameidx; - void *prebind_map; struct prebind_footer *footer; - u_int32_t *fixupidx; - char *nametab; + struct nameidx *nameidx; struct fixup *fixup; - u_int32_t *fixupcnt; - u_int32_t *libmap; + char *nametab, *id; + void *prebind_map; + int i; id = (char *) (base+size); - id -=4; + id -= 4; DL_DEB(("id %c %c %c %c\n", id[0], id[1], id[2], id[3])); footer = (void *) (base+size - sizeof (struct prebind_footer)); dl_dump_footer(footer); diff --git a/libexec/ld.so/dl_prebind.h b/libexec/ld.so/dl_prebind.h index ae1b877568a..f2294911d18 100644 --- a/libexec/ld.so/dl_prebind.h +++ b/libexec/ld.so/dl_prebind.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dl_prebind.h,v 1.1 2006/05/03 16:10:51 drahn Exp $ */ +/* $OpenBSD: dl_prebind.h,v 1.2 2006/05/10 03:26:50 deraadt Exp $ */ /* * Copyright (c) 2006 Dale Rahn <drahn@dalerahn.com> * @@ -18,19 +18,19 @@ #include <sys/exec_elf.h> #include "resolve.h" #include "prebind.h" + extern char *_dl_noprebind; extern char *_dl_prebind_validate; -void _dl_prebind_pre_resolve(void); -void _dl_prebind_post_resolve(void); -void *prebind_load_fd(int fd, const char *name); -void prebind_load_exe(Elf_Phdr *phdp, elf_object_t *exe_obj); +void _dl_prebind_pre_resolve(void); +void _dl_prebind_post_resolve(void); +void *prebind_load_fd(int fd, const char *name); +void prebind_load_exe(Elf_Phdr *phdp, elf_object_t *exe_obj); -void -prebind_validate(elf_object_t *req_obj, unsigned int symidx, int flags, - const Elf_Sym *ref_sym); +void prebind_validate(elf_object_t *req_obj, unsigned int symidx, int flags, + const Elf_Sym *ref_sym); extern char *_dl_prebind_validate; /* XXX */ -void prebind_symcache(elf_object_t *object, int pltflag); -void prebind_free(elf_object_t *object); +void prebind_symcache(elf_object_t *object, int pltflag); +void prebind_free(elf_object_t *object); extern struct prebind_footer *footer; diff --git a/libexec/ld.so/library_mquery.c b/libexec/ld.so/library_mquery.c index 93edfe12ecd..7d3af5b8330 100644 --- a/libexec/ld.so/library_mquery.c +++ b/libexec/ld.so/library_mquery.c @@ -1,4 +1,4 @@ -/* $OpenBSD: library_mquery.c,v 1.33 2006/05/03 16:10:51 drahn Exp $ */ +/* $OpenBSD: library_mquery.c,v 1.34 2006/05/10 03:26:50 deraadt Exp $ */ /* * Copyright (c) 2002 Dale Rahn @@ -64,6 +64,7 @@ void _dl_unload_shlib(elf_object_t *object) { struct dep_node *n; + DL_DEB(("unload_shlib called on %s\n", object->load_name)); if (OBJECT_REF_CNT(object) == 0 && (object->status & STAT_UNLOADED) == 0) { @@ -82,18 +83,16 @@ _dl_unload_shlib(elf_object_t *object) elf_object_t * _dl_tryload_shlib(const char *libname, int type, int flags) { - int libfile, i, align = _dl_pagesz - 1; + int libfile, i, align = _dl_pagesz - 1, off, size; struct load_list *ld, *lowld = NULL; elf_object_t *object; - char hbuf[4096]; Elf_Dyn *dynp = 0; Elf_Ehdr *ehdr; Elf_Phdr *phdp; - int off; - int size; Elf_Addr load_end = 0; struct stat sb; void *prebind_data; + char hbuf[4096]; #define ROUND_PG(x) (((x) + align) & ~(align)) #define TRUNC_PG(x) ((x) & ~(align)) @@ -252,8 +251,8 @@ retry: } for (ld = lowld; ld != NULL; ld = ld->next) { - off_t foff; int fd, flags; + off_t foff; void *res; if (ld->foff < 0) { |