可加载内核模块中是否使用__init属性? [英] Is __init attribute used in loadable kernel modules?

查看:80
本文介绍了可加载内核模块中是否使用__init属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处的描述- http://www.tldp. org/LDP/lkmpg/2.4/html/x281.htm -页面(以及关于SO的一些相关答案,例如此处的答案-

The description at this - http://www.tldp.org/LDP/lkmpg/2.4/html/x281.htm - page (as well as some related answers on SO, for example the answer here - __init and __exit macros usage for built-in and loadable modules ) says

__ init宏导致init函数针对内置驱动程序而不是可加载模块完成后,init函数将被丢弃并释放其内存.

The __init macro causes the init function to be discarded and its memory freed once the init function finishes for built-in drivers, but not loadable modules.

但是,我尝试插入以下模块,在该模块中,我尝试从非初始化函数(f2())中使用__init属性调用init函数,并且从内核中获取错误,从而表明__init具有对可加载模块也有影响.

However, I tried to insert the following module, in which I try to call the init functions with __init attribute from a non-init function (f2()), and I get error from the kernel, thus indicating that __init has an effect on loadable modules as well.

如何以及在哪里可以找到关于此的可靠信息?

How and where can I find reliable information about this?

我的程序(如上所述):

My (above mentioned) program:

#include<linux/module.h>
#include<linux/init.h>

static int __init f1(void){
        printk(KERN_ALERT "hello  \n");
        return 0;
}


static void __exit f2(void){
        f1();
        printk(KERN_ALERT "bye N\n");
}

module_init(f1);
module_exit(f2);

内核错误:

    Jul  8 08:15:51 localhost kernel: hello NOTICE 
    Jul  8 08:15:54 localhost kernel: [303032.948188] BUG: unable to handle kernel paging request at f9b13000
    Jul  8 08:15:54 localhost kernel: [303032.949003] IP: [<f9b13000>] 0xf9b12fff
    Jul  8 08:15:54 localhost kernel: [303032.949003] *pdpt = 0000000000d3c001 *pde = 000000003100b067 *pte = 0000000000000000 

Jul  8 08:15:54 localhost kernel: [303032.949003] Modules linked in: hello(POF-) tcp_lp lp wacom fuse bnep bluetooth ip6t_rpfilter ip6t_REJECT cfg80211 rfkill xt_conntrack ebtable_nat ebtable_broute bridge stp llc ebtable_filter ebtables ip6table_nat nf_conntrack_ipv6 nf_defrag_ipv6 nf_nat_ipv6 ip6table_mangle ip6table_security ip6table_raw ip6table_filter ip6_tables iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack iptable_mangle iptable_security iptable_raw joydev snd_hda_codec_realtek snd_hda_intel snd_hda_codec snd_hwdep snd_seq snd_seq_device snd_pcm coretemp kvm iTCO_wdt iTCO_vendor_support ppdev r8169 mii snd_page_alloc snd_timer snd soundcore microcode serio_raw i2c_i801 lpc_ich mfd_core parport_pc parport acpi_cpufreq mperf binfmt_misc nfsd auth_rpcgss nfs_acl lockd sunrpc i915 ata_generic i2c_algo_bit pata_acpi drm_kms_helper drm i2c_core video [last unloaded: hello]
Jul  8 08:15:54 localhost kernel: [303032.949003] CPU: 1 PID: 11924 Comm: rmmod Tainted: PF          O 3.11.10-301.fc20.i686+PAE #1
Jul  8 08:15:54 localhost kernel: [303032.949003] Hardware name:                  /DG41RQ, BIOS RQG4110H.86A.0013.2009.1223.1136 12/23/2009
Jul  8 08:15:54 localhost kernel: [303032.949003] task: d1bad780 ti: c33a4000 task.ti: c33a4000
Jul  8 08:15:54 localhost kernel: [303032.949003] EIP: 0060:[<f9b13000>] EFLAGS: 00010282 CPU: 1
Jul  8 08:15:54 localhost kernel: [303032.949003] EIP is at 0xf9b13000
Jul  8 08:15:54 localhost kernel: [303032.949003] EAX: f9af6000 EBX: f9af8000 ECX: c0c77270 EDX: 00000000
Jul  8 08:15:54 localhost kernel: [303032.949003] ESI: 00000000 EDI: 00000000 EBP: c33a5f3c ESP: c33a5f30
Jul  8 08:15:54 localhost kernel: [303032.949003]  DS: 007b ES: 007b FS: 00d8 GS: 00e0 SS: 0068
Jul  8 08:15:54 localhost kernel: [303032.949003] CR0: 8005003b CR2: f9b13000 CR3: 10e7b000 CR4: 000407f0
Jul  8 08:15:54 localhost kernel: [303032.949003] Stack:
Jul  8 08:15:54 localhost kernel: [303032.949003]  f9af600b 00000000 00000000 c33a5fac c04b06a9 f4852ac0 c33a5f50 c057989d
Jul  8 08:15:54 localhost kernel: [303032.949003]  00000000 f9af8000 00000800 c33a5f50 6c6c6568 0000006f f4852ac0 f5312490
Jul  8 08:15:54 localhost kernel: [303032.949003]  db5e7100 00000000 d1bad780 d1bada9c c33a5f88 c056160d c33a5f9c c046e9de
Jul  8 08:15:54 localhost kernel: [303032.949003] Call Trace:
Jul  8 08:15:54 localhost kernel: [303032.949003]  [<f9af600b>] ? f2+0xb/0x1000 [hello]
Jul  8 08:15:54 localhost kernel: [303032.949003]  [<c04b06a9>] SyS_delete_module+0x149/0x2a0
Jul  8 08:15:54 localhost kernel: [303032.949003]  [<c057989d>] ? mntput+0x1d/0x30
Jul  8 08:15:54 localhost kernel: [303032.949003]  [<c056160d>] ? ____fput+0xd/0x10
Jul  8 08:15:54 localhost kernel: [303032.949003]  [<c046e9de>] ? task_work_run+0x7e/0xb0
Jul  8 08:15:54 localhost kernel: [303032.949003]  [<c099ff0d>] sysenter_do_call+0x12/0x28
Jul  8 08:15:54 localhost kernel: [303032.949003] Code:  Bad EIP value.
Jul  8 08:15:54 localhost kernel: [303032.949003] EIP: [<f9b13000>] 0xf9b13000 SS:ESP 0068:c33a5f30
Jul  8 08:15:54 localhost kernel: [303032.949003] CR2: 00000000f9b13000
Jul  8 08:15:54 localhost kernel: [303032.949003] ---[ end trace ca338922043618f4 ]---
Jul  8 08:15:54 localhost kernel: BUG: unable to handle kernel paging request at f9b13000
Jul  8 08:15:54 localhost kernel: IP: [<f9b13000>] 0xf9b12fff
Jul  8 08:15:54 localhost kernel: *pdpt = 0000000000d3c001 *pde = 000000003100b067 *pte = 0000000000000000 

推荐答案

实际上,__init属性会影响可加载模块的代码.

Actually, __init attribute affects on loadable modules code.

可能是您所指书中的印刷错误.

Probably, this is misprint in the book you refers.

顺便说一句,在构建给定模块时,您应该收到有关节不匹配的警告.

BTW, you should get warning about sections mismatching when build given module.

这篇关于可加载内核模块中是否使用__init属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