QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1382|回复: 13

Dragonfly帮帮忙!!!!(系统调用新问题)

[复制链接]
发表于 2003-5-31 15:57:23 | 显示全部楼层 |阅读模式
本人想用内核模块的方法增加一个系统调用,具体代码示例如下:
/* 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 icon_smile.gif, (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.

如果使用命令: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 link
ing not done

希望各位高手赐教问题出在哪儿??如何解决??

谢先!!!

附:平台为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);
}
 楼主| 发表于 2003-5-31 15:59:54 | 显示全部楼层
现在我把extern long sys_call_table[]改成extern void *sys_call_table[]后,编译成.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 sys_call_table

不知道问题出在哪儿???
回复

使用道具 举报

发表于 2003-5-31 17:48:42 | 显示全部楼层
#define __NR_pedagogictime 260

sys_call_table总共就252个元素,居然你搞了个260出来,sys_call_table不出错才是怪事。
回复

使用道具 举报

 楼主| 发表于 2003-5-31 18:31:41 | 显示全部楼层
可是我把#define __NR_pedagogictime 260 改成
#define __NR_pedagogictime 222还是一样得提示错误,不知道问题出在哪儿??
回复

使用道具 举报

发表于 2003-6-1 05:57:57 | 显示全部楼层
can u read my post
http://www.linuxfans.org/nuke/modules.php?name=Forums&file=viewtopic&t=25601
carefully?

a minor miss causes  u problem.
回复

使用道具 举报

发表于 2003-6-1 08:30:49 | 显示全部楼层
但是我用你那个程序测试的时候一样会出现错误,提示为:
call.o: unresolved symbol sys_call_table
回复

使用道具 举报

发表于 2003-6-1 08:34:07 | 显示全部楼层
编译你那个程序所用命令为gcc -Wall -O2 -DMODULE -D__KERNEL__ -DLINUX -c call.c -o call.o -I/usr/src/linux-2.4/include
不知道问题出在命令上还是哪儿??
回复

使用道具 举报

发表于 2003-6-1 08:37:01 | 显示全部楼层
补充一下,编译时没有报错,insmod call.o时报的那个错误
回复

使用道具 举报

发表于 2003-6-1 08:48:49 | 显示全部楼层
u use rh kernel? if so, try to use vanilla kernel.
rh kernel doesnot export that symbol.
o u can try to add
#ifndef __mips__
EXPORT_SYMBOL(sys_call_table);
#endif
to kernel/ksyms.c and recompile the kernel.
回复

使用道具 举报

发表于 2003-6-1 09:10:44 | 显示全部楼层
Thanks a lot~I will try it as soon as possible
回复

使用道具 举报

发表于 2003-6-1 09:11:43 | 显示全部楼层
i use the rh kernek 2.4.20-8
回复

使用道具 举报

发表于 2003-6-1 09:19:37 | 显示全部楼层
yes, 2.4.20-8 does not export that symbol.
回复

使用道具 举报

 楼主| 发表于 2003-6-1 11:12:16 | 显示全部楼层
i agree with you ~~
i love freedom
回复

使用道具 举报

发表于 2003-6-1 11:26:58 | 显示全部楼层
so try it together.

    
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-6-29 13:46 , Processed in 0.073445 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表