kernel - FreeBSD 从另一个系统调用发出一个系统调用

标签 kernel hook freebsd

我在一年前编写了一些 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/

相关文章:

git - git 上有用于重置后的钩子(Hook)吗?

node.js - 在 FreeBSD 10.1 上 npm 安装 Canvas

linux - 需要重新插入才能建立 USB 设备链接

macos - 如何在终端加载 I/O 套件驱动程序扩展?

linux - 在 Linux 中为进程分配物理内存

go - 如何进行dll注入(inject)

mercurial - 如何根据脚本拒绝推送到 Mercurial 服务器,而不会在此期间冒坏拉取的风险?

c - freebsd9下在C中查找硬盘名

c - cat.c 中 #if 0 的用途

linux - Linux 内核中的硬件中断上半部分堆栈?