加载简单内核模块时可疑的返回码

时间:2014-04-13 10:00:32

标签: c linux ubuntu linux-kernel ubuntu-12.04

我写了一个简单的hello world内核模块,如下所示:

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

static void hello_init(void){
    printk(KERN_ALERT "TEST: Hello world kernel \n");
    return 0;
}

static void hello_exit(void){
    printk(KERN_ALERT "TEST: Goodbye world!!1\n");
    return 0;
}
module_init(hello_init);
module_exit(hello_exit);

这是我的Makefile

obj-m += hello.o

KDIR = /usr/src/linux-headers-3.11.0-19-generic

all:
    $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
    rm -rf *.o *.ko *.mod.* *.symvers *.order

我使用insmod hello.ko加载模块,dmesg的输出是:

    [ 4203.339976] TEST: Hello world kernel 
[ 4203.339985] do_init_module: 'hello'->init suspiciously returned 25, it should follow 0/-E convention
[ 4203.339985] do_init_module: loading module anyway...
[ 4203.339991] CPU: 0 PID: 7037 Comm: insmod Tainted: PF          O 3.11.0-19-generic #33~precise1-Ubuntu
[ 4203.339993] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
[ 4203.339995]  00000000 00000000 f457dee0 c1673634 f8633000 f457df04 c166a007 c1901418
[ 4203.340001]  c169475c f863300c 00000019 c169475c f457df60 f8633000 f457df3c c10bb1d8
[ 4203.340006]  00000000 ffff8000 00007fff c10b8ce0 00000a02 f457df60 08b9c008 f457df68
[ 4203.340011] Call Trace:
[ 4203.340022]  [<c1673634>] dump_stack+0x41/0x52
[ 4203.340026]  [<c166a007>] do_init_module+0xfc/0x1c6
[ 4203.340033]  [<c10bb1d8>] load_module+0x358/0x520
[ 4203.340036]  [<c10b8ce0>] ? show_initstate+0x50/0x50
[ 4203.340036]  [<c10bb44b>] SyS_init_module+0xab/0xf0
[ 4203.340036]  [<c168540d>] sysenter_do_call+0x12/0x28

这有什么问题&#34;可疑......&#34;消息(在初始化中返回0!)以及为什么打印出呼叫追踪? 不应该打印你好的警报吗? 仅供参考:我在ubuntu 12.04的全新vbox安装中使用3.11.0-19-generic

1 个答案:

答案 0 :(得分:3)

请尝试使用此类型定义:

static int __init hello_init(void)

static void __exit hello_exit(void)