xref: /illumos-gate/usr/src/uts/common/sys/kobj_impl.h (revision 89b2a9fbeabf42fa54594df0e5927bcc50a07cc9)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * Kernel Run-Time Linker/Loader private interfaces.
28  */
29 
30 #ifndef	_SYS_KOBJ_IMPL_H
31 #define	_SYS_KOBJ_IMPL_H
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"
34 
35 #include <sys/kdi.h>
36 #include <sys/kobj.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 /*
43  * Boot/aux vector attributes.
44  */
45 
46 #define	BA_DYNAMIC	0
47 #define	BA_PHDR		1
48 #define	BA_PHNUM	2
49 #define	BA_PHENT	3
50 #define	BA_ENTRY	4
51 #define	BA_PAGESZ	5
52 #define	BA_LPAGESZ	6
53 #define	BA_LDELF	7
54 #define	BA_LDSHDR	8
55 #define	BA_LDNAME	9
56 #define	BA_BSS		10
57 #define	BA_IFLUSH	11
58 #define	BA_CPU		12
59 #define	BA_MMU		13
60 #define	BA_GOTADDR	14
61 #define	BA_NEXTGOT	15
62 #define	BA_NUM		16
63 
64 typedef union {
65 	unsigned long ba_val;
66 	void *ba_ptr;
67 } val_t;
68 
69 /*
70  * Segment info.
71  */
72 struct proginfo {
73 	uint_t size;
74 	uint_t align;
75 };
76 
77 /*
78  * Implementation-specific flags.
79  */
80 #define	KOBJ_EXEC	0x0004	/* executable (unix module) */
81 #define	KOBJ_INTERP	0x0008	/* the interpreter module */
82 #define	KOBJ_PRIM	0x0010	/* a primary kernel module */
83 #define	KOBJ_RESOLVED	0x0020	/* fully resolved */
84 #define	KOBJ_TNF_PROBE	0x0040	/* Contains TNF probe(s) */
85 #define	KOBJ_RELOCATED	0x0080	/* relocation completed */
86 #define	KOBJ_NOPARENTS	0x0200	/* nothing can depend on this module */
87 #define	KOBJ_IGNMULDEF	0x0400	/* ignore dups during sym resolution */
88 #define	KOBJ_NOKSYMS	0x0800	/* module's symbols don't go into ksyms */
89 #define	KOBJ_EXPORTED	0x1000	/* ctf, syms copied to vmem */
90 
91 /*
92  * kobj_notify_add() data notification structure
93  */
94 typedef void kobj_notify_f(uint_t, struct modctl *);
95 
96 typedef struct kobj_notify_list {
97 	kobj_notify_f		*kn_func;	/* notification func */
98 	uint_t			kn_type;	/* notification type */
99 	struct kobj_notify_list	*kn_prev;
100 	struct kobj_notify_list	*kn_next;
101 } kobj_notify_list_t;
102 
103 /*
104  * krtld can provide notification to external clients on the
105  * following events.
106  */
107 #define	KOBJ_NOTIFY_MODLOADING		1	/* very early in module load */
108 #define	KOBJ_NOTIFY_MODUNLOADING	2	/* before module unload */
109 #define	KOBJ_NOTIFY_MODLOADED		3	/* after module load */
110 #define	KOBJ_NOTIFY_MODUNLOADED		4	/* after module unload */
111 #define	KOBJ_NOTIFY_MAX			4
112 
113 #define	ALIGN(x, a)	((a) == 0 ? (uintptr_t)(x) : \
114 	(((uintptr_t)(x) + (uintptr_t)(a) - 1l) & ~((uintptr_t)(a) - 1l)))
115 
116 #ifdef	DEBUG
117 #define	KOBJ_DEBUG
118 #endif
119 
120 #ifdef KOBJ_DEBUG
121 /*
122  * Debugging flags.
123  */
124 #define	D_DEBUG			0x001	/* general debugging */
125 #define	D_SYMBOLS		0x002	/* debug symbols */
126 #define	D_RELOCATIONS		0x004	/* debug relocations */
127 #define	D_LOADING		0x008	/* section loading */
128 
129 extern int kobj_debug;		/* different than moddebug */
130 #endif
131 
132 /*
133  * Flags for kobj memory allocation.
134  */
135 #define	KM_WAIT			0x0	/* wait for it */
136 #define	KM_NOWAIT		0x1	/* return immediately */
137 
138 #define	KM_TMP			0x1000	/* freed before kobj_init returns */
139 #define	KM_SCRATCH		0x2000	/* not freed until kobj_sync */
140 
141 #ifdef	KOBJ_OVERRIDES
142 /*
143  * Until the kernel is fully linked, all code running in the
144  * context of krtld/kobj using bcopy or bzero must be directed
145  * to the kobj equivalents.  All (ok, most) references to bcopy
146  * or bzero are thus so vectored.
147  */
148 #define	bcopy(s, d, n)		kobj_bcopy((s), (d), (n))
149 #define	bzero(p, n)		kobj_bzero((p), (n))
150 #define	strlcat(s, d, n)	kobj_strlcat((s), (d), (n))
151 #endif
152 
153 extern kdi_t kobj_kdi;
154 
155 struct bootops;
156 
157 extern struct modctl_list *kobj_linkmaps[];
158 
159 extern char *kobj_kmdb_argv[];
160 
161 extern int kobj_mmu_pagesize;
162 
163 extern void kobj_init(void *romvec, void *dvec,
164 	struct bootops *bootvec, val_t *bootaux);
165 extern int kobj_notify_add(kobj_notify_list_t *);
166 extern int kobj_notify_remove(kobj_notify_list_t *);
167 extern int do_relocations(struct module *);
168 extern int do_relocate(struct module *, char *, Word, int, int, Addr);
169 extern struct bootops *ops;
170 extern void exitto(caddr_t);
171 extern void kobj_sync_instruction_memory(caddr_t, size_t);
172 extern uint_t kobj_gethashsize(uint_t);
173 extern void * kobj_mod_alloc(struct module *, size_t, int, reloc_dest_t *);
174 extern void mach_alloc_funcdesc(struct module *);
175 extern uint_t kobj_hash_name(const char *);
176 extern caddr_t kobj_segbrk(caddr_t *, size_t, size_t, caddr_t);
177 extern int get_progbits_size(struct module *, struct proginfo *,
178 	struct proginfo *, struct proginfo *);
179 extern Sym *kobj_lookup_kernel(const char *);
180 extern struct modctl *kobj_boot_mod_lookup(const char *);
181 extern void kobj_export_module(struct module *);
182 extern int kobj_load_primary_module(struct modctl *);
183 extern int boot_compinfo(int, struct compinfo *);
184 extern void mach_modpath(char *, const char *);
185 
186 extern void kobj_setup_standalone_vectors(void);
187 extern void kobj_restore_vectors(void);
188 extern void (*_kobj_printf)(void *, const char *fmt, ...);
189 extern void (*kobj_bcopy)(const void *, void *, size_t);
190 extern void (*kobj_bzero)(void *, size_t);
191 extern size_t (*kobj_strlcat)(char *, const char *, size_t);
192 
193 #define	KOBJ_LM_PRIMARY		0x0
194 #define	KOBJ_LM_DEBUGGER	0x1
195 
196 extern void kobj_lm_append(int, struct modctl *modp);
197 extern struct modctl_list *kobj_lm_lookup(int);
198 extern void kobj_lm_dump(int);
199 
200 #ifdef	__cplusplus
201 }
202 #endif
203 
204 #endif	/* _SYS_KOBJ_IMPL_H */
205