2014-09-17 20:51:24 +00:00
|
|
|
#include <linux/module.h> /* all kernel modules need this */
|
|
|
|
#include <linux/init.h> /* provides initialization routines */
|
|
|
|
|
|
|
|
#include <linux/kallsyms.h>
|
2014-09-18 15:48:25 +00:00
|
|
|
#include <linux/string.h>
|
2014-09-17 20:51:24 +00:00
|
|
|
|
2014-09-18 15:48:25 +00:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Vincent Batts <vbatts@hashbangbash.com>");
|
|
|
|
MODULE_DESCRIPTION("just getting familiar");
|
|
|
|
MODULE_VERSION("1.0");
|
|
|
|
|
|
|
|
//static char __initdata hello_hellomsg[] = KERN_NOTICE "Hello, Kernel, I'm in\n";
|
|
|
|
//static char __exitdata hello_byemsg[] = KERN_NOTICE "Bye, I'm out\n";
|
2014-09-17 20:51:24 +00:00
|
|
|
|
2014-09-17 21:03:42 +00:00
|
|
|
static int hello_print_hello(void)
|
2014-09-17 20:51:24 +00:00
|
|
|
{
|
2014-09-18 15:48:25 +00:00
|
|
|
printk(KERN_INFO "[%s] module loaded.\n", __this_module.name);
|
2014-09-17 20:51:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-17 21:03:42 +00:00
|
|
|
long hello_fib(long times, long n1, long n2)
|
2014-09-17 20:51:24 +00:00
|
|
|
{
|
2014-09-17 21:03:42 +00:00
|
|
|
long i = 0;
|
|
|
|
long prev = n1;
|
|
|
|
long curr = n2;
|
|
|
|
long next = 0;
|
2014-09-17 20:51:24 +00:00
|
|
|
|
|
|
|
while (i < times)
|
|
|
|
{
|
|
|
|
next = (prev + curr);
|
|
|
|
prev = curr;
|
|
|
|
curr = next;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return next;
|
|
|
|
}
|
|
|
|
|
2014-09-18 15:48:25 +00:00
|
|
|
static int __init hello_init(void)
|
2014-09-17 20:51:24 +00:00
|
|
|
{
|
2014-09-17 21:03:42 +00:00
|
|
|
long f_int, f_cap, f_start1, f_start2;
|
2014-09-18 15:48:25 +00:00
|
|
|
unsigned long sym_addr;
|
|
|
|
char *sym_name;
|
|
|
|
char filename[255];
|
2014-09-17 21:03:42 +00:00
|
|
|
|
|
|
|
hello_print_hello();
|
|
|
|
|
2014-09-18 15:48:25 +00:00
|
|
|
sym_name = "files";
|
|
|
|
printk("looking up '%s'\n", sym_name);
|
|
|
|
sym_addr = kallsyms_lookup_name(sym_name);
|
|
|
|
printk("%s 0x%lx\n", sym_name, sym_addr);
|
|
|
|
|
|
|
|
strncpy(filename, (char *)sym_addr, 255);
|
|
|
|
printk(KERN_INFO "[%s] %s (0x%lx): %s\n", __this_module.name, sym_name, sym_addr, filename);
|
|
|
|
|
|
|
|
|
|
|
|
printk("[%s] jiffies: %lu\n", __this_module.name, jiffies);
|
2014-09-17 21:03:42 +00:00
|
|
|
f_cap = 10000000;
|
|
|
|
f_start1 = 0;
|
|
|
|
f_start2 = 1;
|
|
|
|
f_int = hello_fib(f_cap, f_start1, f_start2);
|
2014-09-17 20:51:24 +00:00
|
|
|
|
2014-09-17 21:03:42 +00:00
|
|
|
printk("fib of %ld and %ld (up to %ld): %ld\n", f_start1, f_start2, f_cap, f_int);
|
2014-09-18 15:48:25 +00:00
|
|
|
printk("[%s] jiffies: %lu\n", __this_module.name, jiffies);
|
2014-09-17 20:51:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-18 15:48:25 +00:00
|
|
|
static void __exit hello_cleanup(void)
|
2014-09-17 20:51:24 +00:00
|
|
|
{
|
2014-09-18 15:48:25 +00:00
|
|
|
printk(KERN_INFO "[%s] module unloaded.\n", __this_module.name);
|
2014-09-17 20:51:24 +00:00
|
|
|
}
|
|
|
|
|
2014-09-18 15:48:25 +00:00
|
|
|
module_init(hello_init);
|
|
|
|
module_exit(hello_cleanup);
|
2014-09-17 20:51:24 +00:00
|
|
|
|
|
|
|
// vim:set shiftwidth=4 softtabstop=4 expandtab:
|