首页 > 解决方案 > 无法从内核代码中的另一个头文件访问 task_struct 结构

问题描述

我试图在内核代码中访问我的模块中的结构,我想要访问的结构是在头文件task_struct中定义的。<linux/sched.h>然后使用current->parent例如,我尝试访问函数内部的结构init_module

我收到一个警告和一个错误

error: function declaration isn’t a prototype [-Werror=strict-prototypes]
struct task_struct *current;
warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
struct task_struct *current;
#include <linux/init.h>
#include <linux/module.h>
#include <linux/sched.h>

MODULE_LICENSE("GPL");

static int hello_init(void)
{
    printk(KERN_ALERT "My-Module: Hello, World\n");
    struct task_struct *current;
    return 0;
}

static void hello_exit(void)
{
    printk(KERN_ALERT "My-Module: Goodbye, cruel world.\n");
}

module_init(hello_init);
module_exit(hello_exit);
// gcc

标签: clinux-kernel

解决方案


推荐阅读