Make MOD_* macros almost consistent:

Use the name argument almost the same in all LKM types.  Maintain
the current behavior for the external (e.g., modstat) name for DEV,
EXEC, and MISC types being #name ## "_mod" and SYCALL and VFS only
#name.  This is a candidate for change and I vote just the name without
the "_mod".

Change the DISPATCH macro to MOD_DISPATCH for consistency with the
other macros.

Add an LKM_ANON #define to eliminate the magic -1 and associated
signed/unsigned warnings.

Add MOD_PRIVATE to support wcd.c's poking around in the lkm structure.

Change source in tree to use the new interface.

Reviewed by:	Bruce Evans
This commit is contained in:
Peter Dufault 1997-04-06 11:14:13 +00:00
parent 952d112864
commit 0ddf9be1f0
16 changed files with 98 additions and 74 deletions

View File

@ -25,7 +25,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id$
* $Id: star_saver.c,v 1.10 1997/02/22 12:49:22 peter Exp $
*/
#include <sys/param.h>
@ -112,6 +112,6 @@ star_saver_unload(struct lkm_table *lkmtp, int cmd)
int
star_saver_mod(struct lkm_table *lkmtp, int cmd, int ver)
{
DISPATCH(lkmtp, cmd, ver, star_saver_load, star_saver_unload,
lkm_nullcmd);
MOD_DISPATCH(star_saver, lkmtp, cmd, ver,
star_saver_load, star_saver_unload, lkm_nullcmd);
}

View File

@ -37,18 +37,11 @@
*
*/
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/proc.h>
#include <sys/systm.h>
#include <sys/sysproto.h>
#include <sys/conf.h>
#include <sys/mount.h>
#include <sys/exec.h>
#include <sys/sysent.h>
#include <sys/lkm.h>
#include <a.out.h>
#include <sys/file.h>
#include <sys/errno.h>
/* XXX this should be in a header. */
extern int misccall __P((struct proc *p, void *uap, int retval[]));
@ -186,5 +179,6 @@ struct lkm_table *lkmtp;
int cmd;
int ver;
{
DISPATCH(lkmtp, cmd, ver, misc_load, misc_load, lkm_nullcmd);
MOD_DISPATCH(misc, lkmtp, cmd, ver,
misc_load, misc_load, lkm_nullcmd);
}

View File

@ -259,7 +259,7 @@ MOD_DEV (joy, LM_DT_CHAR, CDEV_MAJOR, &joy_cdevsw);
static struct isa_device dev = {0, &joydriver, IO_GAME, 0, -1, (caddr_t) 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0};
int
static int
joy_load (struct lkm_table *lkmtp, int cmd)
{
if (joyprobe (&dev)) {
@ -273,22 +273,24 @@ joy_load (struct lkm_table *lkmtp, int cmd)
}
}
int
static int
joy_unload (struct lkm_table *lkmtp, int cmd)
{
uprintf ("Joystick driver unloaded\n");
return 0;
}
int
static int
joy_stat (struct lkm_table *lkmtp, int cmd)
{
return 0;
}
int
joy_mod (struct lkm_table *lkmtp, int cmd, int ver)
{
#define _module joy_module
DISPATCH(lkmtp, cmd, ver, joy_load, joy_unload, joy_stat);
MOD_DISPATCH(joy, lkmtp, cmd, ver,
joy_load, joy_unload, joy_stat);
}
#endif /* JOY_MODULE */

View File

@ -25,7 +25,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id$
* $Id: star_saver.c,v 1.10 1997/02/22 12:49:22 peter Exp $
*/
#include <sys/param.h>
@ -112,6 +112,6 @@ star_saver_unload(struct lkm_table *lkmtp, int cmd)
int
star_saver_mod(struct lkm_table *lkmtp, int cmd, int ver)
{
DISPATCH(lkmtp, cmd, ver, star_saver_load, star_saver_unload,
lkm_nullcmd);
MOD_DISPATCH(star_saver, lkmtp, cmd, ver,
star_saver_load, star_saver_unload, lkm_nullcmd);
}

