【发布时间】:2015-01-18 14:29:28
【问题描述】:
我是内核和 KLD 编程的新手。我正在寻找在 FreeBSD 中为系统调用模块修改示例文件。我的问题是,是否可以在系统调用函数中分叉或执行?像下面的例子一样?
#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>
/*
* The function for implementing the syscall.
*/
static int hello (struct thread *td, void *arg)
{
printf("Running...\n");
/******************************************************/
/*Something like this?*/
/******************************************************/
execl("/bin/pwd", "pwd", NULL);
return 0;
}
/*
* The `sysent' for the new syscall
*/
static struct sysent hello_sysent = {
0, /* sy_narg */
hello /* sy_call */
};
/*
* The offset in sysent where the syscall is allocated.
*/
static int offset = NO_SYSCALL;
/*
* The function called at load/unload.
*/
static int
load (struct module *module, int cmd, void *arg)
{
int error = 0;
switch (cmd) {
case MOD_LOAD :
uprintf ("syscall loaded at %d\n", offset);
break;
case MOD_UNLOAD :
uprintf ("syscall unloaded from %d\n", offset);
break;
default :
uprintf("There was some error!");
error = EINVAL;
break;
}
return error;
}
SYSCALL_MODULE(syscall, &offset, &hello_sysent, load, NULL);
没有编译错误(系统调用),但是在使用 kldload 加载时,它返回错误: kldload: 无法加载 ./syscall.ko: 没有这样的文件或目录
有什么我可以阅读并了解更多关于为什么会发生这种情况以及我能做些什么的事情吗?
【问题讨论】:
-
你试过给它一个完整的路径吗?
-
是的,我试过了。我可以看到 syscall.ko 文件在那里。
-
检查 dmesg 输出,使用 kldload -v ./syscall.ko 和文件 syscall.ko。确保您正在拉动正在运行的内核的源代码树和正确的架构(例如 i386 与 amd64)。
标签: c operating-system kernel freebsd system-calls