FreeBSD SysCall in C - >函数'modfind'的隐式声明

时间:2011-12-04 04:16:12

标签: c linux gcc freebsd system-calls

我正在扩展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;
}

1 个答案:

答案 0 :(得分:0)

一定要

#include <sys/module.h>

(在sys / param.h之后)。 modfind(2)手册页说明了这一点。

(为什么这个用“linux”标记的问题比我好......)