commit e929dbcb6f137809033a7f8a988fdf6b870e9852 Author: Vincent Batts Date: Wed Sep 17 16:51:24 2014 -0400 initial commit diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..571a323 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +obj-m += mod_hello.o + +all: + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules + +clean: + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean diff --git a/mod_hello.c b/mod_hello.c new file mode 100644 index 0000000..8c15991 --- /dev/null +++ b/mod_hello.c @@ -0,0 +1,64 @@ +#include /* all kernel modules need this */ +#include /* provides initialization routines */ + +#include + +static char __initdata hellomsg[] = KERN_NOTICE "Hello, Kernel, I'm in\n"; +static char __exitdata byemsg[] = KERN_NOTICE "Bye, I'm out\n"; + +static int print_hello(void) +{ + unsigned long i; + char *symbol_name; + + printk(hellomsg); + + symbol_name = "free_pages"; + printk("looking up '%s'\n", symbol_name); + i = kallsyms_lookup_name(symbol_name); + printk("%s 0x%lx\n", symbol_name, i); + + return 0; +} + +int fib(int times, int n1, int n2) +{ + int i = 0; + int prev = n1; + int curr = n2; + int next = 0; + + while (i < times) + { + next = (prev + curr); + prev = curr; + curr = next; + i++; + } + + return next; +} + +static int __init start_hello_world(void) +{ + int f_int; + MODULE_LICENSE("GPL"); + MODULE_AUTHOR("Vincent Batts "); + MODULE_DESCRIPTION("i am just reading headers"); + MODULE_VERSION("1.0"); + print_hello(); + + f_int = fib(10000000, 0, 1); + + return 0; +} + +static void __exit go_away(void) +{ + printk(byemsg); +} + +module_init(start_hello_world); +module_exit(go_away); + +// vim:set shiftwidth=4 softtabstop=4 expandtab: