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