大家帮帮 忙吧 关于使用 自定义的系统调用 时 的 编译错误
基本情况是 我用模快 加了一个系统调用
模块 没有问题 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() 我完全 不知道怎么搞了 大家帮帮我吧
先谢过了