summaryrefslogtreecommitdiffstats
path: root/share/examples
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>1995-12-25 07:19:32 +0000
committerbde <bde@FreeBSD.org>1995-12-25 07:19:32 +0000
commitc37e7feb99eeac77aa76f6347e3025858037c16a (patch)
tree87b8649103817b6ed4829289274a9483a44cc427 /share/examples
parent730abc9c1605bba24a76b58b113e50364f99b484 (diff)
downloadFreeBSD-src-c37e7feb99eeac77aa76f6347e3025858037c16a.zip
FreeBSD-src-c37e7feb99eeac77aa76f6347e3025858037c16a.tar.gz
Updated lkm examples to work with prototype-related changes to the
MOD_MISC() and DISPATCH() macros. Renamed new_syscall module as new_syscall_mod. It seems to be standard to have module names ending with _mod, and this may be forced when MOD_SYSCALL() and MOD_VFS() are updated to match MOD_MISC(). Cleaned up lkm examples a little.
Diffstat (limited to 'share/examples')
-rw-r--r--share/examples/lkm/Makefile4
-rw-r--r--share/examples/lkm/misc/Makefile4
-rw-r--r--share/examples/lkm/misc/module/Makefile5
-rw-r--r--share/examples/lkm/misc/module/misccall.c18
-rw-r--r--share/examples/lkm/misc/module/miscmod.c25
-rw-r--r--share/examples/lkm/misc/test/Makefile6
-rw-r--r--share/examples/lkm/misc/test/testmisc.c6
-rw-r--r--share/examples/lkm/syscall/Makefile4
-rw-r--r--share/examples/lkm/syscall/module/Makefile5
-rw-r--r--share/examples/lkm/syscall/module/mycall.c16
-rw-r--r--share/examples/lkm/syscall/module/newsyscall.c26
-rw-r--r--share/examples/lkm/syscall/test/Makefile8
-rw-r--r--share/examples/lkm/syscall/test/testsyscall.c9
13 files changed, 47 insertions, 89 deletions
diff --git a/share/examples/lkm/Makefile b/share/examples/lkm/Makefile
index be69959..1bf5d10 100644
--- a/share/examples/lkm/Makefile
+++ b/share/examples/lkm/Makefile
@@ -39,7 +39,3 @@
SUBDIR= syscall misc
.include <bsd.subdir.mk>
-
-#
-# EOF -- This file has not been truncated.
-#
diff --git a/share/examples/lkm/misc/Makefile b/share/examples/lkm/misc/Makefile
index b793cca..462c86c 100644
--- a/share/examples/lkm/misc/Makefile
+++ b/share/examples/lkm/misc/Makefile
@@ -42,7 +42,3 @@ load: _SUBDIRUSE
unload: _SUBDIRUSE
.include <bsd.subdir.mk>
-
-#
-# EOF -- This file has not been truncated.
-#
diff --git a/share/examples/lkm/misc/module/Makefile b/share/examples/lkm/misc/module/Makefile
index edb2998..108498b 100644
--- a/share/examples/lkm/misc/module/Makefile
+++ b/share/examples/lkm/misc/module/Makefile
@@ -34,7 +34,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
-# $Id$
+# $Id: Makefile,v 1.2 1995/07/27 09:44:35 joerg Exp $
#
BINDIR= /tmp
SRCS= misccall.c miscmod.c
@@ -44,6 +44,3 @@ NOMAN= none
CLEANFILES+= ${KMOD}
.include <bsd.kmod.mk>
-#
-# EOF -- This file has not been truncated
-#
diff --git a/share/examples/lkm/misc/module/misccall.c b/share/examples/lkm/misc/module/misccall.c
index 5cadafc..dd972c7 100644
--- a/share/examples/lkm/misc/module/misccall.c
+++ b/share/examples/lkm/misc/module/misccall.c
@@ -37,14 +37,15 @@
*/
#include <sys/param.h>
#include <sys/ioctl.h>
-#include <sys/proc.h>
#include <sys/systm.h>
+/* XXX this should be in a header. */
+extern int misccall __P((struct proc *p, void *uap, int retval[]));
/*
- * This is the actual code for system call... it can be static because
- * we've externed it up above... the only plae it needs to be referenced
- * is the sysent we are interested in.
+ * This is the actual code for the system call... it can't be static because
+ * it is exported to another part of the module... the only place it needs
+ * to be referenced is the sysent we are interested in.
*
* To write your own system call using this as a template, you could strip
* out this code and use the rest as a prototype module, changing only the
@@ -66,13 +67,10 @@ int retval[];
* arguments.
*/
- printf( "\nI am a loaded system call using the miscellaneous\n");
- printf( "module loader interface and a kernel printf!\n");
+ printf( "\nI am a loaded system call.\n");
+ printf( "I was loaded using the miscellaneous module loader interface.\n");
+ printf( "I don't do anything except call the kernel's printf().\n");
printf( "I will print this message each time I am called!\n");
return( 0); /* success (or error code from errno.h)*/
}
-
-/*
- * EOF -- This file has not been truncated.
- */
diff --git a/share/examples/lkm/misc/module/miscmod.c b/share/examples/lkm/misc/module/miscmod.c
index 0f5a38f..410b526 100644
--- a/share/examples/lkm/misc/module/miscmod.c
+++ b/share/examples/lkm/misc/module/miscmod.c
@@ -40,6 +40,7 @@
#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>
@@ -49,8 +50,8 @@
#include <sys/file.h>
#include <sys/errno.h>
-
-extern int misccall();
+/* XXX this should be in a header. */
+extern int misccall __P((struct proc *p, void *uap, int retval[]));
/*
* These two entries define our system call and module information. We
@@ -70,7 +71,7 @@ static struct sysent oldent; /* save are for old callslot entry*/
*/
#define nsysent (aout_sysvec.sv_size)
-MOD_MISC( "misc_mod")
+MOD_MISC( misc);
/*
@@ -86,18 +87,17 @@ MOD_MISC( "misc_mod")
* kick out the copyright to the console here (to give an example).
*
* The stat information is basically common to all modules, so there
- * is no real issue involved with stat; we will leave it nosys(),
+ * is no real issue involved with stat; we will leave it lkm_nullcmd(),
* cince we don't have to do anything about it.
*/
static int
-miscmod_handle( lkmtp, cmd)
+misc_load( lkmtp, cmd)
struct lkm_table *lkmtp;
int cmd;
{
int i;
struct lkm_misc *args = lkmtp->private.lkm_misc;
int err = 0; /* default = success*/
- extern int lkmnosys(); /* allocable slot*/
switch( cmd) {
case LKM_E_LOAD:
@@ -118,7 +118,7 @@ int cmd;
* Search the table looking for a slot...
*/
for( i = 0; i < nsysent; i++)
- if( sysent[ i].sy_call == lkmnosys)
+ if( sysent[ i].sy_call == (sy_call_t *)lkmnosys)
break; /* found it!*/
/* out of allocable slots?*/
if( i == nsysent) {
@@ -161,12 +161,11 @@ int cmd;
return( err);
}
-
/*
* External entry point; should generally match name of .o file. The
* arguments are always the same for all loaded modules. The "load",
* "unload", and "stat" functions in "DISPATCH" will be called under
- * their respective circumstances unless their value is "nosys". If
+ * their respective circumstances unless their value is "lkm_nullcmd". If
* called, they are called with the same arguments (cmd is included to
* allow the use of a single function, ver is included for version
* matching between modules and the kernel loader for the modules).
@@ -181,15 +180,11 @@ int cmd;
* The entry point should return 0 unless it is refusing load (in which
* case it should return an errno from errno.h).
*/
+int
misc_mod( lkmtp, cmd, ver)
struct lkm_table *lkmtp;
int cmd;
int ver;
{
- DISPATCH(lkmtp,cmd,ver,miscmod_handle,miscmod_handle,nosys)
+ DISPATCH(lkmtp, cmd, ver, misc_load, misc_load, lkm_nullcmd);
}
-
-
-/*
- * EOF -- This file has not been truncated.
- */
diff --git a/share/examples/lkm/misc/test/Makefile b/share/examples/lkm/misc/test/Makefile
index 61bbf37..4ea3a98 100644
--- a/share/examples/lkm/misc/test/Makefile
+++ b/share/examples/lkm/misc/test/Makefile
@@ -34,7 +34,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
-# $Id$
+# $Id: Makefile,v 1.2 1995/07/27 09:45:26 joerg Exp $
#
PROG= testmisc
NOMAN=
@@ -63,7 +63,3 @@ unload:
${MODSTAT} -n misc_mod
.include <bsd.prog.mk>
-
-#
-# EOF -- This file has not been truncated.
-#
diff --git a/share/examples/lkm/misc/test/testmisc.c b/share/examples/lkm/misc/test/testmisc.c
index 83f3338..b4d6eeb 100644
--- a/share/examples/lkm/misc/test/testmisc.c
+++ b/share/examples/lkm/misc/test/testmisc.c
@@ -47,7 +47,7 @@ main()
printf( "Table offset as reported by modstat: ");
fflush( stdout);
- if( fgets( buf, 80, stdin) == NULL) {
+ if( fgets( buf, sizeof buf, stdin) == NULL) {
printf( "[ABORT]\n");
exit( 1);
}
@@ -57,7 +57,3 @@ main()
exit( err);
}
-
-/*
- * EOF -- This file has not been truncated
- */
diff --git a/share/examples/lkm/syscall/Makefile b/share/examples/lkm/syscall/Makefile
index b793cca..462c86c 100644
--- a/share/examples/lkm/syscall/Makefile
+++ b/share/examples/lkm/syscall/Makefile
@@ -42,7 +42,3 @@ load: _SUBDIRUSE
unload: _SUBDIRUSE
.include <bsd.subdir.mk>
-
-#
-# EOF -- This file has not been truncated.
-#
diff --git a/share/examples/lkm/syscall/module/Makefile b/share/examples/lkm/syscall/module/Makefile
index 602b7a8..db45d8f 100644
--- a/share/examples/lkm/syscall/module/Makefile
+++ b/share/examples/lkm/syscall/module/Makefile
@@ -37,12 +37,9 @@
BINDIR= /tmp
SRCS= mycall.c newsyscall.c
-KMOD= new_syscall
+KMOD= newsyscall_mod
NOMAN= none
CLEANFILES+= ${KMOD}
.include <bsd.kmod.mk>
-#
-# EOF -- This file has not been truncated
-#
diff --git a/share/examples/lkm/syscall/module/mycall.c b/share/examples/lkm/syscall/module/mycall.c
index ac44399..71f5e51 100644
--- a/share/examples/lkm/syscall/module/mycall.c
+++ b/share/examples/lkm/syscall/module/mycall.c
@@ -39,11 +39,13 @@
#include <sys/ioctl.h>
#include <sys/systm.h>
+/* XXX this should be in a header. */
+extern int mycall __P((struct proc *p, void *uap, int retval[]));
/*
- * This is the actual code for system call... it can be static because
- * we've externed it up above... the only plae it needs to be referenced
- * is the sysent we are interested in.
+ * This is the actual code for the system call... it can't be static because
+ * it is exported to another part of the module... the only place it needs
+ * to be referenced is the sysent we are interested in.
*
* To write your own system call using this as a template, you could strip
* out this code and use the rest as a prototype module, changing only the
@@ -65,12 +67,10 @@ int retval[];
* arguments.
*/
- printf( "\nI am a loaded system call using the kernel printf!\n");
+ printf( "\nI am a loaded system call.\n");
+ printf( "I was loaded using the syscall module loader interface.\n");
+ printf( "I don't do anything except call the kernel's printf().\n");
printf( "I will print this message each time I am called!\n");
return( 0); /* success (or error code from errno.h)*/
}
-
-/*
- * EOF -- This file has not been truncated.
- */
diff --git a/share/examples/lkm/syscall/module/newsyscall.c b/share/examples/lkm/syscall/module/newsyscall.c
index 69d1f09..a6f04c9 100644
--- a/share/examples/lkm/syscall/module/newsyscall.c
+++ b/share/examples/lkm/syscall/module/newsyscall.c
@@ -1,6 +1,6 @@
/* 25 May 93*/
/*
- * Makefile for newsyscall
+ * newsyscall.c
*
* 05 Jun 93 Terry Lambert Split mycall.c out
* 25 May 93 Terry Lambert Original
@@ -49,8 +49,12 @@
#include <sys/file.h>
#include <sys/errno.h>
+/* XXX this should be in a header. */
+extern int mycall __P((struct proc *p, void *uap, int retval[]));
-extern int mycall();
+/* XXX these should be generated by MOD_SYSCALL(). */
+static int newsyscall_load __P((struct lkm_table *lkmtp, int cmd));
+extern int newsyscall_mod __P((struct lkm_table *lkmtp, int cmd, int ver));
/*
* These two entries define our system call and module information. We
@@ -60,12 +64,11 @@ static struct sysent newent = {
0, mycall /* # of args, function pointer*/
};
-MOD_SYSCALL( "new_syscall", -1, &newent)
-
+MOD_SYSCALL( "newsyscall_mod", -1, &newent);
/*
* This function is called each time the module is loaded. Technically,
- * we could have made this "nosys" in the "DISPATCH" in "newsyscall()",
+ * we could have made this "lkm_nullcmd" in the "DISPATCH" in "newsyscall()",
* but it's a convenient place to kick a copyright out to the console.
*/
static int
@@ -83,12 +86,11 @@ int cmd;
return( 0);
}
-
/*
* External entry point; should generally match name of .o file. The
* arguments are always the same for all loaded modules. The "load",
* "unload", and "stat" functions in "DISPATCH" will be called under
- * their respective circumstances unless their value is "nosys". If
+ * their respective circumstances unless their value is "lkm_nullcmd". If
* called, they are called with the same arguments (cmd is included to
* allow the use of a single function, ver is included for version
* matching between modules and the kernel loader for the modules).
@@ -103,15 +105,11 @@ int cmd;
* The entry point should return 0 unless it is refusing load (in which
* case it should return an errno from errno.h).
*/
-new_syscall( lkmtp, cmd, ver)
+int
+newsyscall_mod( lkmtp, cmd, ver)
struct lkm_table *lkmtp;
int cmd;
int ver;
{
- DISPATCH(lkmtp,cmd,ver,newsyscall_load,nosys,nosys)
+ DISPATCH(lkmtp, cmd, ver, newsyscall_load, lkm_nullcmd, lkm_nullcmd)
}
-
-
-/*
- * EOF -- This file has not been truncated.
- */
diff --git a/share/examples/lkm/syscall/test/Makefile b/share/examples/lkm/syscall/test/Makefile
index 419a19c..e14e527 100644
--- a/share/examples/lkm/syscall/test/Makefile
+++ b/share/examples/lkm/syscall/test/Makefile
@@ -50,7 +50,7 @@ load:
@echo "system console each time it is run."
@echo
@echo
- ${MODSTAT} -n new_syscall
+ ${MODSTAT} -n newsyscall_mod
@echo
@./testsyscall
@@ -59,10 +59,6 @@ unload:
@echo "has been successfully unloaded by building 'unload' in"
@echo "the 'module' subdirectory."
@echo
- ${MODSTAT} -n new_syscall
+ ${MODSTAT} -n newsyscall_mod
.include <bsd.prog.mk>
-
-#
-# EOF -- This file has not been truncated.
-#
diff --git a/share/examples/lkm/syscall/test/testsyscall.c b/share/examples/lkm/syscall/test/testsyscall.c
index 703d859..da57d3e 100644
--- a/share/examples/lkm/syscall/test/testsyscall.c
+++ b/share/examples/lkm/syscall/test/testsyscall.c
@@ -46,17 +46,14 @@ main()
int err = 0;
printf( "Table offset as reported by modstat: ");
- if( gets( buf) == NULL) {
+ fflush( stdout);
+ if( fgets( buf, sizeof buf, stdin) == NULL) {
printf( "[ABORT]\n");
exit( 1);
}
- if( err = syscall( atoi( buf) /* no arguments*/))
+ if(( err = syscall( atoi( buf) /* no arguments*/)))
perror( "syscall");
exit( err);
}
-
-/*
- * EOF -- This file has not been truncated
- */
OpenPOWER on IntegriCloud