Sun Mar 11 00:58:12 2018 UTC ()
Don't use () around __CONCAT as the expression is no longer constant


(pgoyette)
diff -r1.41.14.4 -r1.41.14.5 src/sys/sys/module.h

cvs diff -r1.41.14.4 -r1.41.14.5 src/sys/sys/module.h (switch to unified diff)

--- src/sys/sys/module.h 2018/03/11 00:53:13 1.41.14.4
+++ src/sys/sys/module.h 2018/03/11 00:58:12 1.41.14.5
@@ -1,265 +1,265 @@ @@ -1,265 +1,265 @@
1/* $NetBSD: module.h,v 1.41.14.4 2018/03/11 00:53:13 pgoyette Exp $ */ 1/* $NetBSD: module.h,v 1.41.14.5 2018/03/11 00:58:12 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} modcmd_t; 65} modcmd_t;
66 66
67#ifdef _KERNEL 67#ifdef _KERNEL
68 68
69#include <sys/kernel.h> 69#include <sys/kernel.h>
70#include <sys/mutex.h> 70#include <sys/mutex.h>
71 71
72#include <prop/proplib.h> 72#include <prop/proplib.h>
73 73
74/* Module header structure. */ 74/* Module header structure. */
75typedef struct modinfo { 75typedef struct modinfo {
76 u_int mi_version; 76 u_int mi_version;
77 modclass_t mi_class; 77 modclass_t mi_class;
78 int (*mi_modcmd)(modcmd_t, void *); 78 int (*mi_modcmd)(modcmd_t, void *);
79 const char *mi_name; 79 const char *mi_name;
80 const char *mi_required; 80 const char *mi_required;
81 const char * const *mi_aliases; 81 const char * const *mi_aliases;
82} const modinfo_t; 82} const modinfo_t;
83 83
84/* Per module information, maintained by kern_module.c */  84/* Per module information, maintained by kern_module.c */
85typedef struct module { 85typedef struct module {
86 u_int mod_refcnt; 86 u_int mod_refcnt;
87 const modinfo_t *mod_info; 87 const modinfo_t *mod_info;
88 struct kobj *mod_kobj; 88 struct kobj *mod_kobj;
89 TAILQ_ENTRY(module) mod_chain; 89 TAILQ_ENTRY(module) mod_chain;
90 struct module *mod_required[MAXMODDEPS]; 90 struct module *mod_required[MAXMODDEPS];
91 u_int mod_nrequired; 91 u_int mod_nrequired;
92 modsrc_t mod_source; 92 modsrc_t mod_source;
93 time_t mod_autotime; 93 time_t mod_autotime;
94 void *mod_ctf; 94 void *mod_ctf;
95 u_int mod_fbtentries; /* DTrace FBT entry count */ 95 u_int mod_fbtentries; /* DTrace FBT entry count */
96 int mod_flags; 96 int mod_flags;
97#define MODFLG_MUST_FORCE 0x01 97#define MODFLG_MUST_FORCE 0x01
98#define MODFLG_AUTO_LOADED 0x02 98#define MODFLG_AUTO_LOADED 0x02
99#define MODFLG_IS_ALIAS 0x04 /* only for export via modstat_t */ 99#define MODFLG_IS_ALIAS 0x04 /* only for export via modstat_t */
100 100
101} module_t; 101} module_t;
102 102
103/* 103/*
104 * Per-module linkage. Loadable modules have a `link_set_modules' section 104 * Per-module linkage. Loadable modules have a `link_set_modules' section
105 * containing only one entry, pointing to the module's modinfo_t record. 105 * containing only one entry, pointing to the module's modinfo_t record.
106 * For the kernel, `link_set_modules' can contain multiple entries and 106 * For the kernel, `link_set_modules' can contain multiple entries and
107 * records all modules built into the kernel at link time. 107 * records all modules built into the kernel at link time.
108 * 108 *
109 * Alternatively, in some environments rump kernels use 109 * Alternatively, in some environments rump kernels use
110 * __attribute__((constructor)) due to link sets being 110 * __attribute__((constructor)) due to link sets being
111 * difficult (impossible?) to implement (e.g. GNU gold, OS X, etc.) 111 * difficult (impossible?) to implement (e.g. GNU gold, OS X, etc.)
112 * If we're cold (read: rump_init() has not been called), we lob the 112 * If we're cold (read: rump_init() has not been called), we lob the
113 * module onto the list to be handled when rump_init() runs. 113 * module onto the list to be handled when rump_init() runs.
114 * nb. it's not possible to use in-kernel locking mechanisms here since 114 * nb. it's not possible to use in-kernel locking mechanisms here since
115 * the code runs before rump_init(). We solve the problem by decreeing 115 * the code runs before rump_init(). We solve the problem by decreeing
116 * that thou shalt not call dlopen()/dlclose() for rump kernel components 116 * that thou shalt not call dlopen()/dlclose() for rump kernel components
117 * from multiple threads before calling rump_init(). 117 * from multiple threads before calling rump_init().
118 */ 118 */
119 119
120#ifdef RUMP_USE_CTOR 120#ifdef RUMP_USE_CTOR
121struct modinfo_chain { 121struct modinfo_chain {
122 const struct modinfo *mc_info; 122 const struct modinfo *mc_info;
123 LIST_ENTRY(modinfo_chain) mc_entries; 123 LIST_ENTRY(modinfo_chain) mc_entries;
124}; 124};
125LIST_HEAD(modinfo_boot_chain, modinfo_chain); 125LIST_HEAD(modinfo_boot_chain, modinfo_chain);
126#define _MODULE_REGISTER(name) \ 126#define _MODULE_REGISTER(name) \
127static struct modinfo_chain __CONCAT(mc,name) = { \ 127static struct modinfo_chain __CONCAT(mc,name) = { \
128 .mc_info = &__CONCAT(name,_modinfo), \ 128 .mc_info = &__CONCAT(name,_modinfo), \
129}; \ 129}; \
130static void __CONCAT(modctor_,name)(void) __attribute__((__constructor__));\ 130static void __CONCAT(modctor_,name)(void) __attribute__((__constructor__));\
131static void __CONCAT(modctor_,name)(void) \ 131static void __CONCAT(modctor_,name)(void) \
132{ \ 132{ \
133 extern struct modinfo_boot_chain modinfo_boot_chain; \ 133 extern struct modinfo_boot_chain modinfo_boot_chain; \
134 if (cold) { \ 134 if (cold) { \
135 struct modinfo_chain *mc = &__CONCAT(mc,name); \ 135 struct modinfo_chain *mc = &__CONCAT(mc,name); \
136 LIST_INSERT_HEAD(&modinfo_boot_chain, mc, mc_entries); \ 136 LIST_INSERT_HEAD(&modinfo_boot_chain, mc, mc_entries); \
137 } \ 137 } \
138} \ 138} \
139 \ 139 \
140static void __CONCAT(moddtor_,name)(void) __attribute__((__destructor__));\ 140static void __CONCAT(moddtor_,name)(void) __attribute__((__destructor__));\
141static void __CONCAT(moddtor_,name)(void) \ 141static void __CONCAT(moddtor_,name)(void) \
142{ \ 142{ \
143 struct modinfo_chain *mc = &__CONCAT(mc,name); \ 143 struct modinfo_chain *mc = &__CONCAT(mc,name); \
144 if (cold) { \ 144 if (cold) { \
145 LIST_REMOVE(mc, mc_entries); \ 145 LIST_REMOVE(mc, mc_entries); \
146 } \ 146 } \
147} 147}
148 148
149#else /* RUMP_USE_CTOR */ 149#else /* RUMP_USE_CTOR */
150 150
151#define _MODULE_REGISTER(name) __link_set_add_rodata(modules, __CONCAT(name,_modinfo)); 151#define _MODULE_REGISTER(name) __link_set_add_rodata(modules, __CONCAT(name,_modinfo));
152 152
153#endif /* RUMP_USE_CTOR */ 153#endif /* RUMP_USE_CTOR */
154 154
155#define MODULE(class, name, required) \ 155#define MODULE(class, name, required) \
156 MODULE_ALIAS(class, name, required, NULL) 156 MODULE_WITH_ALIAS(class, name, required, NULL)
157 157
158#define MODULE_ALIAS(class, name, required, aliases) \ 158#define MODULE_WITH_ALIAS(class, name, required, aliases) \
159static int __CONCAT(name,_modcmd)(modcmd_t, void *); \ 159static int __CONCAT(name,_modcmd)(modcmd_t, void *); \
160static const char * const * __CONCAT(name,_aliases) = { aliases }; \ 160static const char * const * __CONCAT(name,_aliases) = { aliases }; \
161static const modinfo_t __CONCAT(name,_modinfo) = { \ 161static const modinfo_t __CONCAT(name,_modinfo) = { \
162 .mi_version = __NetBSD_Version__, \ 162 .mi_version = __NetBSD_Version__, \
163 .mi_class = (class), \ 163 .mi_class = (class), \
164 .mi_modcmd = __CONCAT(name,_modcmd), \ 164 .mi_modcmd = __CONCAT(name,_modcmd), \
165 .mi_name = __STRING(name), \ 165 .mi_name = __STRING(name), \
166 .mi_aliases = (__CONCAT(name,_aliases)), \ 166 .mi_aliases = __CONCAT(name,_aliases), \
167 .mi_required = (required) \ 167 .mi_required = (required) \
168}; \ 168}; \
169_MODULE_REGISTER(name) 169_MODULE_REGISTER(name)
170 170
171TAILQ_HEAD(modlist, module); 171TAILQ_HEAD(modlist, module);
172 172
173extern struct vm_map *module_map; 173extern struct vm_map *module_map;
174extern u_int module_count; 174extern u_int module_count;
175extern u_int module_builtinlist; 175extern u_int module_builtinlist;
176extern struct modlist module_list; 176extern struct modlist module_list;
177extern struct modlist module_builtins; 177extern struct modlist module_builtins;
178extern u_int module_gen; 178extern u_int module_gen;
179 179
180void module_init(void); 180void module_init(void);
181void module_start_unload_thread(void); 181void module_start_unload_thread(void);
182void module_builtin_require_force(void); 182void module_builtin_require_force(void);
183void module_init_md(void); 183void module_init_md(void);
184void module_init_class(modclass_t); 184void module_init_class(modclass_t);
185int module_prime(const char *, void *, size_t); 185int module_prime(const char *, void *, size_t);
186 186
187bool module_compatible(int, int); 187bool module_compatible(int, int);
188int module_load(const char *, int, prop_dictionary_t, modclass_t); 188int module_load(const char *, int, prop_dictionary_t, modclass_t);
189int module_builtin_add(modinfo_t * const *, size_t, bool); 189int module_builtin_add(modinfo_t * const *, size_t, bool);
190int module_builtin_remove(modinfo_t *, bool); 190int module_builtin_remove(modinfo_t *, bool);
191int module_autoload(const char *, modclass_t); 191int module_autoload(const char *, modclass_t);
192int module_unload(const char *); 192int module_unload(const char *);
193int module_hold(const char *); 193int module_hold(const char *);
194void module_rele(const char *); 194void module_rele(const char *);
195int module_find_section(const char *, void **, size_t *); 195int module_find_section(const char *, void **, size_t *);
196void module_thread_kick(void); 196void module_thread_kick(void);
197void module_load_vfs_init(void); 197void module_load_vfs_init(void);
198 198
199void module_whatis(uintptr_t, void (*)(const char *, ...) 199void module_whatis(uintptr_t, void (*)(const char *, ...)
200 __printflike(1, 2)); 200 __printflike(1, 2));
201void module_print_list(void (*)(const char *, ...) __printflike(1, 2)); 201void module_print_list(void (*)(const char *, ...) __printflike(1, 2));
202 202
203#ifdef _MODULE_INTERNAL 203#ifdef _MODULE_INTERNAL
204extern 204extern
205int (*module_load_vfs_vec)(const char *, int, bool, module_t *, 205int (*module_load_vfs_vec)(const char *, int, bool, module_t *,
206 prop_dictionary_t *); 206 prop_dictionary_t *);
207int module_load_vfs(const char *, int, bool, module_t *, 207int module_load_vfs(const char *, int, bool, module_t *,
208 prop_dictionary_t *); 208 prop_dictionary_t *);
209void module_error(const char *, ...) __printflike(1, 2); 209void module_error(const char *, ...) __printflike(1, 2);
210void module_print(const char *, ...) __printflike(1, 2); 210void module_print(const char *, ...) __printflike(1, 2);
211#endif /* _MODULE_INTERNAL */ 211#endif /* _MODULE_INTERNAL */
212 212
213#define MODULE_BASE_SIZE 64 213#define MODULE_BASE_SIZE 64
214extern char module_base[MODULE_BASE_SIZE]; 214extern char module_base[MODULE_BASE_SIZE];
215extern const char *module_machine; 215extern const char *module_machine;
216 216
217#else /* _KERNEL */ 217#else /* _KERNEL */
218 218
219#include <stdint.h> 219#include <stdint.h>
220 220
221#endif /* _KERNEL */ 221#endif /* _KERNEL */
222 222
223typedef struct modctl_load { 223typedef struct modctl_load {
224 const char *ml_filename; 224 const char *ml_filename;
225 225
226#define MODCTL_NO_PROP 0x2 226#define MODCTL_NO_PROP 0x2
227#define MODCTL_LOAD_FORCE 0x1 227#define MODCTL_LOAD_FORCE 0x1
228 int ml_flags; 228 int ml_flags;
229 229
230 const char *ml_props; 230 const char *ml_props;
231 size_t ml_propslen; 231 size_t ml_propslen;
232} modctl_load_t; 232} modctl_load_t;
233 233
234typedef enum modctl { 234typedef enum modctl {
235 MODCTL_LOAD, /* modctl_load_t *ml */ 235 MODCTL_LOAD, /* modctl_load_t *ml */
236 MODCTL_UNLOAD, /* char *name */ 236 MODCTL_UNLOAD, /* char *name */
237 MODCTL_STAT, /* struct iovec *buffer */ 237 MODCTL_STAT, /* struct iovec *buffer */
238 MODCTL_EXISTS /* enum: 0: load, 1: autoload */ 238 MODCTL_EXISTS /* enum: 0: load, 1: autoload */
239} modctl_t; 239} modctl_t;
240 240
241/* 241/*
242 * This structure intentionally has the same layout for 32 and 64 242 * This structure intentionally has the same layout for 32 and 64
243 * bit builds. 243 * bit builds.
244 */ 244 */
245typedef struct modstat { 245typedef struct modstat {
246 char ms_name[MAXMODNAME]; 246 char ms_name[MAXMODNAME];
247 char ms_required[MAXMODNAME * MAXMODDEPS]; 247 char ms_required[MAXMODNAME * MAXMODDEPS];
248 uint64_t ms_addr; 248 uint64_t ms_addr;
249 modsrc_t ms_source; 249 modsrc_t ms_source;
250 modclass_t ms_class; 250 modclass_t ms_class;
251 u_int ms_size; 251 u_int ms_size;
252 u_int ms_refcnt; 252 u_int ms_refcnt;
253 u_int ms_flags; 253 u_int ms_flags;
254 u_int ms_reserved[3]; 254 u_int ms_reserved[3];
255} modstat_t; 255} modstat_t;
256 256
257int modctl(int, void *); 257int modctl(int, void *);
258 258
259#ifdef _KERNEL 259#ifdef _KERNEL
260/* attention: pointers passed are userland pointers!, 260/* attention: pointers passed are userland pointers!,
261 see modctl_load_t */ 261 see modctl_load_t */
262int handle_modctl_load(const char *, int, const char *, size_t); 262int handle_modctl_load(const char *, int, const char *, size_t);
263#endif 263#endif
264 264
265#endif /* !_SYS_MODULE_H_ */ 265#endif /* !_SYS_MODULE_H_ */