|
|
发表于 2006-7-1 17:40:59
|
显示全部楼层
Post by smartdog
如题:
我在/kernel/ksyms.c中加入了EXPORT_SYMBOL(sys_call_table)这一项了,模块编译成功,但是在加载内核时,说unresolved symbol sys_call_table.不知道怎么办了,我的内核版本是2.4.21
源程序如下:
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <errno.h>
#include <linux/unistd.h>
#include <linux/time.h>//for struct time
#include <asm/uaccess.h>//for copy_to_user()
#include <linux/sched.h>
#include <asm/current.h>//for macro current
#define __NR_pedagogictime 272
MODULE_DESCRIPTION("My sys_pedagogictime()");
MODULE_AUTHOR("smartdog ,(c)2002,GPLv2 or later");
static int (*anything_saved)(void);//用来保存旧系统调用的地址
/*这个是我们自己的系统调用函数sys_pedagogictime().*/
static int sys_pedagogictime(struct timeval *tv)
{
struct timeval ktv;
MOD_INC_USE_COUNT;
do_gettimeofday(&ktv);
if(copy_to_user(tv,&ktv,sizeof(ktv))){
MOD_DEC_USE_COUNT;
return -EFAULT;
}
printk("<0>Here called sys_gettimeofday().\n");
MOD_DEC_USE_COUNT;
return 0;
}
/*这里是初始化函数,__init标志表明这个函数使用后就可以丢弃了*/
int __init init_addsyscall(void)
{
extern long sys_call_table[];
anything_saved=(int(*)(void))(sys_call_table[__NR_pedagogictime]);
sys_call_table[__NR_pedagogictime]=(unsigned long)sys_pedagogictime;
return 0;
}
/*__exit标志表明模块被编译进内核,只要内核还在运行,就不会被卸载*/
void __exit exit_addsyscall(void)
{
extern long sys_call_table[];
sys_call_table[__NR_pedagogictime]=(unsigned long)anything_saved;
}
/*这两个宏告诉系统我们真正的初始化和退出函数*/
module_init(init_addsyscall);
module_exit(exit_addsyscall);
这种方法根本没有通用行!
看看《Linux1.0核心游记》中动态添加系统调用 |
|