module_init()函数内代码不能执行
时间:2010-07-25
来源:互联网
我虚拟机装的是redhat9
hello.c代码如下:
复制代码
Makefile代码如下:
复制代码
执行make后,在该目录下生成hello.o文件,然后我insmod hello.o文件,期望结果是打印出"test init ok",但是结果如下:
[root@localhost hello]# insmod hello.o
Warning: loading hello.o will taint the kernel: no license
See http://www.tux.org/lkml/#export-tainted for information about tainted modules
Module hello loaded, with warnings
出现警告,要加载的hello.o模块会影响内核,没有授权。没有出现期望的"test init ok"字样,也就是说test_init()函数里的代码根本没有执行。但是我用lsmod测试时,内核中已加载模块却有hello这个模块,测试结果如下:
ot@localhost hello]# lsmod
复制代码
而且,当我rmmod hello时,期望出现的“test exit ok”字样也没有出现,即test_exit()函数里的代码根本没有执行。
请教各位高手不吝赐教,谢谢!
hello.c代码如下:
- #ifndef _KERNEL_
- #define _KERNEL_
- #endif
- #ifndef MODULE
- #define MODULE
- #endif
-
- #include<linux/module.h>
- //#include<linux/sched.h>
- #include<linux/kernel.h>
- #include<linux/init.h>
- #include<linux/errno.h>
- int test_init();
- void test_exit();
- module_init(test_init);
- module_exit(test_exit);
- int test_init()
- {
- printk("test init ok\n");
- return 0;
- }
-
- void test_exit()
- {
- printk("test release ok\n");
-
- }
- CC=gcc
- INCLUDE=/usr/src/linux-2.4.20-8/
- OBJS=hello.o
- SRC=hello.c
- FLAGS=-D_KERNEL_ -DMODULE -I $(INCLUDE)
-
- hello.o:hello.c
- $(CC) $(FLAGS) -c $< -o $@
- clean:
- rm -f $(EXEC) *.o
[root@localhost hello]# insmod hello.o
Warning: loading hello.o will taint the kernel: no license
See http://www.tux.org/lkml/#export-tainted for information about tainted modules
Module hello loaded, with warnings
出现警告,要加载的hello.o模块会影响内核,没有授权。没有出现期望的"test init ok"字样,也就是说test_init()函数里的代码根本没有执行。但是我用lsmod测试时,内核中已加载模块却有hello这个模块,测试结果如下:
ot@localhost hello]# lsmod
- Module Size Used by Tainted: P
- hello 824 0 (unused)//这就是新增加的hello模块
- ide-cd 35196 0 (autoclean)
- cdrom 33472 0 (autoclean) [ide-cd]
- parport_pc 18756 1 (autoclean)
- lp 8868 0 (autoclean)
- parport 36480 1 (autoclean) [parport_pc lp]
- autofs 12948 0 (autoclean) (unused)
- pcnet32 18016 1
- mii 3944 0 [pcnet32]
- ipt_REJECT 3896 6 (autoclean)
- iptable_filter 2380 1 (autoclean)
- ip_tables 14648 2 [ipt_REJECT iptable_filter]
- keybdev 2880 0 (unused)
- mousedev 5428 1
- hid 21700 0 (unused)
- input 5792 0 [keybdev mousedev hid]
- usb-uhci 25868 0 (unused)
- usbcore 77696 1 [hid usb-uhci]
- ext3 69984 2
- jbd 51220 2 [ext3]
- BusLogic 99932 3
- sd_mod 13324 6
- scsi_mod 106168 2 [BusLogic sd_mod]
请教各位高手不吝赐教,谢谢!
作者: 0vk0 发布时间: 2010-07-25
本帖最后由 wmmy2008 于 2010-07-25 10:56 编辑
Linux module should be compiled to *.ko
Linux module should be compiled to *.ko
作者: wmmy2008 发布时间: 2010-07-25
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28