gpt4 book ai didi

c - insmod : error when inserting kernel module

转载 作者:太空宇宙 更新时间:2023-11-04 02:09:47 26 4
gpt4 key购买 nike

我正在尝试实现一个内核模块,它可以访问用户进程的 task_struct,我已经知道其进程 ID。我正在使用 find_get_pidpid_task 来获取进程的 task_struct:

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/pid.h>
#include <linux/pid_namespace.h>

int init_module( void )
{
//Declaring the variables
int p_id = 6980; //6980 is the process ID of my user process
struct pid *pid_struct;
struct task_struct *task;

// Trying to access the variables of the p_id
pid_struct = find_get_pid(p_id);
task = pid_task(pid_struct, PIDTYPE_PID);

//Printing the info from the task_struct
printk( KERN_INFO "*** [%d]\n",task->pid);
return 0;
}

void cleanup_module( void )
{
return;
}

编译成功,我得到 *.ko 文件,但是当我试图将它插入内核时,它给我一个错误:
insmod: 错误插入 'main.ko': -1 模块中的未知符号
Dmesg 给我以下输出:
main: 未知符号 find_get_pid (err 0)
我不知道如何进行,如果有人能帮助我,我将不胜感激。

最佳答案

仔细检查你要使用的函数调用了什么。

还要记住,大部分“核心内核”(大概包括 frob_task_by_pid_hard 及其同类)都是 GPL-only,因此除非您将模块的许可证声明为 GPL,否则您将无处可去.也请至少填写模块上的其他样板数据:MODULE_AUTHOR、MODULE_DESCRIPTION、MODULE_LICENSE。

关于c - insmod : error when inserting kernel module,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15837411/

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