-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeveloperGuide
64 lines (43 loc) · 1.9 KB
/
DeveloperGuide
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
@@ This LKM Developer Guide created for simple kernel modules. @@
Testing on ubuntu 18.04
@Install package:
# os's spesific kernel source and developer kit
$ sudo apt-get install build-essential linux-headers-$(uname -r)
@Makefile parameters for used compile lkm
make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) modules
@Programming main requires
## Headers
#include <linux/module.h> /* included all modules */
#include <linux/kernel.h> /* KERN_INFO */
#include <linux/init.h> /* for macro */
#include <linux/fs.h> /* for filp */
#include <asm/uaccess.h> /* for segment descriptors */
#include <linux/kthread.h> /* for thread */
#include <linux/delay.h> /* for delay msec */
## Macros
MODULE_LICENSE("GPL") -> LKM's type of licanse
MODULE_AUTHOR("Atakan Akbulut") -> author
MODULE_DESCRIPTION("Hello from LKM") -> you can explain lkm's descr.
MODULE_VERSION("0.1"); -> version info
## Install, remove, get lkm'm info
sudo insmod module.ko -> run lkm to kernel
sudo rmmod module.ko -> remove from kernel
sudo modinfo module.ko -> get info
@Debugging
## Kernel use printk instead of printf
KERN_EMERG -> mostly emergency crash
KERN_ALERT -> immediate action
KERN_CRIT
KERN_ERR -> for examle cannot find FUZE
KERN_WARNING
KERN_NOTICE
KERN_INFO
KERN_DEBUG
## logs inside dmesg or /var/log/kern.log
@@@@@ KERNEL_DS is instead of set_fs(get_fs()) probability higher than 5 kernel version
@@@@@ read / write functions vfs_read and vfs_write good..
@@@@@ filp_open -> file open like fopen offset perhaps 0 ..
@@@@@ filp_open modes -> O_RDONLY, O_CREAT, O_RDWR, ...
@@@@@ threading -> struct task_struct *ts1; (create task and start kthread)
kthread_run(kthread_func, NULL, "thread-pool-name")
@@@@@ current -> current->comm, current->pid return pool name and pid