1994-08-26 08:42:07 +00:00
|
|
|
/*-
|
1994-08-19 11:45:29 +00:00
|
|
|
* Copyright (c) 1992 Terrence R. Lambert.
|
1994-08-26 08:42:07 +00:00
|
|
|
* Copyright (c) 1994 Christopher G. Demetriou
|
1994-08-19 11:45:29 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Terrence R. Lambert.
|
|
|
|
* 4. The name Terrence R. Lambert may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior written
|
|
|
|
* permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY TERRENCE R. LAMBERT ``AS IS'' AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
1995-04-18 14:10:21 +00:00
|
|
|
*
|
1997-11-06 19:29:57 +00:00
|
|
|
* $Id: kern_lkm.c,v 1.44 1997/10/28 15:58:15 bde Exp $
|
1994-08-19 11:45:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1995-11-09 09:43:32 +00:00
|
|
|
#include <sys/sysproto.h>
|
1994-08-19 11:45:29 +00:00
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/conf.h>
|
1997-03-23 03:37:54 +00:00
|
|
|
#include <sys/fcntl.h>
|
1994-08-19 11:45:29 +00:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/mount.h>
|
1994-08-26 08:42:07 +00:00
|
|
|
#include <sys/sysent.h>
|
1994-08-19 11:45:29 +00:00
|
|
|
#include <sys/exec.h>
|
|
|
|
#include <sys/lkm.h>
|
1996-05-01 02:43:13 +00:00
|
|
|
#include <sys/vnode.h>
|
1995-12-08 11:19:42 +00:00
|
|
|
#ifdef DEVFS
|
|
|
|
#include <sys/devfsext.h>
|
|
|
|
#endif /*DEVFS*/
|
1994-08-19 11:45:29 +00:00
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_kern.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
#include <vm/vm_extern.h>
|
1994-08-19 11:45:29 +00:00
|
|
|
|
1995-11-29 10:49:16 +00:00
|
|
|
|
1994-08-19 11:45:29 +00:00
|
|
|
#define PAGESIZE 1024 /* kmem_alloc() allocation quantum */
|
|
|
|
|
|
|
|
#define LKM_ALLOC 0x01
|
|
|
|
#define LKM_WANT 0x02
|
|
|
|
|
|
|
|
#define LKMS_IDLE 0x00
|
|
|
|
#define LKMS_RESERVED 0x01
|
|
|
|
#define LKMS_LOADING 0x02
|
|
|
|
#define LKMS_LOADED 0x04
|
|
|
|
#define LKMS_UNLOADING 0x08
|
|
|
|
|
|
|
|
static int lkm_v = 0;
|
|
|
|
static int lkm_state = LKMS_IDLE;
|
|
|
|
|
|
|
|
#ifndef MAXLKMS
|
|
|
|
#define MAXLKMS 20
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct lkm_table lkmods[MAXLKMS]; /* table of loaded modules */
|
|
|
|
static struct lkm_table *curp; /* global for in-progress ops */
|
|
|
|
|
1995-11-09 09:43:32 +00:00
|
|
|
static int _lkm_dev __P((struct lkm_table *lkmtp, int cmd));
|
|
|
|
static int _lkm_exec __P((struct lkm_table *lkmtp, int cmd));
|
|
|
|
static int _lkm_vfs __P((struct lkm_table *lkmtp, int cmd));
|
|
|
|
static int _lkm_syscall __P((struct lkm_table *lkmtp, int cmd));
|
|
|
|
static void lkmunreserve __P((void));
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static d_open_t lkmcopen;
|
|
|
|
static d_close_t lkmcclose;
|
|
|
|
static d_ioctl_t lkmcioctl;
|
|
|
|
|
|
|
|
#define CDEV_MAJOR 32
|
1995-12-08 23:23:00 +00:00
|
|
|
static struct cdevsw lkmc_cdevsw =
|
1995-12-08 11:19:42 +00:00
|
|
|
{ lkmcopen, lkmcclose, noread, nowrite, /*32*/
|
|
|
|
lkmcioctl, nostop, nullreset, nodevtotty,
|
1997-09-14 02:52:18 +00:00
|
|
|
seltrue, nommap, NULL, "lkm", NULL, -1 };
|
1995-12-08 11:19:42 +00:00
|
|
|
|
|
|
|
|
1994-08-19 11:45:29 +00:00
|
|
|
/*ARGSUSED*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1994-08-19 11:45:29 +00:00
|
|
|
lkmcopen(dev, flag, devtype, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flag;
|
|
|
|
int devtype;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (minor(dev) != 0)
|
|
|
|
return(ENXIO); /* bad minor # */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use of the loadable kernel module device must be exclusive; we
|
|
|
|
* may try to remove this restriction later, but it's really no
|
|
|
|
* hardship.
|
|
|
|
*/
|
|
|
|
while (lkm_v & LKM_ALLOC) {
|
|
|
|
if (flag & FNONBLOCK) /* don't hang */
|
|
|
|
return(EBUSY);
|
|
|
|
lkm_v |= LKM_WANT;
|
|
|
|
/*
|
|
|
|
* Sleep pending unlock; we use tsleep() to allow
|
|
|
|
* an alarm out of the open.
|
|
|
|
*/
|
1994-10-02 17:35:40 +00:00
|
|
|
error = tsleep((caddr_t)&lkm_v, TTIPRI|PCATCH, "lkmopn", 0);
|
|
|
|
if (error)
|
1994-08-19 11:45:29 +00:00
|
|
|
return(error); /* leave LKM_WANT set -- no problem */
|
|
|
|
}
|
|
|
|
lkm_v |= LKM_ALLOC;
|
|
|
|
|
|
|
|
return(0); /* pseudo-device open */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unreserve the memory associated with the current loaded module; done on
|
|
|
|
* a coerced close of the lkm device (close on premature exit of modload)
|
|
|
|
* or explicitly by modload as a result of a link failure.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
lkmunreserve()
|
|
|
|
{
|
|
|
|
|
|
|
|
if (lkm_state == LKMS_IDLE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Actually unreserve the memory
|
|
|
|
*/
|
|
|
|
if (curp && curp->area) {
|
1996-05-24 01:39:50 +00:00
|
|
|
kmem_free(kernel_map, curp->area, curp->size);/**/
|
1994-08-19 11:45:29 +00:00
|
|
|
curp->area = 0;
|
1995-04-20 05:08:53 +00:00
|
|
|
if (curp->private.lkm_any != NULL)
|
|
|
|
curp->private.lkm_any = NULL;
|
1994-08-19 11:45:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lkm_state = LKMS_IDLE;
|
|
|
|
}
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1994-08-19 11:45:29 +00:00
|
|
|
lkmcclose(dev, flag, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flag;
|
|
|
|
int mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!(lkm_v & LKM_ALLOC)) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("LKM: close before open!\n");
|
|
|
|
#endif /* DEBUG */
|
|
|
|
return(EBADF);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do this before waking the herd... */
|
|
|
|
if (curp && !curp->used) {
|
|
|
|
/*
|
|
|
|
* If we close before setting used, we have aborted
|
|
|
|
* by way of error or by way of close-on-exit from
|
|
|
|
* a premature exit of "modload".
|
|
|
|
*/
|
|
|
|
lkmunreserve(); /* coerce state to LKM_IDLE */
|
|
|
|
}
|
|
|
|
|
|
|
|
lkm_v &= ~LKM_ALLOC;
|
|
|
|
wakeup((caddr_t)&lkm_v); /* thundering herd "problem" here */
|
|
|
|
|
|
|
|
return(0); /* pseudo-device closed */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1995-09-08 11:09:15 +00:00
|
|
|
lkmcioctl(dev, cmd, data, flag, p)
|
1994-08-19 11:45:29 +00:00
|
|
|
dev_t dev;
|
|
|
|
int cmd;
|
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
1995-09-08 11:09:15 +00:00
|
|
|
struct proc *p;
|
1994-08-19 11:45:29 +00:00
|
|
|
{
|
|
|
|
int err = 0;
|
1995-04-18 14:10:21 +00:00
|
|
|
int i;
|
1994-08-19 11:45:29 +00:00
|
|
|
struct lmc_resrv *resrvp;
|
|
|
|
struct lmc_loadbuf *loadbufp;
|
|
|
|
struct lmc_unload *unloadp;
|
|
|
|
struct lmc_stat *statp;
|
|
|
|
char istr[MAXLKMNAME];
|
|
|
|
|
|
|
|
switch(cmd) {
|
|
|
|
case LMRESERV: /* reserve pages for a module */
|
1995-11-29 17:45:59 +00:00
|
|
|
if ((flag & FWRITE) == 0 || securelevel > 0)
|
|
|
|
/* only allow this if writing and insecure */
|
1994-08-19 11:45:29 +00:00
|
|
|
return EPERM;
|
|
|
|
|
|
|
|
resrvp = (struct lmc_resrv *)data;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find a free slot.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < MAXLKMS; i++)
|
|
|
|
if (!lkmods[i].used)
|
|
|
|
break;
|
|
|
|
if (i == MAXLKMS) {
|
|
|
|
err = ENOMEM; /* no slots available */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
curp = &lkmods[i];
|
|
|
|
curp->id = i; /* self reference slot offset */
|
|
|
|
|
|
|
|
resrvp->slot = i; /* return slot */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get memory for module
|
|
|
|
*/
|
|
|
|
curp->size = resrvp->size;
|
1995-04-20 05:08:53 +00:00
|
|
|
|
1996-05-24 01:39:50 +00:00
|
|
|
curp->area = kmem_alloc(kernel_map, curp->size);/**/
|
1994-08-19 11:45:29 +00:00
|
|
|
|
|
|
|
curp->offset = 0; /* load offset */
|
|
|
|
|
|
|
|
resrvp->addr = curp->area; /* ret kernel addr */
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("LKM: LMRESERV (actual = 0x%08x)\n", curp->area);
|
|
|
|
printf("LKM: LMRESERV (adjusted = 0x%08x)\n",
|
|
|
|
trunc_page(curp->area));
|
|
|
|
#endif /* DEBUG */
|
|
|
|
lkm_state = LKMS_RESERVED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LMLOADBUF: /* Copy in; stateful, follows LMRESERV */
|
1995-11-29 17:45:59 +00:00
|
|
|
if ((flag & FWRITE) == 0 || securelevel > 0)
|
|
|
|
/* only allow this if writing and insecure */
|
1994-08-19 11:45:29 +00:00
|
|
|
return EPERM;
|
|
|
|
|
|
|
|
loadbufp = (struct lmc_loadbuf *)data;
|
|
|
|
i = loadbufp->cnt;
|
|
|
|
if ((lkm_state != LKMS_RESERVED && lkm_state != LKMS_LOADING)
|
|
|
|
|| i < 0
|
|
|
|
|| i > MODIOBUF
|
|
|
|
|| i > curp->size - curp->offset) {
|
|
|
|
err = ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy in buffer full of data */
|
1994-10-02 17:35:40 +00:00
|
|
|
err = copyin((caddr_t)loadbufp->data,
|
|
|
|
(caddr_t)curp->area + curp->offset, i);
|
|
|
|
if (err)
|
1994-08-19 11:45:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if ((curp->offset + i) < curp->size) {
|
|
|
|
lkm_state = LKMS_LOADING;
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("LKM: LMLOADBUF (loading @ %d of %d, i = %d)\n",
|
|
|
|
curp->offset, curp->size, i);
|
|
|
|
#endif /* DEBUG */
|
|
|
|
} else {
|
|
|
|
lkm_state = LKMS_LOADED;
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("LKM: LMLOADBUF (loaded)\n");
|
|
|
|
#endif /* DEBUG */
|
|
|
|
}
|
|
|
|
curp->offset += i;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LMUNRESRV: /* discard reserved pages for a module */
|
1995-11-29 17:45:59 +00:00
|
|
|
if ((flag & FWRITE) == 0 || securelevel > 0)
|
|
|
|
/* only allow this if writing and insecure */
|
1994-08-19 11:45:29 +00:00
|
|
|
return EPERM;
|
|
|
|
|
|
|
|
lkmunreserve(); /* coerce state to LKM_IDLE */
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("LKM: LMUNRESERV\n");
|
|
|
|
#endif /* DEBUG */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LMREADY: /* module loaded: call entry */
|
1995-11-29 17:45:59 +00:00
|
|
|
if ((flag & FWRITE) == 0 || securelevel > 0)
|
|
|
|
/* only allow this if writing or insecure */
|
1994-08-19 11:45:29 +00:00
|
|
|
return EPERM;
|
|
|
|
|
|
|
|
switch (lkm_state) {
|
|
|
|
case LKMS_LOADED:
|
|
|
|
break;
|
|
|
|
case LKMS_LOADING:
|
|
|
|
/* The remainder must be bss, so we clear it */
|
|
|
|
bzero((caddr_t)curp->area + curp->offset,
|
|
|
|
curp->size - curp->offset);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("lkm_state is %02x\n", lkm_state);
|
|
|
|
#endif /* DEBUG */
|
|
|
|
return ENXIO;
|
|
|
|
}
|
1995-04-20 05:08:53 +00:00
|
|
|
|
1995-11-09 09:43:32 +00:00
|
|
|
/* XXX gack */
|
|
|
|
curp->entry = (int (*) __P((struct lkm_table *, int, int)))
|
|
|
|
(*((int *)data));
|
1994-08-19 11:45:29 +00:00
|
|
|
|
|
|
|
/* call entry(load)... (assigns "private" portion) */
|
1994-10-02 17:35:40 +00:00
|
|
|
err = (*(curp->entry))(curp, LKM_E_LOAD, LKM_VERSION);
|
|
|
|
if (err) {
|
1994-08-19 11:45:29 +00:00
|
|
|
/*
|
|
|
|
* Module may refuse loading or may have a
|
|
|
|
* version mismatch...
|
|
|
|
*/
|
|
|
|
lkm_state = LKMS_UNLOADING; /* for lkmunreserve */
|
|
|
|
lkmunreserve(); /* free memory */
|
|
|
|
curp->used = 0; /* free slot */
|
|
|
|
break;
|
|
|
|
}
|
Fix module handling to stop oddball modules (if_ppp_mod, if_sl_mod,
if_tun_mod, etc...) from crashing the system. These modules are useful,
but because they don't yet have proper load()/unload() functions,
they can lead to panics: if, for example, you load the if_ppp module,
any user can panic the system by running modstat.
You can also hang the system outright if you try to unload the PPP
module too.
Changes are as follows:
- Save the name passed to us during the RESERVE stage for name matching
(we can't load if_ppp_mod twice: we've have two ppp0's and two ppp1's,
which is beyond strange). This makes the lkmexists() cheks somewhat
redundant, but there's no way around it that I can see.
- If we call the module entry point and find that we have no lkm_any
structure in our 'private' section, create a fake one. This keeps
modstat happy. We mark such modules as LM_UNKNOWN.
- Don't allow LM_UNLOAD modules to be unloaded: it just ain't
possible. (Unless someone wants to write a pppunattach() function. :( )
- In lkmunreserve(), mark private.lkm_any as NULL so we don't get
confused later. I think this is bogus, but I can't prove it.
XXX: the name matching used to keep the user from loading two
instances of the same module can easily be defeated simply by
changing the module name or, in the case of the oddball modules,
simply by renaming the module files. I haven't found a nice simple
way to tell one module from another.
1995-04-18 02:29:26 +00:00
|
|
|
/*
|
1995-04-20 05:08:53 +00:00
|
|
|
* It's possible for a user to load a module that doesn't
|
|
|
|
* initialize itself correctly. (You can even get away with
|
|
|
|
* using it for a while.) Unfortunately, we are faced with
|
|
|
|
* the following problems:
|
|
|
|
* - we can't tell a good module from a bad one until
|
|
|
|
* after we've run its entry function (if the private
|
|
|
|
* section is uninitalized after we return from the
|
|
|
|
* entry, then something's fishy)
|
|
|
|
* - now that we've called the entry function, we can't
|
|
|
|
* forcibly unload the module without risking a crash
|
|
|
|
* - since we don't know what the module's entry function
|
|
|
|
* did, we can't easily clean up the mess it may have
|
|
|
|
* made, so we can't know just how unstable the system
|
|
|
|
* may be
|
|
|
|
* So, being stuck between a rock and a hard place, we
|
|
|
|
* have no choice but to do this...
|
Fix module handling to stop oddball modules (if_ppp_mod, if_sl_mod,
if_tun_mod, etc...) from crashing the system. These modules are useful,
but because they don't yet have proper load()/unload() functions,
they can lead to panics: if, for example, you load the if_ppp module,
any user can panic the system by running modstat.
You can also hang the system outright if you try to unload the PPP
module too.
Changes are as follows:
- Save the name passed to us during the RESERVE stage for name matching
(we can't load if_ppp_mod twice: we've have two ppp0's and two ppp1's,
which is beyond strange). This makes the lkmexists() cheks somewhat
redundant, but there's no way around it that I can see.
- If we call the module entry point and find that we have no lkm_any
structure in our 'private' section, create a fake one. This keeps
modstat happy. We mark such modules as LM_UNKNOWN.
- Don't allow LM_UNLOAD modules to be unloaded: it just ain't
possible. (Unless someone wants to write a pppunattach() function. :( )
- In lkmunreserve(), mark private.lkm_any as NULL so we don't get
confused later. I think this is bogus, but I can't prove it.
XXX: the name matching used to keep the user from loading two
instances of the same module can easily be defeated simply by
changing the module name or, in the case of the oddball modules,
simply by renaming the module files. I haven't found a nice simple
way to tell one module from another.
1995-04-18 02:29:26 +00:00
|
|
|
*/
|
1995-04-20 05:08:53 +00:00
|
|
|
if (curp->private.lkm_any == NULL)
|
|
|
|
panic("loadable module initialization failed");
|
|
|
|
|
1994-08-19 11:45:29 +00:00
|
|
|
curp->used = 1;
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("LKM: LMREADY\n");
|
|
|
|
#endif /* DEBUG */
|
|
|
|
lkm_state = LKMS_IDLE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LMUNLOAD: /* unload a module */
|
1995-11-29 17:45:59 +00:00
|
|
|
if ((flag & FWRITE) == 0 || securelevel > 0)
|
|
|
|
/* only allow this if writing and insecure */
|
1994-08-19 11:45:29 +00:00
|
|
|
return EPERM;
|
|
|
|
|
|
|
|
unloadp = (struct lmc_unload *)data;
|
|
|
|
|
|
|
|
if ((i = unloadp->id) == -1) { /* unload by name */
|
|
|
|
/*
|
|
|
|
* Copy name and lookup id from all loaded
|
|
|
|
* modules. May fail.
|
|
|
|
*/
|
1994-10-02 17:35:40 +00:00
|
|
|
err =copyinstr(unloadp->name, istr, MAXLKMNAME-1, NULL);
|
|
|
|
if (err)
|
1994-08-19 11:45:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* look up id...
|
|
|
|
*/
|
|
|
|
for (i = 0; i < MAXLKMS; i++) {
|
|
|
|
if (!lkmods[i].used)
|
|
|
|
continue;
|
|
|
|
if (!strcmp(istr,
|
|
|
|
lkmods[i].private.lkm_any->lkm_name))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Range check the value; on failure, return EINVAL
|
|
|
|
*/
|
|
|
|
if (i < 0 || i >= MAXLKMS) {
|
|
|
|
err = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
curp = &lkmods[i];
|
|
|
|
|
|
|
|
if (!curp->used) {
|
|
|
|
err = ENOENT;
|
|
|
|
break;
|
|
|
|
}
|
1995-04-20 05:08:53 +00:00
|
|
|
|
|
|
|
/* call entry(unload) */
|
|
|
|
if ((*(curp->entry))(curp, LKM_E_UNLOAD, LKM_VERSION)) {
|
1994-08-19 11:45:29 +00:00
|
|
|
err = EBUSY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
lkm_state = LKMS_UNLOADING; /* non-idle for lkmunreserve */
|
|
|
|
lkmunreserve(); /* free memory */
|
|
|
|
curp->used = 0; /* free slot */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LMSTAT: /* stat a module by id/name */
|
|
|
|
/* allow readers and writers to stat */
|
|
|
|
|
|
|
|
statp = (struct lmc_stat *)data;
|
|
|
|
|
|
|
|
if ((i = statp->id) == -1) { /* stat by name */
|
|
|
|
/*
|
|
|
|
* Copy name and lookup id from all loaded
|
|
|
|
* modules.
|
|
|
|
*/
|
|
|
|
copystr(statp->name, istr, MAXLKMNAME-1, NULL);
|
|
|
|
/*
|
|
|
|
* look up id...
|
|
|
|
*/
|
|
|
|
for (i = 0; i < MAXLKMS; i++) {
|
|
|
|
if (!lkmods[i].used)
|
|
|
|
continue;
|
|
|
|
if (!strcmp(istr,
|
|
|
|
lkmods[i].private.lkm_any->lkm_name))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == MAXLKMS) { /* Not found */
|
|
|
|
err = ENOENT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Range check the value; on failure, return EINVAL
|
|
|
|
*/
|
|
|
|
if (i < 0 || i >= MAXLKMS) {
|
|
|
|
err = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
curp = &lkmods[i];
|
|
|
|
|
|
|
|
if (!curp->used) { /* Not found */
|
|
|
|
err = ENOENT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy out stat information for this module...
|
|
|
|
*/
|
|
|
|
statp->id = curp->id;
|
|
|
|
statp->offset = curp->private.lkm_any->lkm_offset;
|
|
|
|
statp->type = curp->private.lkm_any->lkm_type;
|
|
|
|
statp->area = curp->area;
|
|
|
|
statp->size = curp->size / PAGESIZE;
|
|
|
|
statp->private = (unsigned long)curp->private.lkm_any;
|
|
|
|
statp->ver = curp->private.lkm_any->lkm_ver;
|
1995-05-30 08:16:23 +00:00
|
|
|
copystr(curp->private.lkm_any->lkm_name,
|
1994-08-19 11:45:29 +00:00
|
|
|
statp->name,
|
|
|
|
MAXLKMNAME - 2,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* bad ioctl()... */
|
|
|
|
err = ENOTTY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Acts like "nosys" but can be identified in sysent for dynamic call
|
|
|
|
* number assignment for a limited number of calls.
|
|
|
|
*
|
|
|
|
* Place holder for system call slots reserved for loadable modules.
|
|
|
|
*/
|
|
|
|
int
|
1997-11-06 19:29:57 +00:00
|
|
|
lkmnosys(p, args)
|
1995-08-25 20:03:02 +00:00
|
|
|
struct proc *p;
|
|
|
|
struct nosys_args *args;
|
1994-08-19 11:45:29 +00:00
|
|
|
{
|
|
|
|
|
1997-11-06 19:29:57 +00:00
|
|
|
return(nosys(p, args));
|
1994-08-19 11:45:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
lkmexists(lkmtp)
|
|
|
|
struct lkm_table *lkmtp;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* see if name exists...
|
|
|
|
*/
|
|
|
|
for (i = 0; i < MAXLKMS; i++) {
|
|
|
|
/*
|
|
|
|
* An unused module and the one we are testing are not
|
|
|
|
* considered.
|
|
|
|
*/
|
|
|
|
if (!lkmods[i].used || &lkmods[i] == lkmtp)
|
|
|
|
continue;
|
|
|
|
if (!strcmp(lkmtp->private.lkm_any->lkm_name,
|
|
|
|
lkmods[i].private.lkm_any->lkm_name))
|
|
|
|
return(1); /* already loaded... */
|
|
|
|
}
|
|
|
|
|
|
|
|
return(0); /* module not loaded... */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For the loadable system call described by the structure pointed to
|
|
|
|
* by lkmtp, load/unload/stat it depending on the cmd requested.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
_lkm_syscall(lkmtp, cmd)
|
|
|
|
struct lkm_table *lkmtp;
|
|
|
|
int cmd;
|
|
|
|
{
|
|
|
|
struct lkm_syscall *args = lkmtp->private.lkm_syscall;
|
|
|
|
int i;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
switch(cmd) {
|
|
|
|
case LKM_E_LOAD:
|
|
|
|
/* don't load twice! */
|
|
|
|
if (lkmexists(lkmtp))
|
|
|
|
return(EEXIST);
|
1997-04-06 11:14:13 +00:00
|
|
|
if ((i = args->lkm_offset) == LKM_ANON) { /* auto */
|
1994-08-19 11:45:29 +00:00
|
|
|
/*
|
|
|
|
* Search the table looking for a slot...
|
|
|
|
*/
|
1994-08-26 08:42:07 +00:00
|
|
|
for (i = 0; i < aout_sysvec.sv_size; i++)
|
1995-11-09 09:43:32 +00:00
|
|
|
if (aout_sysvec.sv_table[i].sy_call ==
|
|
|
|
(sy_call_t *)lkmnosys)
|
1994-08-19 11:45:29 +00:00
|
|
|
break; /* found it! */
|
|
|
|
/* out of allocable slots? */
|
1994-08-26 08:42:07 +00:00
|
|
|
if (i == aout_sysvec.sv_size) {
|
1994-08-19 11:45:29 +00:00
|
|
|
err = ENFILE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else { /* assign */
|
1994-08-26 08:42:07 +00:00
|
|
|
if (i < 0 || i >= aout_sysvec.sv_size) {
|
1994-08-19 11:45:29 +00:00
|
|
|
err = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* save old */
|
1994-08-26 08:42:07 +00:00
|
|
|
bcopy(&aout_sysvec.sv_table[i],
|
1995-05-30 08:16:23 +00:00
|
|
|
&(args->lkm_oldent),
|
1994-08-26 08:42:07 +00:00
|
|
|
sizeof(struct sysent));
|
1994-08-19 11:45:29 +00:00
|
|
|
|
|
|
|
/* replace with new */
|
1995-05-30 08:16:23 +00:00
|
|
|
bcopy(args->lkm_sysent,
|
1994-08-26 08:42:07 +00:00
|
|
|
&aout_sysvec.sv_table[i],
|
|
|
|
sizeof(struct sysent));
|
1994-08-19 11:45:29 +00:00
|
|
|
|
|
|
|
/* done! */
|
|
|
|
args->lkm_offset = i; /* slot in sysent[] */
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LKM_E_UNLOAD:
|
|
|
|
/* current slot... */
|
|
|
|
i = args->lkm_offset;
|
|
|
|
|
|
|
|
/* replace current slot contents with old contents */
|
1995-05-30 08:16:23 +00:00
|
|
|
bcopy(&(args->lkm_oldent),
|
|
|
|
&aout_sysvec.sv_table[i],
|
1994-08-26 08:42:07 +00:00
|
|
|
sizeof(struct sysent));
|
1994-08-19 11:45:29 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LKM_E_STAT: /* no special handling... */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For the loadable virtual file system described by the structure pointed
|
|
|
|
* to by lkmtp, load/unload/stat it depending on the cmd requested.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
_lkm_vfs(lkmtp, cmd)
|
|
|
|
struct lkm_table *lkmtp;
|
|
|
|
int cmd;
|
|
|
|
{
|
|
|
|
struct lkm_vfs *args = lkmtp->private.lkm_vfs;
|
1994-09-21 03:47:43 +00:00
|
|
|
struct vfsconf *vfc = args->lkm_vfsconf;
|
1997-02-27 16:40:20 +00:00
|
|
|
struct vfsconf *vfsp, *prev_vfsp;
|
|
|
|
int i, maxtypenum;
|
1994-08-19 11:45:29 +00:00
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
switch(cmd) {
|
|
|
|
case LKM_E_LOAD:
|
|
|
|
/* don't load twice! */
|
|
|
|
if (lkmexists(lkmtp))
|
|
|
|
return(EEXIST);
|
|
|
|
|
1997-02-27 16:40:20 +00:00
|
|
|
for (vfsp = vfsconf; vfsp->vfc_next; vfsp = vfsp->vfc_next) {
|
|
|
|
if (!strcmp(vfc->vfc_name, vfsp->vfc_name)) {
|
|
|
|
return EEXIST;
|
1994-09-21 03:47:43 +00:00
|
|
|
}
|
|
|
|
}
|
1997-02-10 02:22:35 +00:00
|
|
|
|
|
|
|
i = args->lkm_offset = vfc->vfc_typenum;
|
1994-09-21 03:47:43 +00:00
|
|
|
if (i < 0) {
|
1997-02-10 02:22:35 +00:00
|
|
|
i = maxvfsconf;
|
1994-09-21 03:47:43 +00:00
|
|
|
}
|
1997-02-10 02:22:35 +00:00
|
|
|
args->lkm_offset = vfc->vfc_typenum = i;
|
|
|
|
|
1997-02-27 16:40:20 +00:00
|
|
|
if (maxvfsconf <= i)
|
|
|
|
maxvfsconf = i + 1;
|
1994-09-21 23:22:52 +00:00
|
|
|
|
1997-02-27 16:40:20 +00:00
|
|
|
vfsp->vfc_next = vfc;
|
1997-02-10 02:22:35 +00:00
|
|
|
vfc->vfc_next = NULL;
|
1994-09-21 03:47:43 +00:00
|
|
|
|
|
|
|
/* like in vfs_op_init */
|
|
|
|
for(i = 0; args->lkm_vnodeops->ls_items[i]; i++) {
|
1996-09-03 22:52:27 +00:00
|
|
|
const struct vnodeopv_desc *opv =
|
|
|
|
args->lkm_vnodeops->ls_items[i];
|
1995-05-30 08:16:23 +00:00
|
|
|
*(opv->opv_desc_vector_p) = NULL;
|
1994-09-21 03:47:43 +00:00
|
|
|
}
|
|
|
|
vfs_opv_init((struct vnodeopv_desc **)args->lkm_vnodeops->ls_items);
|
1994-08-19 11:45:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Call init function for this VFS...
|
|
|
|
*/
|
1997-02-27 16:40:20 +00:00
|
|
|
(*(vfc->vfc_vfsops->vfs_init))(vfc);
|
1994-08-19 11:45:29 +00:00
|
|
|
|
|
|
|
/* done! */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LKM_E_UNLOAD:
|
|
|
|
/* current slot... */
|
|
|
|
i = args->lkm_offset;
|
|
|
|
|
1997-02-10 02:22:35 +00:00
|
|
|
prev_vfsp = NULL;
|
|
|
|
for (vfsp = vfsconf; vfsp;
|
|
|
|
prev_vfsp = vfsp, vfsp = vfsp->vfc_next) {
|
1997-02-27 16:40:20 +00:00
|
|
|
if (!strcmp(vfc->vfc_name, vfsp->vfc_name))
|
1997-02-10 02:22:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (vfsp == NULL) {
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vfsp->vfc_refcount) {
|
1994-09-21 03:47:43 +00:00
|
|
|
return EBUSY;
|
|
|
|
}
|
|
|
|
|
1997-02-10 02:22:35 +00:00
|
|
|
prev_vfsp->vfc_next = vfsp->vfc_next;
|
1994-09-21 03:47:43 +00:00
|
|
|
|
1997-02-27 16:40:20 +00:00
|
|
|
/*
|
|
|
|
* Maintain maxvfsconf.
|
|
|
|
*/
|
|
|
|
maxtypenum = 0;
|
|
|
|
for (vfsp = vfsconf; vfsp != NULL; vfsp = vfsp->vfc_next)
|
|
|
|
if (maxtypenum < vfsp->vfc_typenum)
|
|
|
|
maxtypenum = vfsp->vfc_typenum;
|
|
|
|
maxvfsconf = maxtypenum + 1;
|
|
|
|
|
1994-08-19 11:45:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LKM_E_STAT: /* no special handling... */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For the loadable device driver described by the structure pointed to
|
|
|
|
* by lkmtp, load/unload/stat it depending on the cmd requested.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
_lkm_dev(lkmtp, cmd)
|
|
|
|
struct lkm_table *lkmtp;
|
|
|
|
int cmd;
|
|
|
|
{
|
|
|
|
struct lkm_dev *args = lkmtp->private.lkm_dev;
|
|
|
|
int i;
|
1995-10-04 03:42:39 +00:00
|
|
|
dev_t descrip;
|
1994-08-19 11:45:29 +00:00
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
switch(cmd) {
|
|
|
|
case LKM_E_LOAD:
|
|
|
|
/* don't load twice! */
|
|
|
|
if (lkmexists(lkmtp))
|
|
|
|
return(EEXIST);
|
|
|
|
switch(args->lkm_devtype) {
|
|
|
|
case LM_DT_BLOCK:
|
1997-04-06 11:14:13 +00:00
|
|
|
if ((i = args->lkm_offset) == LKM_ANON)
|
1995-10-04 03:42:39 +00:00
|
|
|
descrip = (dev_t) -1;
|
|
|
|
else
|
|
|
|
descrip = makedev(args->lkm_offset,0);
|
|
|
|
if ( err = bdevsw_add(&descrip, args->lkm_dev.bdev,
|
|
|
|
&(args->lkm_olddev.bdev))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
args->lkm_offset = major(descrip) ;
|
1994-08-19 11:45:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_DT_CHAR:
|
1997-04-06 11:14:13 +00:00
|
|
|
if ((i = args->lkm_offset) == LKM_ANON)
|
1997-02-22 01:20:57 +00:00
|
|
|
descrip = (dev_t) -1;
|
|
|
|
else
|
|
|
|
descrip = makedev(args->lkm_offset,0);
|
|
|
|
if ( err = cdevsw_add(&descrip, args->lkm_dev.cdev,
|
|
|
|
&(args->lkm_olddev.cdev))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
args->lkm_offset = major(descrip) ;
|
1994-08-19 11:45:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
err = ENODEV;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LKM_E_UNLOAD:
|
|
|
|
/* current slot... */
|
|
|
|
i = args->lkm_offset;
|
1997-02-22 01:20:57 +00:00
|
|
|
descrip = makedev(i,0);
|
1994-08-19 11:45:29 +00:00
|
|
|
|
|
|
|
switch(args->lkm_devtype) {
|
|
|
|
case LM_DT_BLOCK:
|
|
|
|
/* replace current slot contents with old contents */
|
1995-12-13 15:13:57 +00:00
|
|
|
bdevsw_add(&descrip, args->lkm_olddev.bdev,NULL);
|
1994-08-19 11:45:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_DT_CHAR:
|
|
|
|
/* replace current slot contents with old contents */
|
1995-12-13 15:13:57 +00:00
|
|
|
cdevsw_add(&descrip, args->lkm_olddev.cdev,NULL);
|
1994-08-19 11:45:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
err = ENODEV;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LKM_E_STAT: /* no special handling... */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef STREAMS
|
|
|
|
/*
|
|
|
|
* For the loadable streams module described by the structure pointed to
|
|
|
|
* by lkmtp, load/unload/stat it depending on the cmd requested.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
_lkm_strmod(lkmtp, cmd)
|
|
|
|
struct lkm_table *lkmtp;
|
|
|
|
int cmd;
|
|
|
|
{
|
|
|
|
struct lkm_strmod *args = lkmtp->private.lkm_strmod;
|
|
|
|
int i;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
switch(cmd) {
|
|
|
|
case LKM_E_LOAD:
|
|
|
|
/* don't load twice! */
|
|
|
|
if (lkmexists(lkmtp))
|
|
|
|
return(EEXIST);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LKM_E_UNLOAD:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LKM_E_STAT: /* no special handling... */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
#endif /* STREAMS */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For the loadable execution class described by the structure pointed to
|
|
|
|
* by lkmtp, load/unload/stat it depending on the cmd requested.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
_lkm_exec(lkmtp, cmd)
|
|
|
|
struct lkm_table *lkmtp;
|
|
|
|
int cmd;
|
|
|
|
{
|
|
|
|
struct lkm_exec *args = lkmtp->private.lkm_exec;
|
|
|
|
int i;
|
|
|
|
int err = 0;
|
1995-05-30 08:16:23 +00:00
|
|
|
const struct execsw **execsw =
|
1994-09-25 08:51:07 +00:00
|
|
|
(const struct execsw **)&execsw_set.ls_items[0];
|
1994-08-19 11:45:29 +00:00
|
|
|
|
|
|
|
switch(cmd) {
|
|
|
|
case LKM_E_LOAD:
|
|
|
|
/* don't load twice! */
|
|
|
|
if (lkmexists(lkmtp))
|
|
|
|
return(EEXIST);
|
1997-04-06 11:14:13 +00:00
|
|
|
if ((i = args->lkm_offset) == LKM_ANON) { /* auto */
|
1994-08-19 11:45:29 +00:00
|
|
|
/*
|
|
|
|
* Search the table looking for a slot...
|
|
|
|
*/
|
1994-09-25 08:51:07 +00:00
|
|
|
for (i = 0; execsw[i] != NULL; i++)
|
|
|
|
if (execsw[i]->ex_imgact == NULL)
|
1994-08-19 11:45:29 +00:00
|
|
|
break; /* found it! */
|
|
|
|
/* out of allocable slots? */
|
1994-09-25 08:51:07 +00:00
|
|
|
if (execsw[i] == NULL) {
|
1994-08-19 11:45:29 +00:00
|
|
|
err = ENFILE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else { /* assign */
|
1994-09-25 08:51:07 +00:00
|
|
|
err = EINVAL;
|
|
|
|
break;
|
1994-08-19 11:45:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* save old */
|
1994-09-25 08:51:07 +00:00
|
|
|
bcopy(&execsw[i], &(args->lkm_oldexec), sizeof(struct execsw*));
|
1994-08-19 11:45:29 +00:00
|
|
|
|
|
|
|
/* replace with new */
|
1994-09-25 08:51:07 +00:00
|
|
|
bcopy(&(args->lkm_exec), &execsw[i], sizeof(struct execsw*));
|
1994-08-19 11:45:29 +00:00
|
|
|
|
|
|
|
/* done! */
|
|
|
|
args->lkm_offset = i; /* slot in execsw[] */
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LKM_E_UNLOAD:
|
|
|
|
/* current slot... */
|
|
|
|
i = args->lkm_offset;
|
|
|
|
|
|
|
|
/* replace current slot contents with old contents */
|
1994-09-25 08:51:07 +00:00
|
|
|
bcopy(&(args->lkm_oldexec), &execsw[i], sizeof(struct execsw*));
|
1994-08-19 11:45:29 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LKM_E_STAT: /* no special handling... */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
1995-11-20 12:08:08 +00:00
|
|
|
/* XXX: This is bogus. we should find a better method RSN! */
|
|
|
|
static const struct execsw lkm_exec_dummy1 = { NULL, "lkm" };
|
|
|
|
static const struct execsw lkm_exec_dummy2 = { NULL, "lkm" };
|
|
|
|
static const struct execsw lkm_exec_dummy3 = { NULL, "lkm" };
|
|
|
|
static const struct execsw lkm_exec_dummy4 = { NULL, "lkm" };
|
|
|
|
TEXT_SET(execsw_set, lkm_exec_dummy1);
|
|
|
|
TEXT_SET(execsw_set, lkm_exec_dummy2);
|
|
|
|
TEXT_SET(execsw_set, lkm_exec_dummy3);
|
|
|
|
TEXT_SET(execsw_set, lkm_exec_dummy4);
|
1994-09-25 08:51:07 +00:00
|
|
|
|
1994-08-19 11:45:29 +00:00
|
|
|
/*
|
|
|
|
* This code handles the per-module type "wiring-in" of loadable modules
|
|
|
|
* into existing kernel tables. For "LM_MISC" modules, wiring and unwiring
|
|
|
|
* is assumed to be done in their entry routines internal to the module
|
|
|
|
* itself.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
lkmdispatch(lkmtp, cmd)
|
1995-05-30 08:16:23 +00:00
|
|
|
struct lkm_table *lkmtp;
|
1994-08-19 11:45:29 +00:00
|
|
|
int cmd;
|
|
|
|
{
|
|
|
|
int err = 0; /* default = success */
|
|
|
|
|
|
|
|
switch(lkmtp->private.lkm_any->lkm_type) {
|
|
|
|
case LM_SYSCALL:
|
|
|
|
err = _lkm_syscall(lkmtp, cmd);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_VFS:
|
|
|
|
err = _lkm_vfs(lkmtp, cmd);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_DEV:
|
|
|
|
err = _lkm_dev(lkmtp, cmd);
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef STREAMS
|
|
|
|
case LM_STRMOD:
|
|
|
|
{
|
|
|
|
struct lkm_strmod *args = lkmtp->private.lkm_strmod;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
#endif /* STREAMS */
|
|
|
|
|
|
|
|
case LM_EXEC:
|
|
|
|
err = _lkm_exec(lkmtp, cmd);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_MISC: /* ignore content -- no "misc-specific" procedure */
|
1994-10-12 20:28:32 +00:00
|
|
|
if (lkmexists(lkmtp))
|
|
|
|
err = EEXIST;
|
1994-08-19 11:45:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
err = ENXIO; /* unknown type */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
1995-11-09 09:43:32 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
lkm_nullcmd(lkmtp, cmd)
|
|
|
|
struct lkm_table *lkmtp;
|
|
|
|
int cmd;
|
|
|
|
{
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
1995-11-29 10:49:16 +00:00
|
|
|
|
|
|
|
static lkm_devsw_installed = 0;
|
1996-03-28 14:31:42 +00:00
|
|
|
#ifdef DEVFS
|
1995-12-08 11:19:42 +00:00
|
|
|
static void *lkmc_devfs_token;
|
1996-03-28 14:31:42 +00:00
|
|
|
#endif
|
1995-11-29 10:49:16 +00:00
|
|
|
|
|
|
|
static void lkm_drvinit(void *unused)
|
|
|
|
{
|
|
|
|
dev_t dev;
|
|
|
|
|
|
|
|
if( ! lkm_devsw_installed ) {
|
1995-12-08 11:19:42 +00:00
|
|
|
dev = makedev(CDEV_MAJOR, 0);
|
|
|
|
cdevsw_add(&dev,&lkmc_cdevsw, NULL);
|
1995-11-29 10:49:16 +00:00
|
|
|
lkm_devsw_installed = 1;
|
|
|
|
#ifdef DEVFS
|
1996-03-27 19:42:14 +00:00
|
|
|
lkmc_devfs_token = devfs_add_devswf(&lkmc_cdevsw, 0, DV_CHR,
|
|
|
|
UID_ROOT, GID_WHEEL, 0644,
|
|
|
|
"lkm");
|
1995-11-29 10:49:16 +00:00
|
|
|
#endif
|
1995-11-29 14:41:20 +00:00
|
|
|
}
|
1995-11-29 10:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SYSINIT(lkmdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,lkm_drvinit,NULL)
|
|
|
|
|
|
|
|
|