增加系统调用新问题(急!!!)
时间:2003-05-31
来源:互联网
本人想用内核模块的方法增加一个系统调用,具体代码示例如下:
/* pedagogictime.c */
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/unistd.h>
#include <linux/time.h>
#include <asm/uaccess.h>
#include <linux/sched.h>
#define __NR_pedagogictime 260
MODULE_DESCRIPTION("My sys_pedagogictime()");
MODULE_AUTHOR("Your name , (c) 2002,GPLv2 or later");
static int(*anything_saved)(void);
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(KERN_ALERT"Pid %ld called sys_gettimeofday(). \n",(long)current->pid);
MOD_DEC_USE_COUNT;
return 0;
}
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;
}
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);
然后本人想把它编译成.o文件,命令如下
gcc -Wall -o2 -DMODULE -D__KERNEL__ -DLINUX -c pedagogictime.c
-o pedagogictime.o -I/usr/src/linux-2.4/include
编译完成无任何提示,好像编译成功了???
使用insmod pedagogictime.o把它动态地加载到正在运行的内核中.但是提示错误,错误代码如下:
pedagogictime.o: unresolved symbol prefetch
pedagogictime.o: unresolved symbol sys_call_table
pedagogictime.o:
Hint: You are trying to load a module without a GPL compatible license
and it has unresolved symbols. Contact the module supplier for
assistance, only they can help you.
希望各位高手赐教问题出在哪儿??如何解决??
谢先!!!
附:平台为Red Hat 9.0
测试程序test.c如下所示:
#include <linux/time.h>
#include <linux/unistd.h>
#define __NR_pedagogictme 260
_syscall(int,pedagogictime,struct timeval *,thetime)
int main()
{
struct timeval tv;
pedagogictime(&tv);
printf("tv_sec : %ld\n",tv.tv_sec);
printf("tv_usec : %ld\n",tv.tv_usec);
printf("let me sleep for 2 seconds. \n");
sleep(2);
pedagogictime(&tv);
printf("tv_sec : %ld\n",tv.tv_sec);
printf("tv_usec : %ld\n",tv.tv_usec);
}
/* pedagogictime.c */
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/unistd.h>
#include <linux/time.h>
#include <asm/uaccess.h>
#include <linux/sched.h>
#define __NR_pedagogictime 260
MODULE_DESCRIPTION("My sys_pedagogictime()");
MODULE_AUTHOR("Your name , (c) 2002,GPLv2 or later");
static int(*anything_saved)(void);
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(KERN_ALERT"Pid %ld called sys_gettimeofday(). \n",(long)current->pid);
MOD_DEC_USE_COUNT;
return 0;
}
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;
}
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);
然后本人想把它编译成.o文件,命令如下
gcc -Wall -o2 -DMODULE -D__KERNEL__ -DLINUX -c pedagogictime.c
-o pedagogictime.o -I/usr/src/linux-2.4/include
编译完成无任何提示,好像编译成功了???
使用insmod pedagogictime.o把它动态地加载到正在运行的内核中.但是提示错误,错误代码如下:
pedagogictime.o: unresolved symbol prefetch
pedagogictime.o: unresolved symbol sys_call_table
pedagogictime.o:
Hint: You are trying to load a module without a GPL compatible license
and it has unresolved symbols. Contact the module supplier for
assistance, only they can help you.
希望各位高手赐教问题出在哪儿??如何解决??
谢先!!!
附:平台为Red Hat 9.0
测试程序test.c如下所示:
#include <linux/time.h>
#include <linux/unistd.h>
#define __NR_pedagogictme 260
_syscall(int,pedagogictime,struct timeval *,thetime)
int main()
{
struct timeval tv;
pedagogictime(&tv);
printf("tv_sec : %ld\n",tv.tv_sec);
printf("tv_usec : %ld\n",tv.tv_usec);
printf("let me sleep for 2 seconds. \n");
sleep(2);
pedagogictime(&tv);
printf("tv_sec : %ld\n",tv.tv_sec);
printf("tv_usec : %ld\n",tv.tv_usec);
}
作者: upcboy 发布时间: 2003-05-31
如果使用命令:gcc -Wall -O2 -DMODULE -D__KERNEL__ -DLINUX -c pedagogictime.c -O pedagogictime.o -I/usr/src/linux-2.4/include
则错误信息如下所示:gcc: pedagogictime.o: linker input file unused because linking not done
则错误信息如下所示:gcc: pedagogictime.o: linker input file unused because linking not done
作者: upcboy 发布时间: 2003-05-31
我也试过,跟你一样的结果
应该用-O2 ...-o 文件名.o ....(我认为)
应该用-O2 ...-o 文件名.o ....(我认为)
作者: Lazybones 发布时间: 2003-05-31
linuxfans has this
http://www.linuxfans.org/nuke/module...wtopic&t=25601
http://www.linuxfans.org/nuke/module...wtopic&t=25601
作者: cheungming 发布时间: 2003-05-31
好像行不通,我基本上就是那样做的
作者: Lazybones 发布时间: 2003-05-31
好像行不通,我基本上就是那样做的,在9.0下
作者: Lazybones 发布时间: 2003-05-31
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28