View File

@ -1067,7 +1067,8 @@ static int atapi_unload (struct lkm_table *lkmtp, int cmd)
*/
int atapi_mod (struct lkm_table *lkmtp, int cmd, int ver)
{
DISPATCH (lkmtp, cmd, ver, atapi_load, atapi_unload, lkm_nullcmd);
MOD_DISPATCH (atapi, lkmtp, cmd, ver,
atapi_load, atapi_unload, lkm_nullcmd);
}
#endif /* ATAPI_MODULE */

View File

@ -259,7 +259,7 @@ MOD_DEV (joy, LM_DT_CHAR, CDEV_MAJOR, &joy_cdevsw);
static struct isa_device dev = {0, &joydriver, IO_GAME, 0, -1, (caddr_t) 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0};
int
static int
joy_load (struct lkm_table *lkmtp, int cmd)
{
if (joyprobe (&dev)) {
@ -273,22 +273,24 @@ joy_load (struct lkm_table *lkmtp, int cmd)
}
}
int
static int
joy_unload (struct lkm_table *lkmtp, int cmd)
{
uprintf ("Joystick driver unloaded\n");
return 0;
}
int
static int
joy_stat (struct lkm_table *lkmtp, int cmd)
{
return 0;
}
int
joy_mod (struct lkm_table *lkmtp, int cmd, int ver)
{
#define _module joy_module
DISPATCH(lkmtp, cmd, ver, joy_load, joy_unload, joy_stat);
MOD_DISPATCH(joy, lkmtp, cmd, ver,
joy_load, joy_unload, joy_stat);
}
#endif /* JOY_MODULE */

View File

@ -312,8 +312,7 @@ qcam_stat (struct lkm_table *lkmtp, int cmd)
int
qcam_mod (struct lkm_table *lkmtp, int cmd, int ver)
{
#define _module qcam_module
DISPATCH(lkmtp, cmd, ver,
MOD_DISPATCH(qcam, lkmtp, cmd, ver,
qcam_load, qcam_unload, qcam_stat);
}

View File

@ -1179,14 +1179,16 @@ int wcd_mod (struct lkm_table *lkmtp, int cmd, int ver)
if (err)
return err;
/* XXX Poking around in the LKM internals like this is bad.
*/
/* Register the cdevsw entry. */
lkmtp->private.lkm_dev = &rwcd_module;
lkmtp->private.lkm_dev = & MOD_PRIVATE(rwcd);
err = lkmdispatch (lkmtp, cmd);
if (err)
return err;
/* Register the bdevsw entry. */
lkmtp->private.lkm_dev = &wcd_module;
lkmtp->private.lkm_dev = & MOD_PRIVATE(wcd);
return lkmdispatch (lkmtp, cmd);
}
#endif /* WCD_MODULE */

View File

@ -259,7 +259,7 @@ MOD_DEV (joy, LM_DT_CHAR, CDEV_MAJOR, &joy_cdevsw);
static struct isa_device dev = {0, &joydriver, IO_GAME, 0, -1, (caddr_t) 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0};
int
static int
joy_load (struct lkm_table *lkmtp, int cmd)
{
if (joyprobe (&dev)) {
@ -273,22 +273,24 @@ joy_load (struct lkm_table *lkmtp, int cmd)
}
}
int
static int
joy_unload (struct lkm_table *lkmtp, int cmd)
{
uprintf ("Joystick driver unloaded\n");
return 0;
}
int
static int
joy_stat (struct lkm_table *lkmtp, int cmd)
{
return 0;
}
int
joy_mod (struct lkm_table *lkmtp, int cmd, int ver)
{
#define _module joy_module
DISPATCH(lkmtp, cmd, ver, joy_load, joy_unload, joy_stat);
MOD_DISPATCH(joy, lkmtp, cmd, ver,
joy_load, joy_unload, joy_stat);
}
#endif /* JOY_MODULE */

View File

