summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordillon <dillon@FreeBSD.org>1999-01-29 08:12:49 +0000
committerdillon <dillon@FreeBSD.org>1999-01-29 08:12:49 +0000
commitc9d851cd134f45e297e380c497f352c0dc18bc0c (patch)
treea8718cc3ddeeb18620b82d02f4ec008929e80a7a
parent82b636d3e35bfca1711cdd6c6d1e098b6ad99fea (diff)
downloadFreeBSD-src-c9d851cd134f45e297e380c497f352c0dc18bc0c.zip
FreeBSD-src-c9d851cd134f45e297e380c497f352c0dc18bc0c.tar.gz
Commit a solution for the SYSINIT vs C_SYSINIT conundrum. The
problem and solution is outlined in the comments, but basically we needed a way to allow the SYSINIT mechanism to handle const void * arguments and function pointers as well as non-const arguments and function pointers while still maintaining the compiler's ability to issue warnings if you try to use a bad combination.
-rw-r--r--sys/sys/kernel.h48
1 files changed, 28 insertions, 20 deletions
diff --git a/sys/sys/kernel.h b/sys/sys/kernel.h
index d7f1857..52c54fb 100644
--- a/sys/sys/kernel.h
+++ b/sys/sys/kernel.h
@@ -39,7 +39,7 @@
* SUCH DAMAGE.
*
* @(#)kernel.h 8.3 (Berkeley) 1/21/94
- * $Id: kernel.h,v 1.50 1999/01/28 00:57:54 dillon Exp $
+ * $Id: kernel.h,v 1.51 1999/01/28 17:30:51 dillon Exp $
*/
#ifndef _SYS_KERNEL_H_
@@ -180,28 +180,33 @@ typedef enum sysinit_elem_type {
* want two which is why this code is if'd out, but we definitely want
* to discern SYSINIT's which take non-constant data pointers and
* SYSINIT's which take constant data pointers,
+ *
+ * The C_* macros take functions expecting const void * arguments
+ * while the non-C_* macros take functions expecting just void * arguments.
+ *
+ * With -Wcast-qual on, the compiler issues warnings:
+ * - if we pass non-const data or functions taking non-const data
+ * to a C_* macro.
+ *
+ * - if we pass const data to the normal macros
+ *
+ * However, no warning is issued if we pass a function taking const data
+ * through a normal non-const macro. This is ok because the function is
+ * saying it won't modify the data so we don't care whether the data is
+ * modifiable or not.
*/
-struct sysinit {
- unsigned int subsystem; /* subsystem identifier*/
- unsigned int order; /* init order within subsystem*/
- void (*func) __P((void *)); /* function */
- void *udata; /* multiplexer/argument */
- si_elem_t type; /* sysinit_elem_type*/
-};
-#if 0
+typedef void (*sysinit_nfunc_t) __P((void *));
+typedef void (*sysinit_cfunc_t) __P((const void *));
-struct c_sysinit {
+struct sysinit {
unsigned int subsystem; /* subsystem identifier*/
unsigned int order; /* init order within subsystem*/
- void (*func) __P((const void *)); /* function */
+ sysinit_cfunc_t func; /* function */
const void *udata; /* multiplexer/argument */
si_elem_t type; /* sysinit_elem_type*/
};
-#endif
-
-
/*
* Default: no special processing
*
@@ -210,8 +215,11 @@ struct c_sysinit {
* At the moment it is no different from SYSINIT and thus
* still results in warnings.
*
+ * The casts are necessary to have the compiler produce the
+ * correct warnings when -Wcast-qual is used.
+ *
*/
-#define SYSINIT(uniquifier, subsystem, order, func, ident) \
+#define C_SYSINIT(uniquifier, subsystem, order, func, ident) \
static struct sysinit uniquifier ## _sys_init = { \
subsystem, \
order, \
@@ -221,13 +229,13 @@ struct c_sysinit {
}; \
DATA_SET(sysinit_set,uniquifier ## _sys_init);
-#define C_SYSINIT(uniquifier, subsystem, order, func, ident) \
- SYSINIT(uniquifier, subsystem, order, func, ident)
+#define SYSINIT(uniquifier, subsystem, order, func, ident) \
+ C_SYSINIT(uniquifier, subsystem, order, (sysinit_cfunc_t)(sysinit_nfunc_t)func, (void *)ident)
/*
* Called on module unload: no special processing
*/
-#define SYSUNINIT(uniquifier, subsystem, order, func, ident) \
+#define C_SYSUNINIT(uniquifier, subsystem, order, func, ident) \
static struct sysinit uniquifier ## _sys_uninit = { \
subsystem, \
order, \
@@ -237,8 +245,8 @@ struct c_sysinit {
}; \
DATA_SET(sysuninit_set,uniquifier ## _sys_uninit)
-#define C_SYSUNINIT(uniquifier, subsystem, order, func, ident) \
- SYSUNINIT(uniquifier, subsystem, order, func, ident)
+#define SYSUNINIT(uniquifier, subsystem, order, func, ident) \
+ C_SYSUNINIT(uniquifier, subsystem, order, (sysinit_cfunc_t)(sysinit_nfunc_t)func, (void *)ident)
/*
* Call 'fork()' before calling '(*func)(ident)';
OpenPOWER on IntegriCloud