1993-06-07 23:51:59 +04:00
|
|
|
/*
|
|
|
|
* kern_lkm.c
|
|
|
|
*
|
|
|
|
* functions and pseudo-device for loadable kernel modules
|
|
|
|
*
|
|
|
|
* 05 Jun 93 Terry Lambert Release cleanup
|
|
|
|
* 10 Feb 93 Terry Lambert Original
|
|
|
|
*
|
|
|
|
* Copyright (c) 1992 Terrence R. Lambert.
|
|
|
|
* 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.
|
|
|
|
*
|
1994-02-15 17:02:59 +03:00
|
|
|
* $Id: kern_lkm.c,v 1.13 1994/02/15 14:02:59 mycroft Exp $
|
1993-06-07 23:51:59 +04:00
|
|
|
*/
|
|
|
|
|
1993-12-18 06:59:02 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/exec.h>
|
|
|
|
#include <sys/lkm.h>
|
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_param.h>
|
|
|
|
#include <vm/vm_kern.h>
|
1993-06-07 23:51:59 +04:00
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
#define PAGESIZE 1024 /* kmem_alloc() allocation quantum */
|
1993-06-07 23:51:59 +04:00
|
|
|
|
|
|
|
#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
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
static struct lkm_table lkmods[MAXLKMS]; /* table of loaded modules */
|
|
|
|
static struct lkm_table *curp; /* global for in-progress ops */
|
1993-06-07 23:51:59 +04:00
|
|
|
|
|
|
|
/*ARGSUSED*/
|
1994-02-15 17:02:59 +03:00
|
|
|
lkmopen(dev, flag, devtype, p)
|
1993-06-07 23:51:59 +04:00
|
|
|
dev_t dev;
|
|
|
|
int flag;
|
|
|
|
int devtype;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
if (minor(dev) != 0)
|
|
|
|
return(ENXIO); /* bad minor # */
|
1993-06-07 23:51:59 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Use of the loadable kernel module device must be exclusive; we
|
|
|
|
* may try to remove this restriction later, but it's really no
|
|
|
|
* hardship.
|
|
|
|
*/
|
1994-02-15 17:02:59 +03:00
|
|
|
while (lkm_v & LKM_ALLOC) {
|
|
|
|
if (flag & FNONBLOCK) /* don't hang */
|
|
|
|
return(EBUSY);
|
1993-06-07 23:51:59 +04:00
|
|
|
lkm_v |= LKM_WANT;
|
|
|
|
/*
|
|
|
|
* Sleep pending unlock; we use tsleep() to allow
|
|
|
|
* an alarm out of the open.
|
|
|
|
*/
|
1994-02-15 17:02:59 +03:00
|
|
|
if (error = tsleep((caddr_t)&lkm_v, TTIPRI|PCATCH, "LKM", 0))
|
|
|
|
return(error); /* leave LKM_WANT set -- no problem */
|
1993-06-07 23:51:59 +04:00
|
|
|
}
|
|
|
|
lkm_v |= LKM_ALLOC;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
return(0); /* pseudo-device open */
|
1993-06-07 23:51:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* l k m u n r e s e r v e
|
|
|
|
*
|
|
|
|
* 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 int
|
|
|
|
lkmunreserve()
|
|
|
|
{
|
1994-02-15 17:02:59 +03:00
|
|
|
if (lkm_state == LKMS_IDLE)
|
1993-06-07 23:51:59 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Actually unreserve the memory
|
|
|
|
*/
|
1994-01-09 19:47:40 +03:00
|
|
|
if (curp && curp->area) {
|
1994-02-15 17:02:59 +03:00
|
|
|
kmem_free(kmem_map, curp->area, curp->size);/**/
|
1994-01-09 19:47:40 +03:00
|
|
|
curp->area = 0;
|
|
|
|
}
|
1993-06-07 23:51:59 +04:00
|
|
|
|
|
|
|
lkm_state = LKMS_IDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
lkmclose(dev, flag, mode, p)
|
1993-06-07 23:51:59 +04:00
|
|
|
dev_t dev;
|
|
|
|
int flag;
|
|
|
|
int mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1994-02-15 17:02:59 +03:00
|
|
|
if (!(lkm_v & LKM_ALLOC)) {
|
1993-06-07 23:51:59 +04:00
|
|
|
#ifdef DEBUG
|
1994-02-15 17:02:59 +03:00
|
|
|
printf("LKM: close before open!\n");
|
|
|
|
#endif /* DEBUG */
|
|
|
|
return(EBADF);
|
1993-06-07 23:51:59 +04:00
|
|
|
}
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
/* do this before waking the herd... */
|
|
|
|
if (curp && !curp->used) {
|
1993-06-07 23:51:59 +04:00
|
|
|
/*
|
|
|
|
* 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".
|
|
|
|
*/
|
1994-02-15 17:02:59 +03:00
|
|
|
lkmunreserve(); /* coerce state to LKM_IDLE */
|
1993-06-07 23:51:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
lkm_v &= ~LKM_ALLOC;
|
1994-02-15 17:02:59 +03:00
|
|
|
wakeup((caddr_t)&lkm_v); /* thundering herd "problem" here */
|
1993-06-07 23:51:59 +04:00
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
return(0); /* pseudo-device closed */
|
1993-06-07 23:51:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
1994-02-15 17:02:59 +03:00
|
|
|
lkmioctl(dev, cmd, data, flag)
|
1993-06-07 23:51:59 +04:00
|
|
|
dev_t dev;
|
|
|
|
int cmd;
|
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
int i;
|
|
|
|
struct lmc_resrv *resrvp;
|
|
|
|
struct lmc_loadbuf *loadbufp;
|
|
|
|
struct lmc_unload *unloadp;
|
|
|
|
struct lmc_stat *statp;
|
|
|
|
int (*funcp)();
|
1994-02-15 17:02:59 +03:00
|
|
|
char istr[MAXLKMNAME];
|
1993-06-07 23:51:59 +04:00
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
switch(cmd) {
|
|
|
|
case LMRESERV: /* reserve pages for a module */
|
1993-06-08 03:10:09 +04:00
|
|
|
if ((flag & FWRITE) == 0) /* only allow this if writing */
|
|
|
|
return EPERM;
|
1993-06-07 23:51:59 +04:00
|
|
|
|
|
|
|
resrvp = (struct lmc_resrv *)data;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find a free slot.
|
|
|
|
*/
|
1994-02-15 17:02:59 +03:00
|
|
|
for (i = 0; i < MAXLKMS; i++) {
|
|
|
|
if (!lkmods[i].used)
|
1993-06-07 23:51:59 +04:00
|
|
|
break;
|
|
|
|
}
|
1994-02-15 17:02:59 +03:00
|
|
|
if (i == MAXLKMS) {
|
|
|
|
err = ENOMEM; /* no slots available */
|
1993-06-07 23:51:59 +04:00
|
|
|
break;
|
|
|
|
}
|
1994-02-15 17:02:59 +03:00
|
|
|
curp = &lkmods[i];
|
|
|
|
curp->id = i; /* self reference slot offset */
|
1993-06-07 23:51:59 +04:00
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
resrvp->slot = i; /* return slot */
|
1993-06-07 23:51:59 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get memory for module
|
|
|
|
*/
|
|
|
|
curp->size = resrvp->size;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
curp->area = kmem_alloc(kmem_map, curp->size);/**/
|
1993-06-07 23:51:59 +04:00
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
curp->offset = 0; /* load offset */
|
1993-06-07 23:51:59 +04:00
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
resrvp->addr = curp->area; /* ret kernel addr */
|
1993-06-07 23:51:59 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1994-02-15 17:02:59 +03:00
|
|
|
printf("LKM: LMRESERV (actual = 0x%08x)\n", curp->area);
|
|
|
|
printf("LKM: LMRESERV (adjusted = 0x%08x)\n",
|
1993-06-07 23:51:59 +04:00
|
|
|
trunc_page(curp->area));
|
1994-02-15 17:02:59 +03:00
|
|
|
#endif /* DEBUG */
|
1993-06-07 23:51:59 +04:00
|
|
|
lkm_state = LKMS_RESERVED;
|
|
|
|
break;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
case LMLOADBUF: /* Copy in; stateful, follows LMRESERV */
|
1993-06-08 03:10:09 +04:00
|
|
|
if ((flag & FWRITE) == 0) /* only allow this if writing */
|
|
|
|
return EPERM;
|
|
|
|
|
1993-06-07 23:51:59 +04:00
|
|
|
loadbufp = (struct lmc_loadbuf *)data;
|
1994-01-09 19:47:40 +03:00
|
|
|
i = loadbufp->cnt;
|
1994-02-15 17:02:59 +03:00
|
|
|
if ((lkm_state != LKMS_RESERVED && lkm_state != LKMS_LOADING)
|
1994-01-09 19:47:40 +03:00
|
|
|
|| i < 0
|
|
|
|
|| i > MODIOBUF
|
|
|
|
|| i > curp->size - curp->offset) {
|
1993-06-07 23:51:59 +04:00
|
|
|
err = ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
/* copy in buffer full of data */
|
|
|
|
if (err = copyin((caddr_t)loadbufp->data, (caddr_t)curp->area + curp->offset, i))
|
1993-06-07 23:51:59 +04:00
|
|
|
break;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
if ((curp->offset + i) < curp->size) {
|
1993-06-07 23:51:59 +04:00
|
|
|
lkm_state = LKMS_LOADING;
|
|
|
|
#ifdef DEBUG
|
1994-02-15 17:02:59 +03:00
|
|
|
printf("LKM: LMLOADBUF (loading @ %d of %d, i = %d)\n",
|
1993-06-07 23:51:59 +04:00
|
|
|
curp->offset, curp->size, i);
|
1994-02-15 17:02:59 +03:00
|
|
|
#endif /* DEBUG */
|
1993-06-07 23:51:59 +04:00
|
|
|
} else {
|
|
|
|
lkm_state = LKMS_LOADED;
|
|
|
|
#ifdef DEBUG
|
1994-02-15 17:02:59 +03:00
|
|
|
printf("LKM: LMLOADBUF (loaded)\n");
|
|
|
|
#endif /* DEBUG */
|
1993-06-07 23:51:59 +04:00
|
|
|
}
|
1994-01-09 21:46:17 +03:00
|
|
|
curp->offset += i;
|
1993-06-07 23:51:59 +04:00
|
|
|
break;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
case LMUNRESRV: /* discard reserved pages for a module */
|
1993-06-08 03:10:09 +04:00
|
|
|
if ((flag & FWRITE) == 0) /* only allow this if writing */
|
|
|
|
return EPERM;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
lkmunreserve(); /* coerce state to LKM_IDLE */
|
1993-06-07 23:51:59 +04:00
|
|
|
#ifdef DEBUG
|
1994-02-15 17:02:59 +03:00
|
|
|
printf("LKM: LMUNRESERV\n");
|
|
|
|
#endif /* DEBUG */
|
1993-06-07 23:51:59 +04:00
|
|
|
break;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
case LMREADY: /* module loaded: call entry */
|
1993-06-08 03:10:09 +04:00
|
|
|
if ((flag & FWRITE) == 0) /* only allow this if writing */
|
|
|
|
return EPERM;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
if (lkm_state != LKMS_LOADED) {
|
1993-06-07 23:51:59 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1994-02-15 17:02:59 +03:00
|
|
|
printf("lkm_state is %02x\n", lkm_state);
|
|
|
|
#endif /* DEBUG */
|
1993-06-07 23:51:59 +04:00
|
|
|
err = ENXIO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
curp->entry = (int (*)()) (*((int *) (data)));
|
1993-06-07 23:51:59 +04:00
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
/* call entry(load)... (assigns "private" portion) */
|
|
|
|
if (err = (*(curp->entry))(curp, LKM_E_LOAD, LKM_VERSION)) {
|
1993-06-07 23:51:59 +04:00
|
|
|
/*
|
|
|
|
* Module may refuse loading or may have a
|
|
|
|
* version mismatch...
|
|
|
|
*/
|
1994-02-15 17:02:59 +03:00
|
|
|
lkm_state = LKMS_UNLOADING; /* for lkmunreserve */
|
|
|
|
lkmunreserve(); /* free memory */
|
|
|
|
curp->used = 0; /* free slot */
|
1993-06-07 23:51:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
curp->used = 1;
|
|
|
|
#ifdef DEBUG
|
1994-02-15 17:02:59 +03:00
|
|
|
printf("LKM: LMREADY\n");
|
|
|
|
#endif /* DEBUG */
|
1993-06-07 23:51:59 +04:00
|
|
|
lkm_state = LKMS_IDLE;
|
|
|
|
break;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
case LMUNLOAD: /* unload a module */
|
1993-06-08 03:10:09 +04:00
|
|
|
if ((flag & FWRITE) == 0) /* only allow this if writing */
|
|
|
|
return EPERM;
|
|
|
|
|
1993-06-07 23:51:59 +04:00
|
|
|
unloadp = (struct lmc_unload *)data;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
if ((i = unloadp->id) == -1) { /* unload by name */
|
1993-06-07 23:51:59 +04:00
|
|
|
/*
|
1993-07-28 06:20:34 +04:00
|
|
|
* Copy name and lookup id from all loaded
|
1994-01-09 19:47:40 +03:00
|
|
|
* modules. May fail.
|
1993-06-07 23:51:59 +04:00
|
|
|
*/
|
1994-02-15 17:02:59 +03:00
|
|
|
if (err = copyinstr(unloadp->name, istr, MAXLKMNAME-1, NULL))
|
1994-01-09 19:47:40 +03:00
|
|
|
break;
|
|
|
|
|
1993-06-07 23:51:59 +04:00
|
|
|
/*
|
|
|
|
* look up id...
|
|
|
|
*/
|
1994-02-15 17:02:59 +03:00
|
|
|
for (i = 0; i < MAXLKMS; i++) {
|
|
|
|
if (!lkmods[i].used)
|
1993-06-07 23:51:59 +04:00
|
|
|
continue;
|
1994-02-15 17:02:59 +03:00
|
|
|
if (!strcmp(istr,
|
|
|
|
lkmods[i].private.lkm_any->lkm_name))
|
1993-06-07 23:51:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Range check the value; on failure, return EINVAL
|
|
|
|
*/
|
1994-02-15 17:02:59 +03:00
|
|
|
if (i < 0 || i >= MAXLKMS) {
|
1993-06-07 23:51:59 +04:00
|
|
|
err = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
curp = &lkmods[i];
|
1993-06-07 23:51:59 +04:00
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
/* call entry(unload) */
|
|
|
|
if ((*(curp->entry))(curp, LKM_E_UNLOAD, LKM_VERSION)) {
|
1993-06-07 23:51:59 +04:00
|
|
|
err = EBUSY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
lkm_state = LKMS_UNLOADING; /* non-idle for lkmunreserve */
|
|
|
|
lkmunreserve(); /* free memory */
|
|
|
|
curp->used = 0; /* free slot */
|
1993-06-07 23:51:59 +04:00
|
|
|
break;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
case LMSTAT: /* stat a module by id/name */
|
1993-06-08 03:10:09 +04:00
|
|
|
/* allow readers and writers to stat */
|
|
|
|
|
1993-06-07 23:51:59 +04:00
|
|
|
statp = (struct lmc_stat *)data;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
if ((i = statp->id) == -1) { /* stat by name */
|
1993-06-07 23:51:59 +04:00
|
|
|
/*
|
1993-07-28 06:20:34 +04:00
|
|
|
* Copy name and lookup id from all loaded
|
|
|
|
* modules.
|
1993-06-07 23:51:59 +04:00
|
|
|
*/
|
1994-02-15 17:02:59 +03:00
|
|
|
copystr(statp->name, istr, MAXLKMNAME-1, NULL);
|
1993-06-07 23:51:59 +04:00
|
|
|
/*
|
|
|
|
* look up id...
|
|
|
|
*/
|
1994-02-15 17:02:59 +03:00
|
|
|
for (i = 0; i < MAXLKMS; i++) {
|
|
|
|
if (!lkmods[i].used)
|
1993-06-07 23:51:59 +04:00
|
|
|
continue;
|
1994-02-15 17:02:59 +03:00
|
|
|
if (!strcmp(istr,
|
|
|
|
lkmods[i].private.lkm_any->lkm_name))
|
1993-06-07 23:51:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
if (i == MAXLKMS) { /* Not found */
|
1993-06-07 23:51:59 +04:00
|
|
|
err = ENOENT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Range check the value; on failure, return EINVAL
|
|
|
|
*/
|
1994-02-15 17:02:59 +03:00
|
|
|
if (i < 0 || i >= MAXLKMS) {
|
1993-06-07 23:51:59 +04:00
|
|
|
err = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
curp = &lkmods[i];
|
1993-06-07 23:51:59 +04:00
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
if (!curp->used) { /* Not found */
|
1993-06-07 23:51:59 +04:00
|
|
|
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;
|
1994-02-15 17:02:59 +03:00
|
|
|
copystr(curp->private.lkm_any->lkm_name,
|
1993-07-28 06:20:34 +04:00
|
|
|
statp->name,
|
|
|
|
MAXLKMNAME - 2,
|
|
|
|
NULL);
|
1993-06-07 23:51:59 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
default: /* bad ioctl()... */
|
1993-06-07 23:51:59 +04:00
|
|
|
err = ENOTTY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
/******************************************************************** */
|
1993-06-07 23:51:59 +04:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* l k m n o s y s
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
lkmnosys()
|
|
|
|
{
|
1994-02-15 17:02:59 +03:00
|
|
|
return(nosys());
|
1993-06-07 23:51:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* l k m e n o d e v
|
|
|
|
*
|
|
|
|
* Acts like "enodev", but can be identified in cdevsw and bdevsw for
|
|
|
|
* dynamic driver major number assignment for a limited number of
|
|
|
|
* drivers.
|
|
|
|
*
|
|
|
|
* Place holder for device switch slots reserved for loadable modules.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
lkmenodev()
|
|
|
|
{
|
1994-02-15 17:02:59 +03:00
|
|
|
return(enodev());
|
1993-06-07 23:51:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
int
|
1994-02-15 17:02:59 +03:00
|
|
|
lkmexists(lkmtp)
|
1993-06-07 23:51:59 +04:00
|
|
|
struct lkm_table *lkmtp;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* see if name exists...
|
|
|
|
*/
|
1994-02-15 17:02:59 +03:00
|
|
|
for (i = 0; i < MAXLKMS; i++) {
|
1993-06-07 23:51:59 +04:00
|
|
|
/*
|
|
|
|
* An unused module and the one we are testing are not
|
|
|
|
* considered.
|
|
|
|
*/
|
1994-02-15 17:02:59 +03:00
|
|
|
if (!lkmods[i].used || &lkmods[i] == lkmtp)
|
1993-06-07 23:51:59 +04:00
|
|
|
continue;
|
1994-02-15 17:02:59 +03:00
|
|
|
if (!strcmp(lkmtp->private.lkm_any->lkm_name,
|
|
|
|
lkmods[i].private.lkm_any->lkm_name))
|
|
|
|
return(1); /* already loaded... */
|
1993-06-07 23:51:59 +04:00
|
|
|
}
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
return(0); /* module not loaded... */
|
1993-06-07 23:51:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For the loadable system call described by the structure pointed to
|
|
|
|
* by lkmtp, load/unload/stat it depending on the cmd requested.
|
|
|
|
*/
|
|
|
|
static int
|
1994-02-15 17:02:59 +03:00
|
|
|
_lkm_syscall(lkmtp, cmd)
|
1993-06-07 23:51:59 +04:00
|
|
|
struct lkm_table *lkmtp;
|
|
|
|
int cmd;
|
|
|
|
{
|
|
|
|
struct lkm_syscall *args = lkmtp->private.lkm_syscall;
|
|
|
|
int i;
|
|
|
|
int err = 0;
|
1994-02-15 17:02:59 +03:00
|
|
|
extern int nsysent; /* init_sysent.c */
|
1993-06-07 23:51:59 +04:00
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
switch(cmd) {
|
1993-06-07 23:51:59 +04:00
|
|
|
case LKM_E_LOAD:
|
1994-02-15 17:02:59 +03:00
|
|
|
/* don't load twice! */
|
|
|
|
if (lkmexists(lkmtp))
|
|
|
|
return(EEXIST);
|
|
|
|
if ((i = args->lkm_offset) == -1) { /* auto */
|
1993-06-07 23:51:59 +04:00
|
|
|
/*
|
|
|
|
* Search the table looking for a slot...
|
|
|
|
*/
|
1994-02-15 17:02:59 +03:00
|
|
|
for (i = 0; i < nsysent; i++)
|
|
|
|
if (sysent[i].sy_call == lkmnosys)
|
|
|
|
break; /* found it! */
|
|
|
|
/* out of allocable slots? */
|
|
|
|
if (i == nsysent) {
|
1993-06-07 23:51:59 +04:00
|
|
|
err = ENFILE;
|
|
|
|
break;
|
|
|
|
}
|
1994-02-15 17:02:59 +03:00
|
|
|
} else { /* assign */
|
|
|
|
if (i < 0 || i >= nsysent) {
|
1993-06-07 23:51:59 +04:00
|
|
|
err = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
/* save old */
|
|
|
|
bcopy(&sysent[i], &(args->lkm_oldent), sizeof(struct sysent));
|
1993-06-07 23:51:59 +04:00
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
/* replace with new */
|
|
|
|
bcopy(args->lkm_sysent, &sysent[i], sizeof(struct sysent));
|
1993-06-07 23:51:59 +04:00
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
/* done! */
|
|
|
|
args->lkm_offset = i; /* slot in sysent[] */
|
1993-06-07 23:51:59 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LKM_E_UNLOAD:
|
1994-02-15 17:02:59 +03:00
|
|
|
/* current slot... */
|
1993-06-07 23:51:59 +04:00
|
|
|
i = args->lkm_offset;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
/* replace current slot contents with old contents */
|
|
|
|
bcopy(&(args->lkm_oldent), &sysent[i], sizeof(struct sysent));
|
1993-06-07 23:51:59 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
case LKM_E_STAT: /* no special handling... */
|
1993-06-07 23:51:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
return(err);
|
1993-06-07 23:51:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
1994-02-15 17:02:59 +03:00
|
|
|
_lkm_vfs(lkmtp, cmd)
|
1993-06-07 23:51:59 +04:00
|
|
|
struct lkm_table *lkmtp;
|
|
|
|
int cmd;
|
|
|
|
{
|
|
|
|
struct lkm_vfs *args = lkmtp->private.lkm_vfs;
|
|
|
|
int i;
|
|
|
|
int err = 0;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
switch(cmd) {
|
1993-06-07 23:51:59 +04:00
|
|
|
case LKM_E_LOAD:
|
1994-02-15 17:02:59 +03:00
|
|
|
/* don't load twice! */
|
|
|
|
if (lkmexists(lkmtp))
|
|
|
|
return(EEXIST);
|
1993-06-07 23:51:59 +04:00
|
|
|
/*
|
|
|
|
* Currently, the VFS and mount code in 386BSD is malformed;
|
|
|
|
* this means that the per volume file system identifier is
|
|
|
|
* the index into the table rather than the name; this means
|
|
|
|
* that only the file systems already known to 386BSD are
|
|
|
|
* allowable, since all others don't have fixed offsets.
|
|
|
|
* Interestingly, Dell UNIX has this same bug with their VFS
|
|
|
|
* implementation, but generic AT&T SVR4 does not.
|
|
|
|
*
|
|
|
|
* I will correct the VFS code when I get a chance.
|
|
|
|
*/
|
|
|
|
i = args->lkm_offset;
|
1994-02-15 17:02:59 +03:00
|
|
|
if (i < 0 || i > MOUNT_MAXTYPE) {
|
1993-06-07 23:51:59 +04:00
|
|
|
err = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
if (vfssw[i] != (struct vfsops *)0) {
|
1993-06-07 23:51:59 +04:00
|
|
|
err = EEXIST;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up file system
|
|
|
|
*/
|
1994-02-15 17:02:59 +03:00
|
|
|
vfssw[i] = args->lkm_vfsops;
|
1993-06-07 23:51:59 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Call init function for this VFS...
|
|
|
|
*/
|
1994-02-15 17:02:59 +03:00
|
|
|
(*(vfssw[i]->vfs_init))(args->lkm_flags);
|
1993-06-07 23:51:59 +04:00
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
/* done! */
|
|
|
|
args->lkm_offset = i; /* slot in sysent[] */
|
1993-06-07 23:51:59 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LKM_E_UNLOAD:
|
1994-02-15 17:02:59 +03:00
|
|
|
/* current slot... */
|
1993-06-07 23:51:59 +04:00
|
|
|
i = args->lkm_offset;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
/* replace current slot contents with old contents */
|
|
|
|
vfssw[i] = (struct vfsops *)0;
|
1993-06-07 23:51:59 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
case LKM_E_STAT: /* no special handling... */
|
1993-06-07 23:51:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
return(err);
|
1993-06-07 23:51:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For the loadable device driver described by the structure pointed to
|
|
|
|
* by lkmtp, load/unload/stat it depending on the cmd requested.
|
|
|
|
*/
|
|
|
|
static int
|
1994-02-15 17:02:59 +03:00
|
|
|
_lkm_dev(lkmtp, cmd)
|
1993-06-07 23:51:59 +04:00
|
|
|
struct lkm_table *lkmtp;
|
|
|
|
int cmd;
|
|
|
|
{
|
|
|
|
struct lkm_dev *args = lkmtp->private.lkm_dev;
|
|
|
|
int i;
|
|
|
|
int err = 0;
|
1994-02-15 17:02:59 +03:00
|
|
|
extern int nblkdev; /* i386/i386/conf.c */
|
|
|
|
extern int nchrdev; /* i386/i386/conf.c */
|
1993-06-07 23:51:59 +04:00
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
switch(cmd) {
|
1993-06-07 23:51:59 +04:00
|
|
|
case LKM_E_LOAD:
|
1994-02-15 17:02:59 +03:00
|
|
|
/* don't load twice! */
|
|
|
|
if (lkmexists(lkmtp))
|
|
|
|
return(EEXIST);
|
|
|
|
switch(args->lkm_devtype) {
|
1993-06-07 23:51:59 +04:00
|
|
|
case LM_DT_BLOCK:
|
1994-02-15 17:02:59 +03:00
|
|
|
if ((i = args->lkm_offset) == -1) { /* auto */
|
1993-06-07 23:51:59 +04:00
|
|
|
/*
|
|
|
|
* Search the table looking for a slot...
|
|
|
|
*/
|
1994-02-15 17:02:59 +03:00
|
|
|
for (i = 0; i < nblkdev; i++)
|
|
|
|
if (bdevsw[i].d_open == lkmenodev)
|
|
|
|
break; /* found it! */
|
|
|
|
/* out of allocable slots? */
|
|
|
|
if (i == nblkdev) {
|
1993-06-07 23:51:59 +04:00
|
|
|
err = ENFILE;
|
|
|
|
break;
|
|
|
|
}
|
1994-02-15 17:02:59 +03:00
|
|
|
} else { /* assign */
|
|
|
|
if (i < 0 || i >= nblkdev) {
|
1993-06-07 23:51:59 +04:00
|
|
|
err = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
/* save old */
|
|
|
|
bcopy(&bdevsw[i], &(args->lkm_olddev.bdev), sizeof(struct bdevsw));
|
1993-06-07 23:51:59 +04:00
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
/* replace with new */
|
|
|
|
bcopy(args->lkm_dev.bdev, &bdevsw[i], sizeof(struct bdevsw));
|
1993-06-07 23:51:59 +04:00
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
/* done! */
|
|
|
|
args->lkm_offset = i; /* slot in bdevsw[] */
|
1993-06-07 23:51:59 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_DT_CHAR:
|
1994-02-15 17:02:59 +03:00
|
|
|
if ((i = args->lkm_offset) == -1) { /* auto */
|
1993-06-07 23:51:59 +04:00
|
|
|
/*
|
|
|
|
* Search the table looking for a slot...
|
|
|
|
*/
|
1994-02-15 17:02:59 +03:00
|
|
|
for (i = 0; i < nchrdev; i++)
|
|
|
|
if (cdevsw[i].d_open == lkmenodev)
|
|
|
|
break; /* found it! */
|
|
|
|
/* out of allocable slots? */
|
|
|
|
if (i == nchrdev) {
|
1993-06-07 23:51:59 +04:00
|
|
|
err = ENFILE;
|
|
|
|
break;
|
|
|
|
}
|
1994-02-15 17:02:59 +03:00
|
|
|
} else { /* assign */
|
|
|
|
if (i < 0 || i >= nchrdev) {
|
1993-06-07 23:51:59 +04:00
|
|
|
err = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
/* save old */
|
|
|
|
bcopy(&cdevsw[i], &(args->lkm_olddev.cdev), sizeof(struct cdevsw));
|
1993-06-07 23:51:59 +04:00
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
/* replace with new */
|
|
|
|
bcopy(args->lkm_dev.cdev, &cdevsw[i], sizeof(struct cdevsw));
|
1993-06-07 23:51:59 +04:00
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
/* done! */
|
|
|
|
args->lkm_offset = i; /* slot in cdevsw[] */
|
1993-06-07 23:51:59 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
err = ENODEV;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LKM_E_UNLOAD:
|
1994-02-15 17:02:59 +03:00
|
|
|
/* current slot... */
|
1993-06-07 23:51:59 +04:00
|
|
|
i = args->lkm_offset;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
switch(args->lkm_devtype) {
|
1993-06-07 23:51:59 +04:00
|
|
|
case LM_DT_BLOCK:
|
1994-02-15 17:02:59 +03:00
|
|
|
/* replace current slot contents with old contents */
|
|
|
|
bcopy(&(args->lkm_olddev.bdev), &bdevsw[i], sizeof(struct bdevsw));
|
1993-06-07 23:51:59 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_DT_CHAR:
|
1994-02-15 17:02:59 +03:00
|
|
|
/* replace current slot contents with old contents */
|
|
|
|
bcopy(&(args->lkm_olddev.cdev), &cdevsw[i], sizeof(struct cdevsw));
|
1993-06-07 23:51:59 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
err = ENODEV;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
case LKM_E_STAT: /* no special handling... */
|
1993-06-07 23:51:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
return(err);
|
1993-06-07 23:51:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#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
|
1994-02-15 17:02:59 +03:00
|
|
|
_lkm_strmod(lkmtp, cmd)
|
1993-06-07 23:51:59 +04:00
|
|
|
struct lkm_table *lkmtp;
|
|
|
|
int cmd;
|
|
|
|
{
|
|
|
|
struct lkm_strmod *args = lkmtp->private.lkm_strmod;
|
|
|
|
int i;
|
|
|
|
int err = 0;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
switch(cmd) {
|
1993-06-07 23:51:59 +04:00
|
|
|
case LKM_E_LOAD:
|
1994-02-15 17:02:59 +03:00
|
|
|
/* don't load twice! */
|
|
|
|
if (lkmexists(lkmtp))
|
|
|
|
return(EEXIST);
|
1993-06-07 23:51:59 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LKM_E_UNLOAD:
|
|
|
|
break;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
case LKM_E_STAT: /* no special handling... */
|
1993-06-07 23:51:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
return(err);
|
1993-06-07 23:51:59 +04:00
|
|
|
}
|
1994-02-15 17:02:59 +03:00
|
|
|
#endif /* STREAMS */
|
1993-06-07 23:51:59 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For the loadable execution class described by the structure pointed to
|
|
|
|
* by lkmtp, load/unload/stat it depending on the cmd requested.
|
|
|
|
*/
|
|
|
|
static int
|
1994-02-15 17:02:59 +03:00
|
|
|
_lkm_exec(lkmtp, cmd)
|
1993-06-07 23:51:59 +04:00
|
|
|
struct lkm_table *lkmtp;
|
|
|
|
int cmd;
|
|
|
|
{
|
|
|
|
struct lkm_exec *args = lkmtp->private.lkm_exec;
|
|
|
|
int i;
|
|
|
|
int err = 0;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
switch(cmd) {
|
1993-06-07 23:51:59 +04:00
|
|
|
case LKM_E_LOAD:
|
1994-02-15 17:02:59 +03:00
|
|
|
/* don't load twice! */
|
|
|
|
if (lkmexists(lkmtp))
|
|
|
|
return(EEXIST);
|
|
|
|
if ((i = args->lkm_offset) == -1) { /* auto */
|
1993-06-07 23:51:59 +04:00
|
|
|
/*
|
|
|
|
* Search the table looking for a slot...
|
|
|
|
*/
|
1994-02-15 17:02:59 +03:00
|
|
|
for (i = 0; i < nexecs; i++)
|
|
|
|
if (execsw[i].es_check == NULL)
|
|
|
|
break; /* found it! */
|
|
|
|
/* out of allocable slots? */
|
|
|
|
if (i == nexecs) {
|
1993-06-07 23:51:59 +04:00
|
|
|
err = ENFILE;
|
|
|
|
break;
|
|
|
|
}
|
1994-02-15 17:02:59 +03:00
|
|
|
} else { /* assign */
|
|
|
|
if (i < 0 || i >= nexecs) {
|
1993-06-07 23:51:59 +04:00
|
|
|
err = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
/* save old */
|
1994-02-05 05:23:30 +03:00
|
|
|
bcopy(&execsw[i], &(args->lkm_oldexec), sizeof(struct execsw));
|
1993-06-07 23:51:59 +04:00
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
/* replace with new */
|
1994-02-05 05:23:30 +03:00
|
|
|
bcopy(args->lkm_exec, &execsw[i], sizeof(struct execsw));
|
|
|
|
|
|
|
|
/* realize need to recompute max header size */
|
|
|
|
exec_maxhdrsz = 0;
|
1993-06-07 23:51:59 +04:00
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
/* done! */
|
|
|
|
args->lkm_offset = i; /* slot in execsw[] */
|
1993-06-07 23:51:59 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LKM_E_UNLOAD:
|
1994-02-15 17:02:59 +03:00
|
|
|
/* current slot... */
|
1993-06-07 23:51:59 +04:00
|
|
|
i = args->lkm_offset;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
/* replace current slot contents with old contents */
|
1994-02-05 05:23:30 +03:00
|
|
|
bcopy(&(args->lkm_oldexec), &execsw[i], sizeof(struct execsw));
|
|
|
|
|
|
|
|
/* realize need to recompute max header size */
|
|
|
|
exec_maxhdrsz = 0;
|
1993-06-07 23:51:59 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
case LKM_E_STAT: /* no special handling... */
|
1993-06-07 23:51:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
return(err);
|
1993-06-07 23:51:59 +04: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.
|
|
|
|
*/
|
1994-02-15 17:02:59 +03:00
|
|
|
lkmdispatch(lkmtp, cmd)
|
1993-06-07 23:51:59 +04:00
|
|
|
struct lkm_table *lkmtp;
|
|
|
|
int cmd;
|
|
|
|
{
|
1994-02-15 17:02:59 +03:00
|
|
|
int err = 0; /* default = success */
|
1993-06-07 23:51:59 +04:00
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
switch(lkmtp->private.lkm_any->lkm_type) {
|
1993-06-07 23:51:59 +04:00
|
|
|
case LM_SYSCALL:
|
1994-02-15 17:02:59 +03:00
|
|
|
err = _lkm_syscall(lkmtp, cmd);
|
1993-06-07 23:51:59 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_VFS:
|
1994-02-15 17:02:59 +03:00
|
|
|
err = _lkm_vfs(lkmtp, cmd);
|
1993-06-07 23:51:59 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_DEV:
|
1994-02-15 17:02:59 +03:00
|
|
|
err = _lkm_dev(lkmtp, cmd);
|
1993-09-05 04:55:57 +04:00
|
|
|
break;
|
1993-06-07 23:51:59 +04:00
|
|
|
|
|
|
|
#ifdef STREAMS
|
|
|
|
case LM_STRMOD:
|
|
|
|
{
|
|
|
|
struct lkm_strmod *args = lkmtp->private.lkm_strmod;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
#endif /* STREAMS */
|
1993-06-07 23:51:59 +04:00
|
|
|
|
|
|
|
case LM_EXEC:
|
1994-02-15 17:02:59 +03:00
|
|
|
err = _lkm_exec(lkmtp, cmd);
|
1993-06-07 23:51:59 +04:00
|
|
|
break;
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
case LM_MISC: /* ignore content -- no "misc-specific" procedure */
|
1993-06-07 23:51:59 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1994-02-15 17:02:59 +03:00
|
|
|
err = ENXIO; /* unknown type */
|
1993-06-07 23:51:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1994-02-15 17:02:59 +03:00
|
|
|
return(err);
|
1993-06-07 23:51:59 +04:00
|
|
|
}
|