大家帮帮 忙吧 关于使用 自定义的系统调用 时 的 编译错误

drenren 2007-01-15 10:36:51
基本情况是 我用模快 加了一个系统调用
模块 没有问题 insmod 后看上去也很 正常
不过 当我写用户层 程序 时 却无法编译成功
我换了网上了 例程 也不行 大家 帮我看看 把

module shows below
----------------------------
#include<linux/kernel.h>
#include<linux/module.h>
#include<linux/init.h>
#include<linux/unistd.h>

#include<linux/time.h>

#include<asm/uaccess.h> // for copy_to_user
#include<linux/sched.h> // for current macro
MODULE_LICENSE("GPL");

#define __NR_pedagogictime 283

static int (*saved)(void);

static int sys_pedagogictime(struct timeval *tv)
{
struct timeval ktv;
do_gettimeofday(&ktv);
copy_to_user(tv,&ktv,sizeof(ktv));
printk("<0>PID %ld called sys_gettimeofday().\n",(long)current->pid);
return 0;
}

int syscall(void)
{
long *systable;
printk("<0> i am start");
systable=(long*)0xc02b2600;
saved=(int(*)(void))(systable[__NR_pedagogictime]);
systable[__NR_pedagogictime]=(unsigned long)sys_pedagogictime;
return 0;
}

void exit_syscall(void)
{
unsigned long *systable;
systable=( long*)0xc02b2600;
systable[__NR_pedagogictime]=(unsigned long)saved;
}

module_init(syscall);
module_exit(exit_syscall);


app in userspace
---------------------------------
#include<linux/unistd.h>
#include<sys/time.h>
#include<stdio.h>

#define __NR_pedagogictime 283

_syscall1(int,pedagogictime,struct timeval *,thetime)

//struct timeval tv;

int main()
{
struct timeval tv;

pedagogictime(&tv);
printf("tv_sec:%ld\n",tv.tv_sec);
printf("tv_nsec:%ld\n",tv.tv_usec);

printf("em...,let me sleep for 2 second.:)\n");
sleep(2);
pedagogictime(&tv);
printf("tv_sec:%ld\n",tv.tv_sec);
printf("tv_nsec:%ld\n",tv.tv_usec);
}


compiler result
------------------------
usenew.c:7: error: ‘pedagogictime’ has not been declared
usenew.c:7: error: ‘thetime’ has not been declared
usenew.c:11: error: expected constructor, destructor, or type conversion before ‘int’

我把库里的 宏 手动展开 就出现了一些 更加 莫名的问题

我用的是 FC6 刚刚好像看到说 fc6 把 _syscallX 宏 取消了 要用syscall() 我完全 不知道怎么搞了 大家帮帮我吧
先谢过了
...全文
275 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
blueoceanli 2007-01-16
  • 打赏
  • 举报
回复
UP,关注

4,436

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