resolve.h revision 1.5
1/*	$OpenBSD: resolve.h,v 1.5 2001/06/06 12:31:52 art 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
40typedef struct load_list {
41	struct load_list *next;
42	char       *start;
43	size_t     size;
44	int        prot;
45} load_list_t;
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	Elf_Addr load_offs;		/* Load offset from link address */
55	char	   *load_name;		/* Pointer to object name */
56	Elf_Dyn  *load_dyn;		/* Pointer to object dynamic data */
57	struct elf_object *next;
58	struct elf_object *prev;
59/* End struct link_map compatible */
60
61	load_list_t *load_list;
62
63	u_int32_t  load_size;
64
65	union {
66		u_long		info[DT_NUM + DT_PROCNUM];
67		struct {
68			Elf_Word	null;		/* Not used */
69			Elf_Word	needed;		/* Not used */
70			Elf_Word	pltrelsz;
71			Elf_Word	*pltgot;
72			Elf_Word	*hash;
73			const char	*strtab;
74			const Elf_Sym	*symtab;
75			Elf_RelA	*rela;
76			Elf_Word	relasz;
77			Elf_Word	relaent;
78			Elf_Word	strsz;
79			Elf_Word	syment;
80			void		(*init)(void);
81			void		(*fini)(void);
82			const char	*soname;
83			const char	*rpath;
84			Elf_Word	symbolic;
85			Elf_Rel	*rel;
86			Elf_Word	relsz;
87			Elf_Word	relent;
88			Elf_Word	pltrel;
89			Elf_Word	debug;
90			Elf_Word	textrel;
91			Elf_Word	jmprel;
92			Elf_Word	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_malloc(const int size);
140void  _dl_free(void *);
141
142void _dl_rtld(elf_object_t *object);
143void _dl_call_init(elf_object_t *object);
144
145extern elf_object_t *_dl_objects;
146extern elf_object_t *_dl_last_object;
147
148extern const char *_dl_progname;
149extern struct r_debug *_dl_debug_map;
150
151extern int  _dl_pagesz;
152extern int  _dl_trusted;
153extern int  _dl_errno;
154
155extern char *_dl_libpath;
156extern char *_dl_preload;
157extern char *_dl_bindnow;
158extern char *_dl_traceld;
159extern char *_dl_debug;
160
161#define DL_DEB(P) do { if (_dl_debug) _dl_printf P ; } while (0)
162
163#define	DL_NOT_FOUND		1
164#define	DL_CANT_OPEN		2
165#define	DL_NOT_ELF		3
166#define	DL_CANT_OPEN_REF	4
167#define	DL_CANT_MMAP		5
168#define	DL_NO_SYMBOL		6
169#define	DL_INVALID_HANDLE	7
170#define	DL_INVALID_CTL		8
171
172#endif /* _RESOLVE_H_ */
173