Добавление системного вызова с аргументами в ядро ​​FreeBSD

Я хочу добавить системный вызов с помощью KLD в FreeBSD 8.2, который имеет некоторые аргументы (здесь 1 аргумент). Я сделал следующее (фактически я изменил файл syscall.c в /usr/share/examples/kld/syscalls/ модуль/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);

Когда я создаю этот файл, используя предоставленный Makefile в каталоге модуля, я получаю:

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

В чем проблема с этим кодом?


person po0ya    schedule 31.10.2011    source источник
comment
Что такое syscall.c:56? FreeBSD компилирует файлы с -Werror, поэтому такие предупреждения рассматриваются как ошибки.   -  person cnicutar    schedule 31.10.2011


Ответы (3)


Вы инициализируете sy_call член hellomet_sysent указателем на функцию, который не соответствует typedef. sy_call имеет тип sy_call_t, который определяется как функция, которая принимает (struct thread* , void*) и возвращает int. Вместо этого ваш вызов принимает (struct thread*, struct hellomet_args *).

Попробуйте что-то вроде этого:

static struct sysent hellomet_sysent = {
    1,          
    (sy_call_t*) hellomet            
};
person janm    schedule 31.10.2011

Вы также можете добавить

NO_WERROR=

в свой Makefile.

person arrowd    schedule 31.10.2011

Попробуйте изменить подпись вашего системного вызова с

static int
hellomet(struct thread *td, struct hellomet_args *arg)

to

static int
hellomet(struct thread *td, void *arg)

а затем в теле системного вызова

...
struct hellomet_args *uap;
uap = (struct hellomet_args *)arg;
...
person PetrosB    schedule 31.10.2011