gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:39:49 25 4
gpt4 key购买 nike

我正在扩展一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com