bestwc
bestwc

Reputation: 81

FreeBSD issue a system call from another system call

I wrote some freebsd kernel modules like 1 year ago, they were working fine at that time. But now I can't compile.

What I'm trying to do is to hook an existing system call by modifying sysent table.

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;
}

I get the following 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.)

So I think it might be missing library. Here's my include

#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>

I read man 2 mkdir, still no clue. It seems that calling another system call from within a kernel module is no longer supported or it requires additional configuration?

Please help, thank you very much.

Upvotes: 2

Views: 729

Answers (1)

LI Xin
LI Xin

Reputation: 156

The system call entry is now prefixed with "sys_" so you should use sys_mkdir instead of just mkdir now.

The exact changeset was:

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.

Upvotes: 4

Related Questions