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

标签 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;
}

最佳答案

一定要

#include <sys/module.h>

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

(为什么这个问题被标记为“linux”打败了我......)

关于c - C 中的 FreeBSD SysCall -> 函数的隐式声明 'modfind',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8373222/

相关文章:

c++ - 具有可修补嵌入式配置的应用程序

c - fwrite() 会让你写一些超过文件大小的东西吗?

c - 链接列表未显示节点,请检查代码

c - C 中通过函数计算数组大小

linux - ffmpeg 从 Linux 管道读取图像路径时显示 "No JPEG data found in image"

linux - 让 Android SDK 工具在 Raspberry PI 上工作

c - 为什么在 C 中 float 转换为 int 时会四舍五入?

c - Unix 套接字,SOCK_SEQPACKET 与 SOCK_DGRAM

linux - 添加 svn :keywords in RapidSVN not working in Google Code

c - 从 C 中的不兼容指针类型 [默认启用] 警告返回