I need to generate oops linux kernel error. I am using linux-3.13.3 and launching it on qemu. I found a following code which should cause the oops error:
#include <linux/module.h>
#include <linux/kernel.h>
static int crash_module_init(void)
{
printk(KERN_INFO "crash module starting\n");
int *p = 0;
printk("%d\n", *p);
return 0;
}
static void crash_module_exit(void)
{
printk(KERN_INFO "crash module exiting\n");
}
module_init(crash_module_init);
module_exit(crash_module_exit);
and I used the following Makefile:
obj-m = hello.o
KVERSION = $(shell uname -r)
all:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean
Unfortunately on qemu there's no such directory as /lib/modules/3.13.3/build. There is only /lib/modules/3.2.0-4-686-pae and inside some directories (but no build). Even when I tried to put there one of the existing directory I got: "No rule to make target modules
".
Can somebody tell me how to compile this module? Or maybe someone has another idea how to generate oops error? I would be very grateful.