Sat Mar 10 10:33:02 2018 UTC ()
Add new fields and flags needed to support module aliases


(pgoyette)
diff -r1.41 -r1.41.14.1 src/sys/sys/module.h

cvs diff -r1.41 -r1.41.14.1 src/sys/sys/module.h (switch to unified diff)

--- src/sys/sys/module.h 2016/11/16 10:42:14 1.41
+++ src/sys/sys/module.h 2018/03/10 10:33:02 1.41.14.1
@@ -1,258 +1,261 @@ @@ -1,258 +1,261 @@
1/* $NetBSD: module.h,v 1.41 2016/11/16 10:42:14 pgoyette Exp $ */ 1/* $NetBSD: module.h,v 1.41.14.1 2018/03/10 10:33:02 pgoyette Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#ifndef _SYS_MODULE_H_ 29#ifndef _SYS_MODULE_H_
30#define _SYS_MODULE_H_ 30#define _SYS_MODULE_H_
31 31
32#include <sys/types.h> 32#include <sys/types.h>
33#include <sys/param.h> 33#include <sys/param.h>
34#include <sys/cdefs.h> 34#include <sys/cdefs.h>
35#include <sys/queue.h> 35#include <sys/queue.h>
36#include <sys/uio.h> 36#include <sys/uio.h>
37 37
38#define MAXMODNAME 32 38#define MAXMODNAME 32
39#define MAXMODDEPS 10 39#define MAXMODDEPS 10
40 40
41/* Module classes, provided only for system boot and cosmetic purposes. */ 41/* Module classes, provided only for system boot and cosmetic purposes. */
42typedef enum modclass { 42typedef enum modclass {
43 MODULE_CLASS_ANY, 43 MODULE_CLASS_ANY,
44 MODULE_CLASS_MISC, 44 MODULE_CLASS_MISC,
45 MODULE_CLASS_VFS, 45 MODULE_CLASS_VFS,
46 MODULE_CLASS_DRIVER, 46 MODULE_CLASS_DRIVER,
47 MODULE_CLASS_EXEC, 47 MODULE_CLASS_EXEC,
48 MODULE_CLASS_SECMODEL, 48 MODULE_CLASS_SECMODEL,
49 MODULE_CLASS_BUFQ 49 MODULE_CLASS_BUFQ
50} modclass_t; 50} modclass_t;
51 51
52/* Module sources: where did it come from? */ 52/* Module sources: where did it come from? */
53typedef enum modsrc { 53typedef enum modsrc {
54 MODULE_SOURCE_KERNEL, 54 MODULE_SOURCE_KERNEL,
55 MODULE_SOURCE_BOOT, 55 MODULE_SOURCE_BOOT,
56 MODULE_SOURCE_FILESYS 56 MODULE_SOURCE_FILESYS
57} modsrc_t; 57} modsrc_t;
58 58
59/* Commands passed to module control routine. */ 59/* Commands passed to module control routine. */
60typedef enum modcmd { 60typedef enum modcmd {
61 MODULE_CMD_INIT, /* mandatory */ 61 MODULE_CMD_INIT, /* mandatory */
62 MODULE_CMD_FINI, /* mandatory */ 62 MODULE_CMD_FINI, /* mandatory */
63 MODULE_CMD_STAT, /* optional */ 63 MODULE_CMD_STAT, /* optional */
64 MODULE_CMD_AUTOUNLOAD, /* optional */ 64 MODULE_CMD_AUTOUNLOAD, /* optional */
 65 MODULE_CMD_GETALIASES, /* optional */
65} modcmd_t; 66} modcmd_t;
66 67
67#ifdef _KERNEL 68#ifdef _KERNEL
68 69
69#include <sys/kernel.h> 70#include <sys/kernel.h>
70#include <sys/mutex.h> 71#include <sys/mutex.h>
71 72
72#include <prop/proplib.h> 73#include <prop/proplib.h>
73 74
74/* Module header structure. */ 75/* Module header structure. */
75typedef struct modinfo { 76typedef struct modinfo {
76 u_int mi_version; 77 u_int mi_version;
77 modclass_t mi_class; 78 modclass_t mi_class;
78 int (*mi_modcmd)(modcmd_t, void *); 79 int (*mi_modcmd)(modcmd_t, void *);
79 const char *mi_name; 80 const char *mi_name;
80 const char *mi_required; 81 const char *mi_required;
 82 const char *mi_aliases;
81} const modinfo_t; 83} const modinfo_t;
82 84
83/* Per module information, maintained by kern_module.c */  85/* Per module information, maintained by kern_module.c */
84typedef struct module { 86typedef struct module {
85 u_int mod_refcnt; 87 u_int mod_refcnt;
86 const modinfo_t *mod_info; 88 const modinfo_t *mod_info;
87 struct kobj *mod_kobj; 89 struct kobj *mod_kobj;
88 TAILQ_ENTRY(module) mod_chain; 90 TAILQ_ENTRY(module) mod_chain;
89 struct module *mod_required[MAXMODDEPS]; 91 struct module *mod_required[MAXMODDEPS];
90 u_int mod_nrequired; 92 u_int mod_nrequired;
91 modsrc_t mod_source; 93 modsrc_t mod_source;
92 time_t mod_autotime; 94 time_t mod_autotime;
93 void *mod_ctf; 95 void *mod_ctf;
94 u_int mod_fbtentries; /* DTrace FBT entry count */ 96 u_int mod_fbtentries; /* DTrace FBT entry count */
95 int mod_flags; 97 int mod_flags;
96#define MODFLG_MUST_FORCE 0x01 98#define MODFLG_MUST_FORCE 0x01
97#define MODFLG_AUTO_LOADED 0x02 99#define MODFLG_AUTO_LOADED 0x02
 100#define MODFLG_IS_ALIAS 0x04 /* only for export via modstat_t */
98 101
99} module_t; 102} module_t;
100 103
101/* 104/*
102 * Per-module linkage. Loadable modules have a `link_set_modules' section 105 * Per-module linkage. Loadable modules have a `link_set_modules' section
103 * containing only one entry, pointing to the module's modinfo_t record. 106 * containing only one entry, pointing to the module's modinfo_t record.
104 * For the kernel, `link_set_modules' can contain multiple entries and 107 * For the kernel, `link_set_modules' can contain multiple entries and
105 * records all modules built into the kernel at link time. 108 * records all modules built into the kernel at link time.
106 * 109 *
107 * Alternatively, in some environments rump kernels use 110 * Alternatively, in some environments rump kernels use
108 * __attribute__((constructor)) due to link sets being 111 * __attribute__((constructor)) due to link sets being
109 * difficult (impossible?) to implement (e.g. GNU gold, OS X, etc.) 112 * difficult (impossible?) to implement (e.g. GNU gold, OS X, etc.)
110 * If we're cold (read: rump_init() has not been called), we lob the 113 * If we're cold (read: rump_init() has not been called), we lob the
111 * module onto the list to be handled when rump_init() runs. 114 * module onto the list to be handled when rump_init() runs.
112 * nb. it's not possible to use in-kernel locking mechanisms here since 115 * nb. it's not possible to use in-kernel locking mechanisms here since
113 * the code runs before rump_init(). We solve the problem by decreeing 116 * the code runs before rump_init(). We solve the problem by decreeing
114 * that thou shalt not call dlopen()/dlclose() for rump kernel components 117 * that thou shalt not call dlopen()/dlclose() for rump kernel components
115 * from multiple threads before calling rump_init(). 118 * from multiple threads before calling rump_init().
116 */ 119 */
117 120
118#ifdef RUMP_USE_CTOR 121#ifdef RUMP_USE_CTOR
119struct modinfo_chain { 122struct modinfo_chain {
120 const struct modinfo *mc_info; 123 const struct modinfo *mc_info;
121 LIST_ENTRY(modinfo_chain) mc_entries; 124 LIST_ENTRY(modinfo_chain) mc_entries;
122}; 125};
123LIST_HEAD(modinfo_boot_chain, modinfo_chain); 126LIST_HEAD(modinfo_boot_chain, modinfo_chain);
124#define _MODULE_REGISTER(name) \ 127#define _MODULE_REGISTER(name) \
125static struct modinfo_chain __CONCAT(mc,name) = { \ 128static struct modinfo_chain __CONCAT(mc,name) = { \
126 .mc_info = &__CONCAT(name,_modinfo), \ 129 .mc_info = &__CONCAT(name,_modinfo), \
127}; \ 130}; \
128static void __CONCAT(modctor_,name)(void) __attribute__((__constructor__));\ 131static void __CONCAT(modctor_,name)(void) __attribute__((__constructor__));\
129static void __CONCAT(modctor_,name)(void) \ 132static void __CONCAT(modctor_,name)(void) \
130{ \ 133{ \
131 extern struct modinfo_boot_chain modinfo_boot_chain; \ 134 extern struct modinfo_boot_chain modinfo_boot_chain; \
132 if (cold) { \ 135 if (cold) { \
133 struct modinfo_chain *mc = &__CONCAT(mc,name); \ 136 struct modinfo_chain *mc = &__CONCAT(mc,name); \
134 LIST_INSERT_HEAD(&modinfo_boot_chain, mc, mc_entries); \ 137 LIST_INSERT_HEAD(&modinfo_boot_chain, mc, mc_entries); \
135 } \ 138 } \
136} \ 139} \
137 \ 140 \
138static void __CONCAT(moddtor_,name)(void) __attribute__((__destructor__));\ 141static void __CONCAT(moddtor_,name)(void) __attribute__((__destructor__));\
139static void __CONCAT(moddtor_,name)(void) \ 142static void __CONCAT(moddtor_,name)(void) \
140{ \ 143{ \
141 struct modinfo_chain *mc = &__CONCAT(mc,name); \ 144 struct modinfo_chain *mc = &__CONCAT(mc,name); \
142 if (cold) { \ 145 if (cold) { \
143 LIST_REMOVE(mc, mc_entries); \ 146 LIST_REMOVE(mc, mc_entries); \
144 } \ 147 } \
145} 148}
146 149
147#else /* RUMP_USE_CTOR */ 150#else /* RUMP_USE_CTOR */
148 151
149#define _MODULE_REGISTER(name) __link_set_add_rodata(modules, __CONCAT(name,_modinfo)); 152#define _MODULE_REGISTER(name) __link_set_add_rodata(modules, __CONCAT(name,_modinfo));
150 153
151#endif /* RUMP_USE_CTOR */ 154#endif /* RUMP_USE_CTOR */
152 155
153#define MODULE(class, name, required) \ 156#define MODULE(class, name, required) \
154static int __CONCAT(name,_modcmd)(modcmd_t, void *); \ 157static int __CONCAT(name,_modcmd)(modcmd_t, void *); \
155static const modinfo_t __CONCAT(name,_modinfo) = { \ 158static const modinfo_t __CONCAT(name,_modinfo) = { \
156 .mi_version = __NetBSD_Version__, \ 159 .mi_version = __NetBSD_Version__, \
157 .mi_class = (class), \ 160 .mi_class = (class), \
158 .mi_modcmd = __CONCAT(name,_modcmd), \ 161 .mi_modcmd = __CONCAT(name,_modcmd), \
159 .mi_name = __STRING(name), \ 162 .mi_name = __STRING(name), \
160 .mi_required = (required) \ 163 .mi_required = (required) \
161}; \ 164}; \
162_MODULE_REGISTER(name) 165_MODULE_REGISTER(name)
163 166
164TAILQ_HEAD(modlist, module); 167TAILQ_HEAD(modlist, module);
165 168
166extern struct vm_map *module_map; 169extern struct vm_map *module_map;
167extern u_int module_count; 170extern u_int module_count;
168extern u_int module_builtinlist; 171extern u_int module_builtinlist;
169extern struct modlist module_list; 172extern struct modlist module_list;
170extern struct modlist module_builtins; 173extern struct modlist module_builtins;
171extern u_int module_gen; 174extern u_int module_gen;
172 175
173void module_init(void); 176void module_init(void);
174void module_start_unload_thread(void); 177void module_start_unload_thread(void);
175void module_builtin_require_force(void); 178void module_builtin_require_force(void);
176void module_init_md(void); 179void module_init_md(void);
177void module_init_class(modclass_t); 180void module_init_class(modclass_t);
178int module_prime(const char *, void *, size_t); 181int module_prime(const char *, void *, size_t);
179 182
180bool module_compatible(int, int); 183bool module_compatible(int, int);
181int module_load(const char *, int, prop_dictionary_t, modclass_t); 184int module_load(const char *, int, prop_dictionary_t, modclass_t);
182int module_builtin_add(modinfo_t * const *, size_t, bool); 185int module_builtin_add(modinfo_t * const *, size_t, bool);
183int module_builtin_remove(modinfo_t *, bool); 186int module_builtin_remove(modinfo_t *, bool);
184int module_autoload(const char *, modclass_t); 187int module_autoload(const char *, modclass_t);
185int module_unload(const char *); 188int module_unload(const char *);
186int module_hold(const char *); 189int module_hold(const char *);
187void module_rele(const char *); 190void module_rele(const char *);
188int module_find_section(const char *, void **, size_t *); 191int module_find_section(const char *, void **, size_t *);
189void module_thread_kick(void); 192void module_thread_kick(void);
190void module_load_vfs_init(void); 193void module_load_vfs_init(void);
191 194
192void module_whatis(uintptr_t, void (*)(const char *, ...) 195void module_whatis(uintptr_t, void (*)(const char *, ...)
193 __printflike(1, 2)); 196 __printflike(1, 2));
194void module_print_list(void (*)(const char *, ...) __printflike(1, 2)); 197void module_print_list(void (*)(const char *, ...) __printflike(1, 2));
195 198
196#ifdef _MODULE_INTERNAL 199#ifdef _MODULE_INTERNAL
197extern 200extern
198int (*module_load_vfs_vec)(const char *, int, bool, module_t *, 201int (*module_load_vfs_vec)(const char *, int, bool, module_t *,
199 prop_dictionary_t *); 202 prop_dictionary_t *);
200int module_load_vfs(const char *, int, bool, module_t *, 203int module_load_vfs(const char *, int, bool, module_t *,
201 prop_dictionary_t *); 204 prop_dictionary_t *);
202void module_error(const char *, ...) __printflike(1, 2); 205void module_error(const char *, ...) __printflike(1, 2);
203void module_print(const char *, ...) __printflike(1, 2); 206void module_print(const char *, ...) __printflike(1, 2);
204#endif /* _MODULE_INTERNAL */ 207#endif /* _MODULE_INTERNAL */
205 208
206#define MODULE_BASE_SIZE 64 209#define MODULE_BASE_SIZE 64
207extern char module_base[MODULE_BASE_SIZE]; 210extern char module_base[MODULE_BASE_SIZE];
208extern const char *module_machine; 211extern const char *module_machine;
209 212
210#else /* _KERNEL */ 213#else /* _KERNEL */
211 214
212#include <stdint.h> 215#include <stdint.h>
213 216
214#endif /* _KERNEL */ 217#endif /* _KERNEL */
215 218
216typedef struct modctl_load { 219typedef struct modctl_load {
217 const char *ml_filename; 220 const char *ml_filename;
218 221
219#define MODCTL_NO_PROP 0x2 222#define MODCTL_NO_PROP 0x2
220#define MODCTL_LOAD_FORCE 0x1 223#define MODCTL_LOAD_FORCE 0x1
221 int ml_flags; 224 int ml_flags;
222 225
223 const char *ml_props; 226 const char *ml_props;
224 size_t ml_propslen; 227 size_t ml_propslen;
225} modctl_load_t; 228} modctl_load_t;
226 229
227typedef enum modctl { 230typedef enum modctl {
228 MODCTL_LOAD, /* modctl_load_t *ml */ 231 MODCTL_LOAD, /* modctl_load_t *ml */
229 MODCTL_UNLOAD, /* char *name */ 232 MODCTL_UNLOAD, /* char *name */
230 MODCTL_STAT, /* struct iovec *buffer */ 233 MODCTL_STAT, /* struct iovec *buffer */
231 MODCTL_EXISTS /* enum: 0: load, 1: autoload */ 234 MODCTL_EXISTS /* enum: 0: load, 1: autoload */
232} modctl_t; 235} modctl_t;
233 236
234/* 237/*
235 * This structure intentionally has the same layout for 32 and 64 238 * This structure intentionally has the same layout for 32 and 64
236 * bit builds. 239 * bit builds.
237 */ 240 */
238typedef struct modstat { 241typedef struct modstat {
239 char ms_name[MAXMODNAME]; 242 char ms_name[MAXMODNAME];
240 char ms_required[MAXMODNAME * MAXMODDEPS]; 243 char ms_required[MAXMODNAME * MAXMODDEPS];
241 uint64_t ms_addr; 244 uint64_t ms_addr;
242 modsrc_t ms_source; 245 modsrc_t ms_source;
243 modclass_t ms_class; 246 modclass_t ms_class;
244 u_int ms_size; 247 u_int ms_size;
245 u_int ms_refcnt; 248 u_int ms_refcnt;
246 u_int ms_flags; 249 u_int ms_flags;
247 u_int ms_reserved[3]; 250 u_int ms_reserved[3];
248} modstat_t; 251} modstat_t;
249 252
250int modctl(int, void *); 253int modctl(int, void *);
251 254
252#ifdef _KERNEL 255#ifdef _KERNEL
253/* attention: pointers passed are userland pointers!, 256/* attention: pointers passed are userland pointers!,
254 see modctl_load_t */ 257 see modctl_load_t */
255int handle_modctl_load(const char *, int, const char *, size_t); 258int handle_modctl_load(const char *, int, const char *, size_t);
256#endif 259#endif
257 260
258#endif /* !_SYS_MODULE_H_ */ 261#endif /* !_SYS_MODULE_H_ */