Código de retorno suspeito ao carregar o módulo simples do kernel
-
21-12-2019 - |
Pergunta
Eu escrevi um módulo de kernel simples, hello world, que se parece com isto:
#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);
e este é o meu 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
Carreguei o módulo usando insmod hello.ko e a saída do 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
O que há de errado com aquela mensagem "suspeita..." (há um retorno 0 no init!) e por que é impresso um rastreamento de chamada?apenas o alerta de olá não deveria ser impresso?PARA SUA INFORMAÇÃO:estou usando 3.11.0-19-generic de uma nova instalação vbox do ubuntu 12.04
Solução
Tente usar esta definição de tipo:
static int __init hello_init(void)
static void __exit hello_exit(void)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow