- 论坛徽章:
- 0
|
看来只有我一直坚守阵地研究 2.4 内核,我落伍了。。。
是这样的,2.4 的 LKM 明确指出
如果你在使用2.4或更新的内核,当你加载你的模块时,你也许注意到了这些输出信息:
# insmod hello-3.o
Warning: loading hello-3.o will taint the kernel: no license
See http://www.tux.org/lkml/#export-tainted for information about tainted modules
Hello, world 3
Module hello-3 loaded, with warnings
在2.4或更新的内核中,一种识别代码是否在GPL许可下发布的机制被引入,因此人们可以在使用非公开的源代码产品时得到警告。这通过在下一章展示的宏MODULE_LICENSE()当你设置在GPL证书下发布你的代码时,你可以取消这些警告。这种证书机制在头文件linux/module.h实现,同时还有一些相关文档信息。
类似的,宏 MODULE_DESCRIPTION() 用来描述模块的用途。宏MODULE_AUTHOR() 用来声明模块的作者。宏MODULE_SUPPORTED_DEVICE()声明模块支持的设备。
这些宏都在头文件linux/module.h 定义,并且内核本身并不使用这些宏。它们只是用来提供识别信息,可用工具程序像objdump查看。作为一个练习,使用grep从目录 linux/drivers 看一看这些模块的作者是如何为他们的模块提供识别信息和档案的。
我看的是电子版的 LKM,在 part4 有正确的代码
- /* hello-4.c - Demonstrates module documentation.
- */
- #include <linux/module.h>
- #include <linux/kernel.h>
- #include <linux/init.h>
- #define DRIVER_AUTHOR "Peiter Jay Salzman <p@dirac.org>"
- #define DRIVER_DESC "A sample driver"
- int init_hello_3(void);
- void cleanup_hello_3(void);
- static int init_hello_4(void)
- {
- printk(KERN_ALERT "Hello, world 4\n");
- return 0;
- }
- static void cleanup_hello_4(void)
- {
- printk(KERN_ALERT "Goodbye, world 4\n");
- }
- module_init(init_hello_4);
- module_exit(cleanup_hello_4);
- /* You can use strings, like this:
- */
- MODULE_LICENSE("GPL"); // Get rid of taint message by declaring code as GPL.
- /* Or with defines, like this:
- */
- MODULE_AUTHOR(DRIVER_AUTHOR); // Who wrote this module?
- MODULE_DESCRIPTION(DRIVER_DESC); // What does this module do?
- /* This module uses /dev/testdevice. The MODULE_SUPPORTED_DEVICE macro might be used in
- * the future to help automatic configuration of modules, but is currently unused other
- * than for documentation purposes.
- */
- MODULE_SUPPORTED_DEVICE("testdevice");
复制代码
[ 本帖最后由 platinum 于 2006-2-9 16:21 编辑 ] |
|