@ -30,7 +30,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: kern_lkm.c,v 1.38 1997/03/23 03:36:20 bde Exp $
* $Id: kern_lkm.c,v 1.39 1997/03/24 11:24:35 bde Exp $
*/
#include <sys/param.h>
@ -539,7 +539,7 @@ _lkm_syscall(lkmtp, cmd)
/* don't load twice! */
if (lkmexists(lkmtp))
return(EEXIST);
if ((i = args->lkm_offset) == -1) { /* auto */
if ((i = args->lkm_offset) == LKM_ANON) { /* auto */
/*
* Search the table looking for a slot...
*/
@ -707,7 +707,7 @@ _lkm_dev(lkmtp, cmd)
return(EEXIST);
switch(args->lkm_devtype) {
case LM_DT_BLOCK:
if ((i = args->lkm_offset) == -1)
if ((i = args->lkm_offset) == LKM_ANON)
descrip = (dev_t) -1;
else
descrip = makedev(args->lkm_offset,0);
@ -719,7 +719,7 @@ _lkm_dev(lkmtp, cmd)
break;
case LM_DT_CHAR:
if ((i = args->lkm_offset) == -1)
if ((i = args->lkm_offset) == LKM_ANON)
descrip = (dev_t) -1;
else
descrip = makedev(args->lkm_offset,0);
@ -817,7 +817,7 @@ _lkm_exec(lkmtp, cmd)
/* don't load twice! */
if (lkmexists(lkmtp))
return(EEXIST);
if ((i = args->lkm_offset) == -1) { /* auto */
if ((i = args->lkm_offset) == LKM_ANON) { /* auto */
/*
* Search the table looking for a slot...
*/

View File

@ -25,7 +25,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id$
* $Id: star_saver.c,v 1.10 1997/02/22 12:49:22 peter Exp $
*/
#include <sys/param.h>
@ -112,6 +112,6 @@ star_saver_unload(struct lkm_table *lkmtp, int cmd)
int
star_saver_mod(struct lkm_table *lkmtp, int cmd, int ver)
{
DISPATCH(lkmtp, cmd, ver, star_saver_load, star_saver_unload,
lkm_nullcmd);
MOD_DISPATCH(star_saver, lkmtp, cmd, ver,
star_saver_load, star_saver_unload, lkm_nullcmd);
}

View File

@ -12,7 +12,7 @@
*
* This software is provided ``AS IS'' without any warranties of any kind.
*
* $Id$
* $Id: ip_fw.c,v 1.55 1997/02/22 09:41:32 peter Exp $
*/
/*
@ -823,6 +823,7 @@ ipfw_unload(struct lkm_table *lkmtp, int cmd)
int
ipfw_mod(struct lkm_table *lkmtp, int cmd, int ver)
{
DISPATCH(lkmtp, cmd, ver, ipfw_load, ipfw_unload, lkm_nullcmd);
MOD_DISPATCH(ipfw, lkmtp, cmd, ver,
ipfw_load, ipfw_unload, lkm_nullcmd);
}
#endif

View File

@ -213,7 +213,8 @@ pcic_handle(struct lkm_table *lkmtp, int cmd)
int
pcic_mod(struct lkm_table *lkmtp, int cmd, int ver)
{
DISPATCH(lkmtp,cmd,ver,pcic_handle,pcic_handle,lkm_nullcmd);
MOD_DISPATCH(pcic, lkmtp, cmd, ver,
pcic_handle, pcic_handle, lkm_nullcmd);
}
/*

View File

@ -39,7 +39,7 @@
* SUCH DAMAGE.
*
* @(#)kernel.h 8.3 (Berkeley) 1/21/94
* $Id: kernel.h,v 1.25 1997/02/22 09:45:25 peter Exp $
* $Id: kernel.h,v 1.26 1997/03/22 08:03:45 bde Exp $
*/
#ifndef _SYS_KERNEL_H_
@ -249,7 +249,7 @@ void kproc_start __P((void *udata));
{ return EINVAL; } \
int \
name ## _mod(struct lkm_table *lkmtp, int cmd, int ver) { \
DISPATCH(lkmtp, cmd, ver, name ## _load, name ## _unload, \
MOD_DISPATCH(name, lkmtp, cmd, ver, name ## _load, name ## _unload, \
lkm_nullcmd); }
#else /* PSEUDO_LKM */

View File

@ -34,7 +34,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
* $Id: lkm.h,v 1.15 1997/02/22 09:45:30 peter Exp $
*/
#ifndef _SYS_LKM_H_
@ -67,7 +67,7 @@ typedef enum loadmod {
struct lkm_syscall {
MODTYPE lkm_type;
int lkm_ver;
char *lkm_name;
const char *lkm_name;
u_long lkm_offset; /* save/assign area */
struct sysent *lkm_sysent;
struct sysent lkm_oldent; /* save area for unload */
@ -79,7 +79,7 @@ struct lkm_syscall {
struct lkm_vfs {
MODTYPE lkm_type;
int lkm_ver;
char *lkm_name;
const char *lkm_name;
u_long lkm_offset;
struct linker_set *lkm_vnodeops;
struct vfsconf *lkm_vfsconf;
@ -99,7 +99,7 @@ typedef enum devtype {
struct lkm_dev {
MODTYPE lkm_type;
int lkm_ver;
char *lkm_name;
const char *lkm_name;
u_long lkm_offset;
DEVTYPE lkm_devtype;
union {
@ -119,7 +119,7 @@ struct lkm_dev {
struct lkm_strmod {
MODTYPE lkm_type;
int lkm_ver;
char *lkm_name;
const char *lkm_name;
u_long lkm_offset;
/*
* Removed: future release
@ -132,7 +132,7 @@ struct lkm_strmod {
struct lkm_exec {
MODTYPE lkm_type;
int lkm_ver;
char *lkm_name;
const char *lkm_name;
u_long lkm_offset;
const struct execsw *lkm_exec;
struct execsw lkm_oldexec;
@ -144,7 +144,7 @@ struct lkm_exec {
struct lkm_misc {
MODTYPE lkm_type;
int lkm_ver;
char *lkm_name;
const char *lkm_name;
u_long lkm_offset;
};
@ -154,7 +154,7 @@ struct lkm_misc {
struct lkm_any {
MODTYPE lkm_type;
int lkm_ver;
char *lkm_name;
const char *lkm_name;
u_long lkm_offset;
};
@ -208,25 +208,35 @@ struct lkm_table {
#define LKM_E_UNLOAD 2
#define LKM_E_STAT 3
/* Flag to indicate that LKM should select the slot, etc. Supported by:
* devslot in MOD_DEV
*/
#define LKM_ANON ((u_long)-1)
/* XXX wcd.c pokes around in the lkm private structure, so until that
* is fixed here is a way to export the structure name.
*/
#define MOD_PRIVATE(name) name ## _mod_struct
#define MOD_DECL(name) \
static int name ## _load __P((struct lkm_table *lkmtp, int cmd)); \
static int name ## _unload __P((struct lkm_table *lkmtp, int cmd)); \
int name ## _mod __P((struct lkm_table *lkmtp, int cmd, int ver)) \
#define MOD_SYSCALL(name,callslot,sysentp) \
static struct lkm_syscall _module = { \
static struct lkm_syscall MOD_PRIVATE(name) = { \
LM_SYSCALL, \
LKM_VERSION, \
name, \
#name, \
callslot, \
sysentp \
}
#define MOD_VFS(name,vnodeops,vfsconf) \
static struct lkm_vfs _module = { \
static struct lkm_vfs MOD_PRIVATE(name) = { \
LM_VFS, \
LKM_VERSION, \
name, \
#name, \
0, \
vnodeops, \
vfsconf \
@ -234,18 +244,18 @@ struct lkm_table {
#define MOD_DEV(name,devtype,devslot,devp) \
MOD_DECL(name); \
static struct lkm_dev name ## _module = { \
static struct lkm_dev MOD_PRIVATE(name) = { \
LM_DEV, \
LKM_VERSION, \
#name ## "_mod", \
devslot, \
devtype, \
(void *)devp \
{ (void *)devp } \
}
#define MOD_EXEC(name,execslot,execsw) \
MOD_DECL(name); \
static struct lkm_exec _module = { \
static struct lkm_exec MOD_PRIVATE(name) = { \
LM_EXEC, \
LKM_VERSION, \
#name ## "_mod", \
@ -255,28 +265,29 @@ struct lkm_table {
#define MOD_MISC(name) \
MOD_DECL(name); \
static struct lkm_misc _module = { \
static struct lkm_misc MOD_PRIVATE(name) = { \
LM_MISC, \
LKM_VERSION, \
#name ## "_mod" \
}
/*
* DISPATCH -- body function for use in module entry point function;
* MOD_DISPATCH -- body function for use in module entry point function;
* generally, the function body will consist entirely of a single
* DISPATCH line.
* MOD_DISPATCH line.
*
* Call load/unload/stat on each corresponding entry instance. "cmd" is
* passed to each function so that a single function can be used if desired.
*
*/
#define DISPATCH(lkmtp,cmd,ver,load,unload,stat) \
#define MOD_DISPATCH(name,lkmtp,cmd,ver,load,unload,stat) \
if (ver != LKM_VERSION) \
return EINVAL; /* version mismatch */ \
switch (cmd) { \
int error; \
case LKM_E_LOAD: \
lkmtp->private.lkm_any = (struct lkm_any *)&_module; \
lkmtp->private.lkm_any = \
(struct lkm_any *)& MOD_PRIVATE(name) ; \
if (lkmexists(lkmtp)) /* !!! */ \
return EEXIST; \
if ((error = load(lkmtp, cmd))) \
@ -293,6 +304,12 @@ struct lkm_table {
} \
return lkmdispatch(lkmtp, cmd);
/* Provide a backward compatible stub that will generate compile time errors.
* When fixing, prefer MOD_DISPATCH to be consistent with the others.
*/
#define DISPATCH(name,lkmtp,cmd,ver,load,unload,stat) \
MOD_DISPATCH(name,lkmtp,cmd,ver,load,unload,stat)
int lkmdispatch __P((struct lkm_table *lkmtp, int cmd));
int lkmexists __P((struct lkm_table *lkmtp));
int lkm_nullcmd __P((struct lkm_table *lkmtp, int cmd));
@ -325,7 +342,7 @@ int lkm_nullcmd __P((struct lkm_table *lkmtp, int cmd));
*/
struct lmc_resrv {
u_long size; /* IN: size of module to reserve */
char *name; /* IN: name (must be provided */
const char *name; /* IN: name (must be provided */
int slot; /* OUT: allocated slot (module ID) */
u_long addr; /* OUT: Link-to address */
};
@ -355,7 +372,7 @@ struct lmc_load {
*/
struct lmc_unload {
int id; /* IN: module ID to unload */
char *name; /* IN: module name to unload if id -1 */
const char *name; /* IN: module name to unload if id -1 */
int status; /* OUT: status of operation */
};

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)mount.h 8.21 (Berkeley) 5/20/95
* $Id: mount.h,v 1.40 1997/03/02 17:53:28 bde Exp $
* $Id: mount.h,v 1.41 1997/03/03 11:55:47 bde Exp $
*/
#ifndef _SYS_MOUNT_H_
@ -355,10 +355,13 @@ struct vfsops {
flags, \
}; \
extern struct linker_set MODVNOPS; \
MOD_VFS(#fsname,&MODVNOPS,&_fs_vfsconf); \
MOD_VFS(fsname,&MODVNOPS,&_fs_vfsconf); \
extern int \
fsname ## _mod __P((struct lkm_table *, int, int)); \
int \
fsname ## _mod(struct lkm_table *lkmtp, int cmd, int ver) { \
DISPATCH(lkmtp, cmd, ver, lkm_nullcmd, lkm_nullcmd, lkm_nullcmd); }
MOD_DISPATCH(fsname, \
lkmtp, cmd, ver, lkm_nullcmd, lkm_nullcmd, lkm_nullcmd); }
#else
#define VFS_SET(vfsops, fsname, index, flags) \