xref: /titanic_41/usr/src/uts/common/sys/kobj_impl.h (revision 45916cd2fec6e79bca5dee0421bd39e3c2910d1e)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * Kernel Run-Time Linker/Loader private interfaces.
29  */
30 
31 #ifndef	_SYS_KOBJ_IMPL_H
32 #define	_SYS_KOBJ_IMPL_H
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"
35 
36 #include <sys/kdi.h>
37 #include <sys/kobj.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 #define	KOBJ_TNF_PROBE	0x0040	/* Contains TNF probe(s) */
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 return */
140 #define	KM_SCRATCH		0x2000	/* not freed until boot unmap */
141 
142 extern kdi_t kobj_kdi;
143 
144 struct bootops;
145 
146 extern struct modctl_list *kobj_linkmaps[];
147 
148 extern char *kobj_kmdb_argv[];
149 
150 extern int kobj_mmu_pagesize;
151 
152 extern void kobj_init(void *romvec, void *dvec,
153 	struct bootops *bootvec, val_t *bootaux);
154 extern int kobj_notify_add(kobj_notify_list_t *);
155 extern int kobj_notify_remove(kobj_notify_list_t *);
156 extern int do_relocations(struct module *);
157 extern int do_relocate(struct module *, char *, Word, int, int, Addr);
158 extern void (*_kobj_printf)(void *, const char *fmt, ...);
159 extern struct bootops *ops;
160 extern void exitto(caddr_t);
161 extern void kobj_sync_instruction_memory(caddr_t, size_t);
162 extern uint_t kobj_gethashsize(uint_t);
163 extern void * kobj_mod_alloc(struct module *, size_t, int, reloc_dest_t *);
164 extern void mach_alloc_funcdesc(struct module *);
165 extern uint_t kobj_hash_name(const char *);
166 extern caddr_t kobj_segbrk(caddr_t *, size_t, size_t, caddr_t);
167 extern int get_progbits_size(struct module *, struct proginfo *,
168 	struct proginfo *, struct proginfo *);
169 extern Sym *kobj_lookup_kernel(const char *);
170 extern struct modctl *kobj_boot_mod_lookup(const char *);
171 extern void kobj_export_module(struct module *);
172 extern int kobj_load_primary_module(struct modctl *);
173 
174 #ifdef __sparc
175 extern void *kobj_bs_alloc(size_t);
176 
177 extern void *kobj_tmp_alloc(size_t);
178 extern void kobj_tmp_free(void);
179 #else
180 extern void kobj_boot_unmountroot(void);
181 #endif
182 
183 #define	KOBJ_LM_PRIMARY		0x0
184 #define	KOBJ_LM_DEBUGGER	0x1
185 
186 extern void kobj_lm_append(int, struct modctl *modp);
187 extern struct modctl_list *kobj_lm_lookup(int);
188 extern void kobj_lm_dump(int);
189 
190 #ifdef	__cplusplus
191 }
192 #endif
193 
194 #endif	/* _SYS_KOBJ_IMPL_H */
195