Turn from http://blog.csdn.net/lisan04/article/details/4076013
The'/ prob/kallsyms'file of Linux 2.6 corresponds to the symbol table of the kernel, recording the symbol and the memory address where the symbol is located.
Kernel Symbol Table: Records the address and name of all symbols (functions, global variables, etc.) in the kernel. This symbol table is embedded in the kernel image, so that the kernel can get a symbol name corresponding to the symbol address at any time during operation.
Modules can export symbols to the kernel symbol table using the following macros:
- EXPORT_SYMBOL(Symbol name);
- EXPORT_SYMBOL_GPL(Symbol name)
EXPORT_SYMBOL(Symbol name); EXPORT_SYMBOL_GPL(Symbol name)Exported symbols can be used by other modules, howeverBe sure to make a statement before using it.. EXPORT_SYMBOL_GPL()Applicable only to inclusion GPL The module of permission.
Code demo:
- //hello.c file, define two functions for export
- #include <<a href="http://lib.csdn.net/base/linux "class='replace_word'title="Linux knowledge base "target='_blank' style='color:#df3434; font-weight: bold;'>Linux</a>/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);
- //test.c. Functions derived from the hello module are invoked
- #include <linux/init.h>
- #include <linux/module.h>
- MODULE_LICENSE("Dual BSD/GPL");
- extern int add_integar(int ,int); //Declare the function to be called
- extern int sub_integar(int ,int); //Declare the function to be called
- 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;
- }
//hello.c file, define two functions for export #include <<a href="http://Lib.csdn.net/base/linux "class='replace_word'title=" Linux knowledge base "target='_blank' style='color:#df3434; font-weight: bold;'>Linux</a>/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); //test.c is used to call the functions derived from the hello module #include <linux/init.h> #include <linux/module.h> MODULE_LICENSE("Dual BSD/GPL"); extern int add_integar(int ,int); //Declare the function to be called extern int sub_integar(int ,int); //Declare the function to be called 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 After that, add in hello Module, reload test Modular.
Then? cat /proc/kallsyms | grep integer
Show:
- [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]
Items in the list:
It should be easy to see that the first column is the symbol address, the second column is the type, the third column is the symbol name, and the fourth column is the file.
Note: If all symbolic addresses are found to be 0, that is because of system protection. Use root permission to view.
The type of the second column:
Some symbols are capitalized and some are lowercase. The capitalized symbols are global.
- b symbol in uninitialized data area (BSS)
- c Ordinary symbol, is an uninitialized region
- d symbol in initialization data area
- g symbols for small object s, in the initialization data area
- i Symbols that do not directly refer to other symbols
- n Debugging Symbol
- r symbol in read-only data area
- The s symbol is for small object s in the uninitialized data area
- t symbol in code segment
- u symbol undefined