Created
December 22, 2019 04:50
-
-
Save cvam0000/b2b37e7b88cfb2426c6f4874a9d804eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* An example of Memory Allocation */ | |
#include<linux/slab.h> | |
#include<linux/init.h> | |
#include<linux/module.h> | |
#include<linux/kernel.h> | |
#define size 10 | |
MODULE_DESCRIPTION("example of memory allocation "); | |
MODULE_AUTHOR("cvam"); | |
MODULE_LICENSE("GPL"); | |
int alloc_init(void) | |
{ | |
void *pointer; | |
pointer = kmalloc(size, GFP_KERNEL); | |
if(!pointer) | |
{ printk(KERN_ALERT" Faild "); | |
//report error | |
} | |
printk(" I got : %zu Byes", ksize(pointer)); | |
kfree(pointer); | |
return 0; | |
} | |
void alloc_exit(void) | |
{ | |
printk(KERN_ALERT"Time to exit"); | |
} | |
module_init(alloc_init); | |
module_exit(alloc_exit); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment