无法在BUG()调用后卸载Linux内核模块

问题描述 投票:0回答:1

这里是我的基本内核模块代码。

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

MODULE_LICENSE("GPL");
static int test_bug_init(void)
{
    printk(KERN_INFO"%s: In init\n", __func__);
    BUG();
    return 0;
}

static void test_bug_exit(void)
{
    printk(KERN_INFO"%s: In exit\n", __func__);
}

module_init(test_bug_init);
module_exit(test_bug_exit);

当我加载此模块时,它已成功加载,但是在卸载时会收到类似“模块正在使用”的消息。

所以,为什么我们在调用BUG()之后不能卸载模块?还有另一种卸载模块的方法吗?

c linux-kernel operating-system linux-device-driver kernel-module
1个回答
0
投票

在内核源代码中,您可以看到BUG()代码最终会调用unreachable()宏:

unreachable()

由于其中存在无限循环,因此使用了init函数# define unreachable() do { } while (1) -无法返回。通过添加类似的内容来验证]

test_bug_init()

所以您不会在日志中看到此打印。

也请阅读://... BUG(); printk(KERN_INFO "%s: After BUG()\n", __func__);

© www.soinside.com 2019 - 2024. All rights reserved.