LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 898|回复: 0

替换系统调用open 编译通不过

[复制链接]
发表于 2004-8-11 20:10:59 | 显示全部楼层 |阅读模式
替换系统调用open 编译通不过
这几天一直在看 《Linux Program White Paper》
其中有一章是关于替换系统调用open 函数的
不知道是不是 程序太老的原因 总是不能编译通过
按照提示,好多函数没有声明,我想可能是我安装的linux Red Hat 9 版本太新没有包含该包含的文件所致 或者包含文件有变化的缘故
还请各位大虾帮我看看 谢谢!

下面是源文件和出错提示:
/* The necessary header files */
#include <linux/kernel.h>
#include <linux/module.h>

/* Deal with CONFIG_MODVERSIONS
#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include <linux/modversions.h>
#endif
*/
#include <sys/syscall.h> /* The list of system call */
#include <linux/linkage.h>
#include <linux/config.h>
#include <linux/sched.h> /* for the current structure,we need this to know who the current user is. */

#ifndef KERNEL_VERSION
#define KERNEL_VERSION(a,b,c) ((a)*65536+(b)*256+(c))
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
#include <asm/uaccess.h>
#endif

/* the system call table (a table of function). we
* just define this as external,and the kernel will
* fill it up for us when we are insmod'ed
*/
extern void *sys_call_tabel[];

int uid;

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
MODULE_PARM(uid,"i");
#endif

asmlinkage int (*original_call)(const char *,int,int);
asmlinkage int (*getuid_call)();

/* the function will replace sys_open.To find the exact prototype,
* with the number and type of arguments. we find the original
* function first.
*/
asmlinkage int our_sys_open(const char *filename,int flags,int mode)
{
int i=0;
char ch;
if (uid==getuid_call()){
printk("Open file by %d: ",uid);
do{
get_user(ch,filename+i);
i++;
printk("%c",ch);
}while (ch!=0);
printk("\n");
}
}

/* Initialize the module - replace the system call */
int init_module()
{
printk("repare to replace the system call....");

original_call = sys_call_table[__NR_open];
sys_call_table[__NR_open] = our_sys_open;

printk(" Spying on UID:%d\n",uid);

getuid_call = sys_call_table[__NR_getuid];

return 0;
}

/* Clearup - unregister teh appropriate file from /proc */
void cleanup_module()
{
if (sys_call_table[__NR_open]!=our_sys_open){
printk("The system may be left in an unstable state.\n");
}

sys_call_table[__NR_open] = original_call;
}

这基本和书上的程序一样 有些条件编译的语句去掉了

下面是Makefile 文件
CC=gcc
MODCFLAGS := -Wall -DMODULE -D__KERNEL__ -DLINUX

syscall.o:syscall.c /usr/include/linux/version.h
$(CC) $(MODCFLAGS) -c syscall.c

这是我写的 很简单,不知道有没有错误

当我运行 make 时 出来一堆的错
不知道什么原因
[#alpha@wildwolf]:make
gcc -Wall -DMODULE -D__KERNEL__ -DLINUX -c syscall.c
In file included from /usr/include/linux/fs.h:23,
from /usr/include/linux/capability.h:17,
from /usr/include/linux/binfmts.h:5,
from /usr/include/linux/sched.h:9,
from syscall.c:14:
/usr/include/linux/string.h:8:2: warning: #warning Using kernel header in userland!
In file included from /usr/include/linux/sched.h:14,
from syscall.c:14:
/usr/include/linux/timex.h:173: field `time' has incomplete type
In file included from /usr/include/linux/bitops.h:69,
from /usr/include/asm/system.h:7,
from /usr/include/linux/sched.h:16,
from syscall.c:14:
/usr/include/asm/bitops.h:327:2: warning: #warning This includefile is not available on all architectures.
/usr/include/asm/bitops.h:328:2: warning: #warning Using kernel headers in userspace: atomicity not guaranteed
In file included from /usr/include/linux/signal.h:4,
from /usr/include/linux/sched.h:25,
from syscall.c:14:
/usr/include/asm/signal.h:107: parse error before "sigset_t"
/usr/include/asm/signal.h:110: parse error before '}' token
In file included from /usr/include/linux/sched.h:81,
from syscall.c:14:
/usr/include/linux/timer.h:45: parse error before "spinlock_t"
/usr/include/linux/timer.h:53: parse error before '}' token
/usr/include/linux/timer.h:67: parse error before "tvec_base_t"
/usr/include/linux/timer.h:101: parse error before "tvec_bases"
/usr/include/linux/timer.h: In function `init_timer':
/usr/include/linux/timer.h:105: dereferencing pointer to incomplete type
/usr/include/linux/timer.h:105: dereferencing pointer to incomplete type
/usr/include/linux/timer.h:106: dereferencing pointer to incomplete type
/usr/include/linux/timer.h: In function `timer_pending':
/usr/include/linux/timer.h:121: dereferencing pointer to incomplete type
syscall.c:20:25: asm/uaccess.h: 没有那个文件或目录
syscall.c: In function `our_sys_open':
syscall.c:47: warning: implicit declaration of function `printk'
syscall.c:49: warning: implicit declaration of function `get_user'
syscall.c: In function `init_module':
syscall.c:62: `sys_call_table' undeclared (first use in this function)
syscall.c:62: (Each undeclared identifier is reported only once
syscall.c:62: for each function it appears in.)
syscall.c: In function `cleanup_module':
syscall.c:75: `sys_call_table' undeclared (first use in this function)
make: *** [syscall.o] Error 1
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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