【问题标题】:FreeBSD issue a system call from another system callFreeBSD 从另一个系统调用发出系统调用
【发布时间】:2013-02-22 14:32:05
【问题描述】:

我像 1 年前写了一些 freebsd 内核模块,当时它们运行良好。但现在我无法编译。

我要做的是通过修改 sysent 表来挂钩现有的系统调用。

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,仍然没有任何线索。似乎不再支持从内核模块中调用另一个系统调用或需要额外配置?

请帮忙,非常感谢。

【问题讨论】:

    标签: kernel hook freebsd


    【解决方案1】:

    系统调用条目现在以“sys_”为前缀,因此您现在应该使用 sys_mkdir 而不是只使用 mkdir。

    确切的变更集是:

    r225617 |公里| 2011-09-16 06:58:51 -0700(2011 年 9 月 16 日星期五)| 12行

    为了最大限度地提高内核代码在用户空间的可重用性 patch 修改 makesyscalls.sh 为所有不兼容添加前缀 使用 sys_ 调用(例如不是 linux_、freebsd32_)并更新内核 入口点和代码中使用它们的所有位置。它也是 修复了内核函数之间的额外名称空间冲突 psignal和libc函数通过重命名内核实现同名 psignal kern_psignal()。通过现在引入这一变化,我们将缓解未来 更改系统调用的 MFC。

    【讨论】:

    • 在 /usr/src/sys/sys/sysent.h, '"sys/" #name,' tyvm 中找到它
    猜你喜欢
    • 1970-01-01
    • 2011-12-15
    • 2016-06-02
    • 2014-12-25
    • 1970-01-01
    • 2017-06-30
    • 2017-06-22
    • 2016-05-31
    • 2016-02-09
    相关资源
    最近更新 更多