gpt4 book ai didi

linux - 为什么这个内核模块在 2.6.39 上标记为永久

转载 作者:IT王子 更新时间:2023-10-29 00:11:51 25 4
gpt4 key购买 nike

当我加载这个模块时:

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

MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void) {
printk("<1> Hello world!\n");
return 0;
}

static void hello_exit(void) {
printk("<1> Bye, cruel world\n");
}


module_init(hello_init);
module_exit(hello_exit);

(来自http://www.freesoftwaremagazine.com/articles/drivers_linux?page=0,2)

该模块在 lsmod 中被标记为 [permanent] 并且无法在 2.6.39-02063904-generic 上卸载(来自 Ubuntu PPA )。但它在默认的 2.6.38 内核上运行良好。 (均在 Ubuntu 11.04 x86 上)。

2.6.39 有什么变化?我的代码需要更改什么?

当我遇到这个问题时,我试图找出一个更复杂的问题。

编辑:

根据答案的建议,我编辑了代码以添加 __init__exit (hello3.c):

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

MODULE_LICENSE("Dual BSD/GPL");

static int __init hello_init(void) {
printk("<1> Hello world!\n");
return 0;
}

static void __exit hello_exit(void) {
printk("<1> Bye, cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);

构建输出:

make -C /lib/modules/2.6.39-02063904-generic/build M=/home/douglas/kernelmod modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.39-02063904-generic'
Building with KERNELRELEASE = 2.6.39-02063904-generic
CC [M] /home/douglas/kernelmod/hello3.o
Building modules, stage 2.
Building with KERNELRELEASE = 2.6.39-02063904-generic
MODPOST 8 modules
CC /home/douglas/kernelmod/hello3.mod.o
LD [M] /home/douglas/kernelmod/hello3.ko
make[1]: Leaving directory `/usr/src/linux-headers-2.6.39-02063904-generic'

编辑2:

hello3.mod.c:

#include <linux/module.h>
#include <linux/vermagic.h>
#include <linux/compiler.h>

MODULE_INFO(vermagic, VERMAGIC_STRING);

struct module __this_module
__attribute__((section(".gnu.linkonce.this_module"))) = {
.name = KBUILD_MODNAME,
.init = init_module,
#ifdef CONFIG_MODULE_UNLOAD
.exit = cleanup_module,
#endif
.arch = MODULE_ARCH_INIT,
};

static const struct modversion_info ____versions[]
__used
__attribute__((section("__versions"))) = {
{ 0xbe4b3e92, "module_layout" },
{ 0xb4390f9a, "mcount" },
{ 0x5e3b3ab4, "printk" },
};

static const char __module_depends[]
__used
__attribute__((section(".modinfo"))) =
"depends=";


MODULE_INFO(srcversion, "D2A869459874C22AB265981");

还有

# grep CONFIG_MODULE_UNLOAD /boot/config-2.6.39-02063904-generic 
CONFIG_MODULE_UNLOAD=y

编辑3:

更有趣的是,我自己编译的 Vanilla 内核不会发生这种情况 - 那加载和卸载模块正常。

编辑4:

我在虚拟机上安装了 Oneiric beta 2 build,那个 3.0.0-11 内核也没有任何问题。所以它似乎仅限于 Ubuntu Vanilla PPA 内核。解决这个问题不会很有趣。

最佳答案

所以,在咨询了 Canonical 之后,我知道问题出在哪里了:

Ubuntu mainline builds使用 Hardy 工具链构建,11.04 和 11.10 工具链不兼容构建树外内核模块。

关于linux - 为什么这个内核模块在 2.6.39 上标记为永久,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7482469/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com