I want to add a system call using KLD in FreeBSD 8.2 that has some arguments (1 argument here)
I’ve done the following (I’ve actually changed the the syscall.c in /usr/share/examples/kld/syscalls/module/syscall.c)
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/module.h>
#include <sys/sysproto.h>
#include <sys/sysent.h>
#include <sys/kernel.h>
#include <sys/systm.h>
struct hellomet_args{
int a;
};
static int
hellomet(struct thread *td, struct hellomet_args *arg)
{
int a = arg->a;
printf("hello secondish kernel %d \n",a);
return (0);
}
static struct sysent hellomet_sysent = {
1,
hellomet
};
static int offset = NO_SYSCALL;
static int
load(struct module *module, int cmd, void *arg)
{
int error = 0;
switch (cmd) {
case MOD_LOAD :
printf("syscall loaded at %d\n", offset);
break;
case MOD_UNLOAD :
printf("syscall unloaded from %d\n", offset);
break;
default :
error = EOPNOTSUPP;
break;
}
return (error);
}
SYSCALL_MODULE(hellomet, &offset, &hellomet_sysent, load, NULL);
When I make this file using provided Makefile in module directory I get :
cc1: warnings being treated as errors syscall.c:56: warning: initialization from incompatible pointer type
*** Error code 1
Stop in /usr/share/examples/kld/syscall/module.
*** Error code 1
What’s the problem with this code?
You are initialising the
sy_callmember ofhellomet_sysentwith a function pointer that doesn’t match the typedef.sy_callis of typesy_call_t, which is defined as being a function that takes(struct thread* , void*)and returnsint. Your call takes(struct thread*, struct hellomet_args *)instead.Try something like this: