resolve.h revision 1.13
1/* $OpenBSD: resolve.h,v 1.13 2002/07/24 00:13:55 deraadt Exp $ */ 2 3/* 4 * Copyright (c) 1998 Per Fogelstrom, Opsycon AB 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed under OpenBSD by 17 * Per Fogelstrom, Opsycon AB, Sweden. 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 */ 34 35#ifndef _RESOLVE_H_ 36#define _RESOLVE_H_ 37 38#include <link.h> 39 40struct load_list { 41 struct load_list *next; 42 char *start; 43 size_t size; 44 int prot; 45}; 46 47/* 48 * Structure describing a loaded object. 49 * The head of this struct must be compatible 50 * with struct link_map in sys/link.h 51 */ 52typedef struct elf_object { 53 Elf_Addr load_addr; /* Real load address */ 54 char *load_name; /* Pointer to object name */ 55 Elf_Dyn *load_dyn; /* Pointer to object dynamic data */ 56 struct elf_object *next; 57 struct elf_object *prev; 58/* End struct link_map compatible */ 59 Elf_Addr load_offs; /* Load offset from link address */ 60 61 struct load_list *load_list; 62 63 u_int32_t load_size; 64 65 union { 66 u_long info[DT_NUM + DT_PROCNUM]; 67 struct { 68 Elf_Addr null; /* Not used */ 69 Elf_Addr needed; /* Not used */ 70 Elf_Addr pltrelsz; 71 Elf_Addr *pltgot; 72 Elf_Addr *hash; 73 const char *strtab; 74 const Elf_Sym *symtab; 75 Elf_RelA *rela; 76 Elf_Addr relasz; 77 Elf_Addr relaent; 78 Elf_Addr strsz; 79 Elf_Addr syment; 80 void (*init)(void); 81 void (*fini)(void); 82 const char *soname; 83 const char *rpath; 84 Elf_Addr symbolic; 85 Elf_Rel *rel; 86 Elf_Addr relsz; 87 Elf_Addr relent; 88 Elf_Addr pltrel; 89 Elf_Addr debug; 90 Elf_Addr textrel; 91 Elf_Addr jmprel; 92 Elf_Addr bind_now; 93 } u; 94 } Dyn; 95#define dyn Dyn.u 96 97 struct elf_object *dep_next; /* Shadow objects for resolve search */ 98 99 int status; 100#define STAT_RELOC_DONE 1 101#define STAT_GOT_DONE 2 102#define STAT_INIT_DONE 4 103 104 Elf_Phdr *phdrp; 105 int phdrc; 106 107 int refcount; 108 int obj_type; 109#define OBJTYPE_LDR 1 110#define OBJTYPE_EXE 2 111#define OBJTYPE_LIB 3 112#define OBJTYPE_DLO 4 113 114 Elf_Word *buckets; 115 u_int32_t nbuckets; 116 Elf_Word *chains; 117 u_int32_t nchains; 118 Elf_Dyn *dynamic; 119 120} elf_object_t; 121 122extern void _dl_rt_resolve(void); 123 124extern elf_object_t *_dl_add_object(const char *objname, Elf_Dyn *dynp, 125 const u_long *, const int objtype, 126 const long laddr, const long loff); 127extern void _dl_remove_object(elf_object_t *object); 128 129extern elf_object_t *_dl_lookup_object(const char *objname); 130extern elf_object_t *_dl_load_shlib(const char *, elf_object_t *, int); 131extern void _dl_unload_shlib(elf_object_t *object); 132 133extern int _dl_md_reloc(elf_object_t *object, int rel, int relsz); 134extern void _dl_md_reloc_got(elf_object_t *object, int lazy); 135 136Elf_Addr _dl_find_symbol(const char *name, elf_object_t *startlook, 137 const Elf_Sym **ref, int myself, int warnnotfound); 138 139void _dl_rtld(elf_object_t *object); 140void _dl_call_init(elf_object_t *object); 141 142extern elf_object_t *_dl_objects; 143extern elf_object_t *_dl_last_object; 144 145extern const char *_dl_progname; 146extern struct r_debug *_dl_debug_map; 147 148extern int _dl_pagesz; 149extern int _dl_errno; 150 151extern char *_dl_libpath; 152extern char *_dl_preload; 153extern char *_dl_bindnow; 154extern char *_dl_traceld; 155extern char *_dl_debug; 156 157#define DL_DEB(P) do { if (_dl_debug) _dl_printf P ; } while (0) 158 159#define DL_NOT_FOUND 1 160#define DL_CANT_OPEN 2 161#define DL_NOT_ELF 3 162#define DL_CANT_OPEN_REF 4 163#define DL_CANT_MMAP 5 164#define DL_NO_SYMBOL 6 165#define DL_INVALID_HANDLE 7 166#define DL_INVALID_CTL 8 167 168#endif /* _RESOLVE_H_ */ 169