linux内核版本 2.6.39,linux – 为什么这个内核模块在2.6.39上被标记为永久

加载此模块时:

#include

#include

#include

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);

该模块在lsmod中被标记为[永久],不能卸载,在2.6.39-02063904-generic(从Ubuntu PPA).但它在默认的2.6.38内核上工作正常. (在Ubuntu 11.04 x86上).

2.6.39发生了什么变化?我的代码需要改变什么?

当我遇到这个问题时,我试图分离一个更复杂的问题.

编辑:

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

#include

#include

#include

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'

EDIT2:

hello3.mod.c:

#include

#include

#include

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

EDIT3:

更有趣的是,我自己编译的香草内核不会发生这种情况

加载和卸载模块正常.

EDIT4:

我在虚拟机上安装了Oneiric beta 2内核,而3.0.0-11内核也没有任何问题.所以它似乎局限于Ubuntu香草PPA内核.这不是很有趣的解决.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值