【问题标题】:Adding a syscall with arguments to FreeBSD kernel向 FreeBSD 内核添加带有参数的系统调用
【发布时间】:2011-12-18 12:04:17
【问题描述】:

我想在 FreeBSD 8.2 中使用 KLD 添加一个系统调用,它有一些参数(这里有 1 个参数) 我已经完成了以下操作(实际上我已经更改了 /usr/share/examples/kld/syscalls/module/syscall.c 中的 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

这段代码有什么问题?

【问题讨论】:

  • syscall.c:56 是什么? FreeBSD 编译带有-Werror 的东西,所以像这样的警告被视为错误。

标签: kernel freebsd system-calls


【解决方案1】:

您正在使用与 typedef 不匹配的函数指针初始化 hellomet_sysentsy_call 成员。 sy_callsy_call_t 类型,它被定义为一个接受(struct thread* , void*) 并返回int 的函数。您的电话改为使用(struct thread*, struct hellomet_args *)

试试这样的:

static struct sysent hellomet_sysent = {
    1,          
    (sy_call_t*) hellomet            
};

【讨论】:

    【解决方案2】:

    你也可以加

    NO_WERROR=
    

    进入你的 Makefile。

    【讨论】:

      【解决方案3】:

      尝试从

      更改系统调用的签名
      static int
      hellomet(struct thread *td, struct hellomet_args *arg)
      

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

      然后,在系统调用的主体中

      ...
      struct hellomet_args *uap;
      uap = (struct hellomet_args *)arg;
      ...
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-04-25
        • 1970-01-01
        • 2016-06-02
        • 1970-01-01
        • 2020-05-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多