linux 导出符号列表例子
--在网友基础上修改而来
模块1代码:
#include
#include
MODULE_LICENSE("Dual BSD/GPL");
int test_global_value_1 = 0x55;
int test_global_value_2 = 0xaa;
EXPORT_SYMBOL(test_global_value_1);
EXPORT_SYMBOL(test_global_value_2);
static int __init symbol_init(void)
{
printk("<0> symbol_init\n");
return 0;
}
int add_integar(int a, int b)
{
return (a + b);
}
int sub_integar(int a, int b)
{
return (a - b);
}
static void __exit symbol_exit(void)
{
printk("<0> symbol_exit\n");
}
EXPORT_SYMBOL(add_integar);
EXPORT_SYMBOL(sub_integar);
module_init(symbol_init);
module_exit(symbol_exit);
模块2代码:
#include
#include
extern int add_integar(int, int);
extern int sub_integar(int, int);
extern int test_global_value_1;
extern int test_global_value_2;
MODULE_LICENSE("GPL");
static int __init use_symbol_init(void)
{
printk("test_global_value_1 = %x\n", test_global_value_1);
printk("test_global_value_2 = %x\n", test_global_value_2);
printk("<0> use_symbol_init");
printk("<0> 1+2 = %d\n",add_integar(1,2));
printk("<0> 3-2 = %d\n",sub_integar(3,2));
return 0;
}
static void __exit use_symbol_exit(void)
{
printk("<0> Module exit!\n");
}
module_init(use_symbol_init);
module_exit(use_symbol_exit);