生活随笔
收集整理的這篇文章主要介紹了
EXPORT_SYMBOL
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
linux2.6的“/prob/kallsyms”文件對(duì)應(yīng)著內(nèi)核符號(hào)表,記錄了符號(hào)以及符號(hào)所在的內(nèi)存地址。
模塊可以使用如下宏導(dǎo)出符號(hào)到內(nèi)核符號(hào)表:
[c-sharp]?view plaincopy
EXPORT_SYMBOL(符號(hào)名);?? EXPORT_SYMBOL_GPL(符號(hào)名)??
導(dǎo)出的符號(hào)可以被其他模塊使用,不過使用之前一定要聲明一下。EXPORT_SYMBOL_GPL()只適用于包含GPL許可權(quán)的模塊。
?
代碼演示:
[c-sharp]?view plaincopy
?? #include?<linux/init.h>?? #include?<linux/module.h>?? MODULE_LICENSE("Dual?BSD/GPL");?? int?add_integar(int?a,int?b)?? {?? ????return?a?+?b;?? }?? int?sub_integar(int?a,int?b)?? {?? ????return?a?-?b;?? }?? EXPORT_SYMBOL(add_integar);?? EXPORT_SYMBOL(sub_integar);?? ?? #include?<linux/init.h>?? #include?<linux/module.h>?? MODULE_LICENSE("Dual?BSD/GPL");?? extern?int?add_integar(int?,int);??? extern?int?sub_integar(int?,int);??? int?result(void)?? {?? ????int?a,b;?? ????a?=?add_integar(1,1);?? ????b?=?sub_integar(1,1);?? ?????? ????printk("%d/n",a);?? ????printk("%d/n",b);?? ?????? ????return?0;?? }??
?
make后,先加在hello模塊,再加載test模塊。
然后cat /proc/kallsyms | grep integer
顯示:
[c-sharp]?view plaincopy
[root@localhost?test]#?cat?/proc/kallsyms?|grep?integar?? e053d000?u?add_integar??[test]?? e053d004?u?sub_integar??[test]?? e053d02c?r?__ksymtab_sub_integar????????[hello]?? e053d03c?r?__kstrtab_sub_integar????????[hello]?? e053d034?r?__ksymtab_add_integar????????[hello]?? e053d048?r?__kstrtab_add_integar????????[hello]?? e053d000?T?add_integar??[hello]?? e053d004?T?sub_integar??[hello]??
總結(jié)
以上是生活随笔為你收集整理的EXPORT_SYMBOL的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。