我在一年前编写了一些 freebsd 内核模块,当时它们工作得很好。但现在我无法编译。
我想做的是通过修改 sysent 表来 Hook 现有的系统调用。
static int
mkdir_hook (struct proc *p, struct mkdir_args *ua)
{
printf("Making dir: %s\n", ua->path);
return mkdir(p, ua);
}
static int
load (struct module *module, int cmd, void *arg)
{
int error = 0;
switch (cmd) {
case MOD_LOAD :
sysent[SYS_mkdir]=mkdir_hook_sysent;
break;
case MOD_UNLOAD :
sysent[SYS_mkdir].sy_call=(sy_call_t*)mkdir;
break;
default :
error = EINVAL;
break;
}
return error;
}
我收到以下错误
test.c:21: warning: implicit declaration of function 'mkdir'
test.c:21: warning: nested extern declaration of 'mkdir' [-Wnested-externs]
test.c:49: error: 'mkdir' undeclared (first use in this function)
test.c:49: error: (Each undeclared identifier is reported only once
test.c:49: error: for each function it appears in.)
所以我认为它可能缺少库。这是我的包含内容
#include <sys/types.h>
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/module.h>
#include <sys/sysent.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/linker.h>
#include <sys/sysproto.h>
#include <sys/sysent.h>
#include <sys/proc.h>
#include <sys/syscall.h>
我读了man 2 mkdir
,仍然没有线索。似乎不再支持从内核模块内调用另一个系统调用或者需要额外的配置?
请帮忙,非常感谢。
最佳答案
系统调用条目现在以“sys_”为前缀,因此您现在应该使用 sys_mkdir 而不是仅使用 mkdir。
确切的变更集是:
r225617 | kmacy | 2011-09-16 06:58:51 -0700 (Fri, 16 Sep 2011) | 12 lines
In order to maximize the re-usability of kernel code in user space this patch modifies makesyscalls.sh to prefix all of the non-compatibility calls (e.g. not linux_, freebsd32_) with sys_ and updates the kernel entry points and all places in the code that use them. It also fixes an additional name space collision between the kernel function psignal and the libc function of the same name by renaming the kernel psignal kern_psignal(). By introducing this change now we will ease future MFCs that change syscalls.
关于kernel - FreeBSD 从另一个系统调用发出一个系统调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15017403/