Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <linux/module.h>
  2. #include <linux/init.h>
  3. #include <linux/slab.h>
  4.  
  5. struct kmem_cache * cache;
  6. void * object;
  7.  
  8. static __init int cache_init(void)
  9. {
  10. cache = kmem_cache_create("super_cache", 4096, 0, SLAB_HWCACHE_ALIGN, NULL);
  11. pr_info("Cache allocated: %s", cache->name);
  12. object = kmem_cache_alloc(cache, GFP_KERNEL);
  13. object = "My super dupper object";
  14. pr_info("Value: %s", object);
  15. return 0;
  16. }
  17.  
  18. static __exit void cache_exit(void)
  19. {
  20. kmem_cache_free(cache, NULL);
  21. }
  22.  
  23. module_init(cache_init);
  24. module_exit(cache_exit);
  25. MODULE_AUTHOR("A buckhead");
  26. MODULE_LICENSE("GPL v2");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement