1

我写了一个简单的 jiffies 代码,当我尝试做 rmmod 我得到

ERROR: Removing 'jiffi_module': Device or resource busy

所以我做了一些研究,发现通过在“永久”症状下执行 lsmod 是由未找到 exit_function 引起的问题。

Module                  Size  Used by
jiffi_module            1027  0 **[permanent]**

事实上,我的 make 文件确实向我显示了与退出功能相关的警告

退出函数定义为时的警告

static void __exit
jif_exit(void)
{
    remove_proc_entry("jif", NULL);
}

warning: data definition has no type or storage class
warning: type defaults to ‘int’ in declaration of ‘modile_exit’
warning: parameter names (without types) in function declaration
warning: ‘jif_exit’ defined but not used

当我删除 __exit 似乎它至少识别 jif_exit - 所以现在我得到的警告是

warning: data definition has no type or storage class
warning: type defaults to ‘int’ in declaration of ‘modile_exit’
warning: parameter names (without types) in function declaration

通读下面为什么这个内核模块在 2.6.39 上被标记为永久

它谈到 gcc 不匹配是一个问题?有人可以帮助我无法进一步调试吗?任何指针如何正确加载模块使其不是永久性的?

4

1 回答 1

1

如果没有为内核模块定义退出函数,则内核模块被标记为permanent(无法卸载) 。

退出函数不接受任何参数并且不返回任何内容,并且应该使用预定义的名称进行定义

void cleanup_module(void)
{
    ...
}

或具有任意名称但已使用module_exit宏注册

void <func_name>(void)
{
    ...
}

module_exit(<func_name>);

退出函数的static__exit和其他属性是可选的。

于 2015-11-01T16:14:37.733 回答