内核模块 (二) LKM加载

open("printk_test.ko", O_RDONLY|O_LARGEFILE) = 3  // 打开二进制文件,文件描述符为3
read(3, "\177E", 2)                     = 2  // 打开并读取两个字节, '\177' 'E'
_llseek(3, -2, [0], SEEK_CUR)           = 0 // 回到第一个字节.
fstat64(3, {st_mode=S_IFREG|0664, st_size=34324, ...}) = 0 // 获取保护模式,字节数
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\1\0(\0\1\0\0\0\0\0\0\0\0\0\0\0"..., 34816) = 34324 // 读取所有的字节
read(3, "", 492)                        = 0 // 在读一次,直到0
close(3)                                = 0 //关闭
init_module(0x132088, 34324, """\001" "0" level 0! // load a kernel module 地址为 0x132088 ,长度为 34324 , 参数为空 "",从 "\001" 就是打印 // man 2 init_module
KERN_EMERG level 0!
pr_emerg level 0!
"\001" "6" level 6!
KERN_INFO level 6!
pr_info level 6!
"\001" "7" level 7!
KERN_DEBUG level 7!
"\001" "d" level default!
KERN_DEFAULT level d!
KERN_DEFAULT level d!
printk contpr_cont cont
)        = 0
exit_group(0)                           = ?
+++ exited with 0 +++

# insmod printk_test.ko 
"\001" "0" level 0!
KERN_EMERG level 0!
pr_emerg level 0!
"\001" "6" level 6!
KERN_INFO level 6!
pr_info level 6!
"\001" "7" level 7!
KERN_DEBUG level 7!
"\001" "d" level default!
KERN_DEFAULT level d!
KERN_DEFAULT level d!
printk contpr_cont cont
  • init_module

CPU: 0 PID: 711 Comm: insmod Tainted: G           O    4.0.0+ #34
Hardware name: ARM-Versatile Express
[<80016db0>] (unwind_backtrace) from [<80012cd8>] (show_stack+0x20/0x24)
[<80012cd8>] (show_stack) from [<80544e20>] (dump_stack+0x80/0x90)
[<80544e20>] (dump_stack) from [<7f004018>] (hello_init+0x18/0xbc [printk_test])
[<7f004018>] (hello_init [printk_test]) from [<80008acc>] (do_one_initcall+0x9c/0x1e4)
[<80008acc>] (do_one_initcall) from [<80542f68>] (do_init_module+0x70/0x1bc)
[<80542f68>] (do_init_module) from [<8008df80>] (load_module+0x1850/0x1ed8)
[<8008df80>] (load_module) from [<8008e730>] (SyS_init_module+0x128/0x138)
[<8008e730>] (SyS_init_module) from [<8000ec80>] (ret_fast_syscall+0x0/0x34)


kernel/module.c
	SYSCALL_DEFINE3(init_module, void __user *, umod,unsigned long, len, const char __user *, uargs)
		load_module(&info, uargs, 0);
			do_init_module(mod);
				do_one_initcall(mod->init);
					fn();
				
		

内核模块 (二) LKM加载_第1张图片

你可能感兴趣的:(驱动)