【问题标题】:FreeBSD SysCall in C -> implicit declaration of function 'modfind'C 中的 FreeBSD SysCall -> 函数“modfind”的隐式声明
【发布时间】:2012-01-12 11:30:40
【问题描述】:

我正在扩展一个 FreeBSD 模块,我需要能够调用我编写的 2 个系统调用函数(使用 KLD)。我知道系统调用函数本身工作正常,因为我有一个单独的测试程序可以调用它们并返回正确的值。

但是,当我尝试将该测试程序的适当部分插入到实际程序中时,我得到了

vnode.c: In function 'getSyscall':
vnode.c:1014: warning: implicit declaration of function 'modfind'
vnode.c:1022: warning: implicit declaration of function 'modstat'
*** Error code 1

我拥有真实的(工作)测试程序的所有包含,所以我不明白为什么它找不到 modfind 和 modstat 函数。

#include <stdio.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/module.h>
#include <unistd.h>
#include <errno.h>
#include <sys/param.h>

// Lots of other unrelated functions here


/*
 *
 * returns a syscall number or -1 for error
 */
int getSyscall
(char *str)
{
    struct module_stat stat;
    int modid;
    int syscallnum;

    modid = modfind(str);
    if (modid == -1)
    {
        perror("modfind: ");
        return -1;
    }

    stat.version = sizeof(stat);
    if (modstat(modid, &stat) == -1)
    {
        perror("modstat: ");
        return -1;
    }

    syscallnum = stat.data.intval;

    return syscallnum;
}

【问题讨论】:

  • 您使用的是什么 FreeBSD 版本?我已经在 9-STABLE 上编译了你的代码,没有任何警告。

标签: c linux gcc freebsd system-calls


【解决方案1】:

一定要

#include <sys/module.h>

(在 sys/param.h 之后)。 modfind(2) 手册页是这样说的。

(为什么这个带有“linux”标签的问题比我好...)

【讨论】:

    猜你喜欢
    • 2012-02-29
    • 2016-08-10
    • 1970-01-01
    • 1970-01-01
    • 2014-03-27
    • 1970-01-01
    相关资源
    最近更新 更多