diff options
author | Kyle K <kylek389@gmail.com> | 2012-12-22 00:31:53 -0600 |
---|---|---|
committer | Kyle Kaminski <kyle@kkaminsk.com> | 2012-12-22 00:31:53 -0600 |
commit | adbfb7c71fe1e958a2a2397c7b88c3061043c54e (patch) | |
tree | 28743080d118905dd5199f382a2f535d39c5b20b /main.c | |
download | kernelhello-adbfb7c71fe1e958a2a2397c7b88c3061043c54e.tar.gz kernelhello-adbfb7c71fe1e958a2a2397c7b88c3061043c54e.tar.bz2 kernelhello-adbfb7c71fe1e958a2a2397c7b88c3061043c54e.zip |
initial commit
this is a simple try of unuseful code in kernel space, debugfs is
used to create a dir and a file
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -0,0 +1,46 @@ +#include <linux/module.h> +#include <linux/version.h> +#include <linux/kernel.h> +#include <linux/init.h> +#include <linux/string.h> +/* used for kmalloc */ +#include <linux/slab.h> + +#include <debug.h> + +char *debugmsg = "Tesla coil is a hi freq transformer"; +struct dentry *debug_dir = NULL; +struct dentry *debug_file = NULL; + +/* __init is a hint that the func is only used at initialization time, then module + * loader drops the function after module is loaded making its memory available for other uses + */ +static int __init hello_init(void) +{ + int err = 0; + char *msg = (char *) kmalloc_array(128, sizeof(char), GFP_KERNEL /* kernel ram */); + + printk("module named hello inserted\n"); + strcpy(msg, "photon is the energy carrier particle for EM waves within light spectrum"); + printk("%s\n", msg); + kfree(msg); + + /* modifies passed in ptrs */ + err = debug_init(&debug_dir, &debug_file); + if (err) + printk("debugfs might not have been mounted\n"); + + return 0; +} + +static void __exit hello_exit(void) +{ + debug_destroy(debug_dir, debug_file); + printk("module named hello removed\n"); +} + +module_init(hello_init); +module_exit(hello_exit); + +MODULE_LICENSE("GPL"); + |