--- /dev/null
+ifneq ($(KERNELRELEASE),)
+ obj-y += hello/
+ obj-y += mproc/
+else
+ KERNELDIR ?= /usr/src/linux
+ PWD := $(shell pwd)
+default:
+ $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
+endif
--- /dev/null
+several kernel modules
+----------------------
+
+build:
+******
+
+ - link this directory into the kernel source tree
+
+ example:
+
+ ln -s $PWD /usr/src/linux/driver/misc/foo
+
+ - add a line containing 'obj-y += foo/' to the Makefile
+
+ example:
+
+ echo "obj-y +=foo/" >> /usr/src/linux/driver/misc/Makefile
+
+ - build the modules
+
+ example:
+
+ make
+
+ or if that doesnt' work ...
+
+ make -C /usr/src/linux SUBDIRS=$PWD modules
+
+
+what is what:
+*************
+
+h3ll0.c - the hello world kernel module
+mproc.c - process monitor in kernelspace
+
+++ /dev/null
-/* general stuff */
-
-#define ME_THE_AUTHOR "hackbard/qubit http://hackdaworld.dyndns.org"
-
+++ /dev/null
-# Makefile of hello.o - my first kernel module.
-
-INCLUDEDIR = /usr/include
-CC = gcc
-CFLAGS = -D__KERNEL__ -DMODULE -O -Wall # -I$(INCLUDEDIR)
-
-# findout kernel version.
-VER = $(shell awk -F\" '/REL/ {print $$2}' $(INCLUDEDIR)/linux/version.h)
-
-OBJS = hello.o hello-1.o
-
-all: $(OBJS)
-
-#hello.o: hello.o
-# $(LD) -r $^ -o $@
-
-install:
- install -d /lib/modules/$(VER)/misc
- install -c hello.o /lib/modules/$(VER)/misc
-
-clean:
- rm -f *.o *~ core
-
-uninstall:
- rm -f /lib/modules/$(VER)/misc/hello.o
-
+++ /dev/null
-/* hello world */
-
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/init.h>
-#include "../general.h"
-
-#if CONFIG_MODVERSIONS==1
- #define MODVERSIONS
-#endif
-
-#include <linux/devfs_fs_kernel.h>
-
-#ifndef CONFIG_DEVFS_FS
- #error no devfs
-#endif
-
-#include <sys/syscall.h>
-#include <linux/sched.h>
-
-extern void *sys_call_table[];
-
-static devfs_handle_t devfs_handle;
-
-static struct file_operations fops =
-{
- .read=device_read,
- .write=device_write,
- .open=device_open,
- .release=device_release,
- .ioctl=device_ioctl
-}
-
-int my_uid=0;
-char *parm_string="blah";
-
-MODULE_PARM(my_uid,"i");
-MODULE_PARM(parm_string,"s");
-
-int my_init(void)
-{
- devfs_handle=devfs_register(NULL,"hackbard/1",DEVFS_FL_DEFAULT,0,0,
- printk(KERN_ALERT "module loaded with uid %d, string %s\n",my_uid,parm_string);
- return 0;
-}
-
-void my_cleanup(void)
-{
- printk(KERN_ALERT "module unloaded\n");
-}
-
-module_init(my_init);
-module_exit(my_cleanup);
-
-MODULE_AUTHOR(ME_THE_AUTHOR);
-MODULE_DESCRIPTION("bullshit ;)");
-MODULE_LICENSE("GPL");
-
+++ /dev/null
-/* my first kernel driver :-) */
-
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/sched.h>
-
-int init_module(void) {
- printk(KERN_ALERT "hi hackbard, here is your kernel speaking! :)\n");
- printk(KERN_ALERT "some info : %s has process id %i\n",current->comm,
- current->pid);
- return 0;
-}
-
-void cleanup_module(void) {
- printk(KERN_ALERT "bye hackbard ...\n");
-}
-
--- /dev/null
+obj-m += mproc.o
--- /dev/null
+/*
+ * mproc kernel module
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/config.h>
+#include <linux/init.h>
+#include <linux/sched.h>
+
+MODULE_LICENSE("GPL");
+
+static int __init mproc_init(void)
+{
+ printk(KERN_INFO "mproc module loaded\n");
+ printk(KERN_INFO "process: %s | pid: %i\n",
+ current->comm,current->pid);
+ return 0;
+}
+
+static void __exit mproc_exit(void)
+{
+ printk(KERN_INFO "process: %s | pid: %i\n",
+ current->comm,current->pid);
+ printk(KERN_INFO "mproc module unloaded\n");
+}
+
+module_init(mproc_init);
+module_exit(mproc_exit);