summaryrefslogtreecommitdiff
path: root/sys/kern/kern_lkm.c
diff options
context:
space:
mode:
authorNiklas Hallqvist <niklas@cvs.openbsd.org>1996-03-03 17:20:29 +0000
committerNiklas Hallqvist <niklas@cvs.openbsd.org>1996-03-03 17:20:29 +0000
commita69a4a568209bb69852224e2cd6f6394ed4da746 (patch)
tree35d8778bf8e995cb348c0bb9d78d38b7a7e6e356 /sys/kern/kern_lkm.c
parent5aeba8440e8d2256e4b716030f97e3bf493b725a (diff)
From NetBSD: 960217 merge
Diffstat (limited to 'sys/kern/kern_lkm.c')
-rw-r--r--sys/kern/kern_lkm.c126
1 files changed, 75 insertions, 51 deletions
diff --git a/sys/kern/kern_lkm.c b/sys/kern/kern_lkm.c
index b04ae281ece..54a616e2ff3 100644
--- a/sys/kern/kern_lkm.c
+++ b/sys/kern/kern_lkm.c
@@ -1,4 +1,5 @@
-/* $NetBSD: kern_lkm.c,v 1.26 1995/10/10 00:23:20 thorpej Exp $ */
+/* $OpenBSD: kern_lkm.c,v 1.2 1996/03/03 17:19:47 niklas Exp $ */
+/* $NetBSD: kern_lkm.c,v 1.28 1996/02/09 18:59:38 christos Exp $ */
/*
* Copyright (c) 1994 Christopher G. Demetriou
@@ -44,7 +45,6 @@
#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>
@@ -53,6 +53,10 @@
#include <sys/malloc.h>
#include <sys/mount.h>
#include <sys/exec.h>
+#include <sys/syscallargs.h>
+
+#include <kern/kern_conf.h>
+
#include <sys/lkm.h>
#include <sys/syscall.h>
@@ -60,6 +64,7 @@
#include <vm/vm_param.h>
#include <vm/vm_kern.h>
+
#define PAGESIZE 1024 /* kmem_alloc() allocation quantum */
#define LKM_ALLOC 0x01
@@ -81,6 +86,18 @@ static int lkm_state = LKMS_IDLE;
static struct lkm_table lkmods[MAXLKMS]; /* table of loaded modules */
static struct lkm_table *curp; /* global for in-progress ops */
+static void lkmunreserve __P((void));
+static int _lkm_syscall __P((struct lkm_table *, int));
+static int _lkm_vfs __P((struct lkm_table *, int));
+static int _lkm_dev __P((struct lkm_table *, int));
+#ifdef STREAMS
+static int _lkm_strmod __P((struct lkm_table *, int));
+#endif
+static int _lkm_exec __P((struct lkm_table *, int));
+
+int lkmexists __P((struct lkm_table *));
+int lkmdispatch __P((struct lkm_table *, int));
+
/*ARGSUSED*/
int
lkmopen(dev, flag, devtype, p)
@@ -107,7 +124,8 @@ lkmopen(dev, flag, devtype, p)
* Sleep pending unlock; we use tsleep() to allow
* an alarm out of the open.
*/
- if (error = tsleep((caddr_t)&lkm_v, TTIPRI|PCATCH, "lkmopn", 0))
+ error = tsleep((caddr_t)&lkm_v, TTIPRI|PCATCH, "lkmopn", 0);
+ if (error)
return (error); /* leave LKM_WANT set -- no problem */
}
lkm_v |= LKM_ALLOC;
@@ -120,7 +138,7 @@ lkmopen(dev, flag, devtype, p)
* 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
+static void
lkmunreserve()
{
@@ -171,19 +189,19 @@ lkmclose(dev, flag, mode, p)
/*ARGSUSED*/
int
-lkmioctl(dev, cmd, data, flag)
+lkmioctl(dev, cmd, data, flag, p)
dev_t dev;
u_long cmd;
caddr_t data;
int flag;
+ struct proc *p;
{
- int err = 0;
+ int error = 0;
int i;
struct lmc_resrv *resrvp;
struct lmc_loadbuf *loadbufp;
struct lmc_unload *unloadp;
struct lmc_stat *statp;
- int (*funcp)();
char istr[MAXLKMNAME];
switch(cmd) {
@@ -203,7 +221,7 @@ lkmioctl(dev, cmd, data, flag)
if (!lkmods[i].used)
break;
if (i == MAXLKMS) {
- err = ENOMEM; /* no slots available */
+ error = ENOMEM; /* no slots available */
break;
}
curp = &lkmods[i];
@@ -243,12 +261,14 @@ lkmioctl(dev, cmd, data, flag)
|| i < 0
|| i > MODIOBUF
|| i > curp->size - curp->offset) {
- err = ENOMEM;
+ error = ENOMEM;
break;
}
/* copy in buffer full of data */
- if (err = copyin((caddr_t)loadbufp->data, (caddr_t)curp->area + curp->offset, i))
+ error = copyin(loadbufp->data,
+ (caddr_t)curp->area + curp->offset, i);
+ if (error)
break;
if ((curp->offset + i) < curp->size) {
@@ -302,10 +322,12 @@ lkmioctl(dev, cmd, data, flag)
return ENXIO;
}
- curp->entry = (int (*)()) (*((long *) (data)));
+ curp->entry = (int (*) __P((struct lkm_table *, int, int)))
+ (*((long *) (data)));
/* call entry(load)... (assigns "private" portion) */
- if (err = (*(curp->entry))(curp, LKM_E_LOAD, LKM_VERSION)) {
+ error = (*(curp->entry))(curp, LKM_E_LOAD, LKM_VERSION);
+ if (error) {
/*
* Module may refuse loading or may have a
* version mismatch...
@@ -337,8 +359,9 @@ lkmioctl(dev, cmd, data, flag)
* Copy name and lookup id from all loaded
* modules. May fail.
*/
- if (err = copyinstr(unloadp->name, istr, MAXLKMNAME-1,
- (size_t *)0))
+ error = copyinstr(unloadp->name, istr, MAXLKMNAME-1,
+ NULL);
+ if (error)
break;
/*
@@ -357,20 +380,20 @@ lkmioctl(dev, cmd, data, flag)
* Range check the value; on failure, return EINVAL
*/
if (i < 0 || i >= MAXLKMS) {
- err = EINVAL;
+ error = EINVAL;
break;
}
curp = &lkmods[i];
if (!curp->used) {
- err = ENOENT;
+ error = ENOENT;
break;
}
/* call entry(unload) */
if ((*(curp->entry))(curp, LKM_E_UNLOAD, LKM_VERSION)) {
- err = EBUSY;
+ error = EBUSY;
break;
}
@@ -402,7 +425,7 @@ lkmioctl(dev, cmd, data, flag)
}
if (i == MAXLKMS) { /* Not found */
- err = ENOENT;
+ error = ENOENT;
break;
}
}
@@ -411,14 +434,14 @@ lkmioctl(dev, cmd, data, flag)
* Range check the value; on failure, return EINVAL
*/
if (i < 0 || i >= MAXLKMS) {
- err = EINVAL;
+ error = EINVAL;
break;
}
curp = &lkmods[i];
if (!curp->used) { /* Not found */
- err = ENOENT;
+ error = ENOENT;
break;
}
@@ -440,11 +463,11 @@ lkmioctl(dev, cmd, data, flag)
break;
default: /* bad ioctl()... */
- err = ENOTTY;
+ error = ENOTTY;
break;
}
- return (err);
+ return (error);
}
/*
@@ -528,7 +551,7 @@ _lkm_syscall(lkmtp, cmd)
{
struct lkm_syscall *args = lkmtp->private.lkm_syscall;
int i;
- int err = 0;
+ int error = 0;
switch(cmd) {
case LKM_E_LOAD:
@@ -545,12 +568,12 @@ _lkm_syscall(lkmtp, cmd)
break; /* found it! */
/* out of allocable slots? */
if (i == SYS_MAXSYSCALL) {
- err = ENFILE;
+ error = ENFILE;
break;
}
} else { /* assign */
if (i < 0 || i >= SYS_MAXSYSCALL) {
- err = EINVAL;
+ error = EINVAL;
break;
}
}
@@ -579,7 +602,7 @@ _lkm_syscall(lkmtp, cmd)
break;
}
- return (err);
+ return (error);
}
/*
@@ -593,7 +616,7 @@ _lkm_vfs(lkmtp, cmd)
{
struct lkm_vfs *args = lkmtp->private.lkm_vfs;
int i;
- int err = 0;
+ int error = 0;
switch(cmd) {
case LKM_E_LOAD:
@@ -605,7 +628,8 @@ _lkm_vfs(lkmtp, cmd)
for (i = 0; i < nvfssw; i++)
if (vfssw[i] != (struct vfsops *)0 &&
strncmp(vfssw[i]->vfs_name,
- args->lkm_vfsops->vfs_name, MFSNAMELEN) == 0)
+ args->lkm_vfsops->vfs_name,
+ MFSNAMELEN) == 0)
return (EEXIST);
/* pick the last available empty slot */
@@ -613,7 +637,7 @@ _lkm_vfs(lkmtp, cmd)
if (vfssw[i] == (struct vfsops *)0)
break;
if (i == -1) { /* or if none, punt */
- err = EINVAL;
+ error = EINVAL;
break;
}
@@ -647,7 +671,7 @@ _lkm_vfs(lkmtp, cmd)
break;
}
- return (err);
+ return (error);
}
/*
@@ -661,7 +685,7 @@ _lkm_dev(lkmtp, cmd)
{
struct lkm_dev *args = lkmtp->private.lkm_dev;
int i;
- int err = 0;
+ int error = 0;
extern int nblkdev, nchrdev; /* from conf.c */
switch(cmd) {
@@ -681,12 +705,12 @@ _lkm_dev(lkmtp, cmd)
break; /* found it! */
/* out of allocable slots? */
if (i == nblkdev) {
- err = ENFILE;
+ error = ENFILE;
break;
}
} else { /* assign */
if (i < 0 || i >= nblkdev) {
- err = EINVAL;
+ error = EINVAL;
break;
}
}
@@ -711,12 +735,12 @@ _lkm_dev(lkmtp, cmd)
break; /* found it! */
/* out of allocable slots? */
if (i == nchrdev) {
- err = ENFILE;
+ error = ENFILE;
break;
}
} else { /* assign */
if (i < 0 || i >= nchrdev) {
- err = EINVAL;
+ error = EINVAL;
break;
}
}
@@ -733,7 +757,7 @@ _lkm_dev(lkmtp, cmd)
break;
default:
- err = ENODEV;
+ error = ENODEV;
break;
}
break;
@@ -754,7 +778,7 @@ _lkm_dev(lkmtp, cmd)
break;
default:
- err = ENODEV;
+ error = ENODEV;
break;
}
break;
@@ -763,7 +787,7 @@ _lkm_dev(lkmtp, cmd)
break;
}
- return (err);
+ return (error);
}
#ifdef STREAMS
@@ -778,7 +802,7 @@ _lkm_strmod(lkmtp, cmd)
{
struct lkm_strmod *args = lkmtp->private.lkm_strmod;
int i;
- int err = 0;
+ int error = 0;
switch(cmd) {
case LKM_E_LOAD:
@@ -794,7 +818,7 @@ _lkm_strmod(lkmtp, cmd)
break;
}
- return (err);
+ return (error);
}
#endif /* STREAMS */
@@ -809,7 +833,7 @@ _lkm_exec(lkmtp, cmd)
{
struct lkm_exec *args = lkmtp->private.lkm_exec;
int i;
- int err = 0;
+ int error = 0;
switch(cmd) {
case LKM_E_LOAD:
@@ -826,12 +850,12 @@ _lkm_exec(lkmtp, cmd)
break; /* found it! */
/* out of allocable slots? */
if (i == nexecs) {
- err = ENFILE;
+ error = ENFILE;
break;
}
} else { /* assign */
if (i < 0 || i >= nexecs) {
- err = EINVAL;
+ error = EINVAL;
break;
}
}
@@ -866,7 +890,7 @@ _lkm_exec(lkmtp, cmd)
break;
}
- return (err);
+ return (error);
}
/*
@@ -880,19 +904,19 @@ lkmdispatch(lkmtp, cmd)
struct lkm_table *lkmtp;
int cmd;
{
- int err = 0; /* default = success */
+ int error = 0; /* default = success */
switch(lkmtp->private.lkm_any->lkm_type) {
case LM_SYSCALL:
- err = _lkm_syscall(lkmtp, cmd);
+ error = _lkm_syscall(lkmtp, cmd);
break;
case LM_VFS:
- err = _lkm_vfs(lkmtp, cmd);
+ error = _lkm_vfs(lkmtp, cmd);
break;
case LM_DEV:
- err = _lkm_dev(lkmtp, cmd);
+ error = _lkm_dev(lkmtp, cmd);
break;
#ifdef STREAMS
@@ -905,16 +929,16 @@ lkmdispatch(lkmtp, cmd)
#endif /* STREAMS */
case LM_EXEC:
- err = _lkm_exec(lkmtp, cmd);
+ error = _lkm_exec(lkmtp, cmd);
break;
case LM_MISC: /* ignore content -- no "misc-specific" procedure */
break;
default:
- err = ENXIO; /* unknown type */
+ error = ENXIO; /* unknown type */
break;
}
- return (err);
+ return (error);
}