Linux kernel Linux内核编程

Linux kernel Linux内核编程,linux-kernel,Linux Kernel,我想捕获pipe()系统调用,所以我更改了pipe.c中的源代码 static pipe_hook_t pipe_hook; pipe_hook_t set_pipe_hook(pipe_hook_t hook) { pipe_hook_t old_hook = pipe_hook; pipe_hook = hook; printk(KERN_INFO, "pipe hook: %p", hook); return old_hook; } EXPORT_SYMB

我想捕获pipe()系统调用,所以我更改了pipe.c中的源代码

static pipe_hook_t pipe_hook;
pipe_hook_t set_pipe_hook(pipe_hook_t hook)
{
    pipe_hook_t old_hook = pipe_hook;
    pipe_hook = hook;
    printk(KERN_INFO, "pipe hook: %p", hook);
    return old_hook;
}

EXPORT_SYMBOL_GPL(set_pipe_hook); 
typedef void (*pipe_hook_t)(int *filedes);
pipe_hook_t set_pipe_hook(pipe_hook_t hook);
然后我尝试在syscalls.h文件(包含在pipe.c中)中定义pipe\u hook\t

我有一个错误:

fs/pipe.c:1130: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘pipe_hook’
fs/pipe.c:1131: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘set_pipe_hook’
fs/pipe.c:1138: error: ‘set_pipe_hook’ undeclared here (not in a function)
fs/pipe.c:1138: warning: type defaults to ‘int’ in declaration of ‘set_pipe_hook’
fs/pipe.c: In function ‘sys_pipe2’:
fs/pipe.c:1153: error: ‘pipe_hook’ undeclared (first use in this function)
fs/pipe.c:1153: error: (Each undeclared identifier is reported only once
fs/pipe.c:1153: error: for each function it appears in.)
fs/pipe.c:1154: error: implicit declaration of function ‘pipe_hook’

我试图创建自己的.h文件并在那里定义管道钩子,但错误是相同的

问题已经解决。我刚刚把头文件所在的目录弄糊涂了

如果在
set\u pipe\u hook()
实现之前声明typedef,是否仍会出现错误?看起来您缺少了
typedef
可能是由于条件编译?