[問題] 如何取得module內的變數位址

看板LinuxDev作者 (明月照大江)時間15年前 (2011/02/15 22:03), 編輯推噓0(007)
留言7則, 2人參與, 最新討論串1/1
有個問題想請教大家,我把問題簡化如下: 使用的kernel 版本: 2.6.29-rc3 hello module裡面有全域變數victor_global_var,載入kernel後 透過指令grep 即可知道victor_global_var的位址 # grep victor_global_var /proc/kallsyms 現在換kernel版本 2.6.32 發現/proc/kallsyms內不會顯示 victor_global_var的位址導致無法取得 victor_global_var的位址,透過指令 # grep hello /proc/kallsyms 發現kallsyms只會顯示函式的位址,但不會顯示資料結構、全域變數等等的資訊 請問有什麼方法可以使2.6.32的kallsyms顯示module的變數位址?還是有 其他更好的方式可以得知module內的全域變數位址?? 謝謝大家! ================================================================= hello.c -------------------------- #include <linux/module.h> #include <linux/init.h> #include "hello.h" MODULE_LICENSE("Dual BSD/GPL"); int victor_global_var=1; static int hello_init(void) { int victor_local_var=2; printk(KERN_ALERT "driver loaded\n"); victor_local_var=3; victor_global_var=5; printk("##victor_global_var=%d\n",victor_global_var); return 0; } static void hello_exit(void) { printk(KERN_ALERT "driver unloaded\n"); } module_init(hello_init); module_exit(hello_exit); ================================================================ hello.h -------- #ifndef _HELLO_H_ #define _HELLO_H_ extern int victor_global_var; #endif ================================================================ LINUX 2.6.29-rc3 時的執行結果 ----------------------------- root@SERVER:~# uname -r 2.6.29-rc3-omap1 root@SERVER:~# insmod /hello.ko driver loaded root@SERVER:~# driver loaded ##victor_global_var=5 root@SERVER:~# grep hello /proc/kallsyms c02fb5f0 t br_hello_timer_expired c02fc1e8 t show_hello_timer c02fc34c t store_hello_time c02fc4a8 t show_hello_time c02fc550 t set_hello_time 00000000 a hello.c [hello] bf000000 t $a [hello] bf000000 t hello_exit [hello] bf000018 t $d [hello] bf00001c t $a [hello] bf00001c t hello_init [hello] bf000058 t $d [hello] c68690c0 ? __mod_license4 [hello] c68690c0 ? $d [hello] bf00008c r $d [hello] bf000468 d $d [hello] 00000000 a hello.mod.c [hello] c68690d5 ? __mod_srcversion30 [hello] c68690d5 ? $d [hello] c68690f8 ? __module_depends [hello] c6869101 ? __mod_vermagic5 [hello] c6869180 ? $d [hello] c6869180 ? ____versions [hello] bf000480 d $d [hello] c6869c83 n $d [hello] bf000480 d __this_module [hello] bf000000 t cleanup_module [hello] bf00001c t init_module [hello] bf000468 d victor_global_var [hello] c033a3f8 u printk [hello] root@SERVER:~# ================================================================= LINUX 2.6.32時察看執行結果 -------------------------- root@SERVER:~# insmod /hello.ko driver loaded root@SERVER:~# driver loaded ##victor_global_var=5 root@SERVER:~# grep hello /proc/kallsyms c0327e18 t br_hello_timer_expired c032889c t show_hello_timer c0328998 t store_hello_time c0328ae0 t show_hello_time c0328b70 t set_hello_time bf7b6000 t $a [hello] bf7b6000 t hello_exit [hello] bf7b6008 t $d [hello] bf7b600c t $a [hello] bf7b600c t hello_init [hello] bf7b6038 t $d [hello] bf7b6000 t cleanup_module [hello] bf7b600c t init_module [hello] root@SERVER:~# -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.116.220.253 ※ 編輯: neurone 來自: 122.116.220.253 (02/15 22:06)

02/16 23:01, , 1F
如果你只是在其他module要看到該變數,用 EXPORT_SYMBOL 吧
02/16 23:01, 1F

02/17 11:35, , 2F
我想要在應用程式中得知位址,也不希望變數被其他module看
02/17 11:35, 2F

02/17 11:36, , 3F
到。到目前為止2.6.35.10 2.6.35.11皆是如此
02/17 11:36, 3F

02/17 18:32, , 4F
知道位置之後要幹啥?
02/17 18:32, 4F

02/21 12:27, , 5F
知道變數的位址後,應用程式可透過自訂的ioctl去取值
02/21 12:27, 5F

02/21 12:27, , 6F
不需要另外解析變數
02/21 12:27, 6F

02/21 17:15, , 7F
ioctl 不是這樣搞的吧?
02/21 17:15, 7F
文章代碼(AID): #1DMeV6S6 (LinuxDev)
文章代碼(AID): #1DMeV6S6 (LinuxDev)