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