c - 无法从内核代码中的另一个头文件访问 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
解决方案
推荐阅读
- python - Pandas: Find first occurrences of elements that appear in a certain column
- python - 如何在 Python 中将 HDF5 文件直接上传到 S3 存储桶
- java - Rotating Coordinates (Java and Geometry)
- asp.net-core - Asp.net Core 2.1 HttpClientFactory:第二个api调用不等待第一个api调用的返回结果
- c++11 - 为什么我在使用 Drake 构建 CMake 项目时会出现链接器错误,但我可以清楚地看到符号?
- sql - 我的数据库的 SQL Server 脚本权限
- java - 如果给定条件为假,如何编写注释/方面以不输入方法但返回 null?
- c# - 自定义迭代器如何通知订阅者对其迭代项的更改(想想“INotifyCollectionChanged”)?
- django - Django admin ImageField:上传一个有效的图像。您上传的文件不是图像或损坏的图像
- java - 将 Java 类转换为 Proto 定义的工具