initial commit
This commit is contained in:
commit
e929dbcb6f
2 changed files with 71 additions and 0 deletions
7
Makefile
Normal file
7
Makefile
Normal file
|
@ -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
|
64
mod_hello.c
Normal file
64
mod_hello.c
Normal file
|
@ -0,0 +1,64 @@
|
|||
#include <linux/module.h> /* all kernel modules need this */
|
||||
#include <linux/init.h> /* provides initialization routines */
|
||||
|
||||
#include <linux/kallsyms.h>
|
||||
|
||||
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 <vbatts@hashbangbash.com>");
|
||||
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:
|
Loading…
Reference in a new issue