在加载内核模块使用__init属性?(Is __init attribute used in loa

2019-10-23 17:18发布

-这说明http://www.tldp.org/LDP/lkmpg/2.4/html/x281.htm -页面(以及对SO一些相关的答案,例如答案在这里- __init和__exit宏使用情况内置和可加载模块 )说:

在__init宏导致init函数被丢弃的内存被释放,一旦初始化函数完成了内置的驱动程序,但没有可加载模块。

然而,我试图插入以下模块,其中,我试图从非init函数(F2())调用与__init属性初始化功能,并且我从内核错误,因此表明__init上具有效果可加载模块,以及。

我如何以及在哪里可以找到这个可靠的信息?

我的(上述)程序:

#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 

Answer 1:

其实, __init属性影响在可加载模块的代码。

也许,这是印错在你指的书。

顺便说一句,你应该得到有关部分建立时给定的模块不匹配警告。



文章来源: Is __init attribute used in loadable kernel modules?