我刚开始和内核打交道。我想将一个链接列表添加到内核中,并尝试像以下链接那样修复它:Linux内核编程链表
下面是我添加到sys.c中的代码:
系统呼叫防御:
SYSCALL_DEFINE1(init_process_list,pid_t,ppid)
{
LIST_HEAD(processList);
struct scallNode* newNode;
newNode = kmalloc(sizeof(*newNode), GFP_KERNEL);
newNode->ID = ppid;
INIT_LIST_HEAD(&newNode -> list);
list_add_tail(&newNode -> list , &processList.list);
printk(KERN_INFO "INIT PROCESS UID: %u\n", ppid);
return 0;
}我的链接列表结构:
struct scallNode{
int ID;
struct file_struct ffs;
struct task_struct ts;
struct list_head list;
};
struct scallNode processList;当我编译内核时,我看到了这个错误:
error: ‘struct list_head’ has no member named ‘list’ list_add_tail(&newNode -> list , &processList.list);谢谢你的回复。
这个错误消失了,但另一个错误仍然存在。
kernel/sys.c:2136:24: error: field ‘fs’ has incomplete type struct file_struct fs;再次感谢你的答复。
发布于 2018-04-05 15:23:23
list_add_tail函数是
void list_add_tail(struct list_head *new, struct list_head *head);第二个参数应该是指向一个struct list_head的指针,所以只需这样使用:
list_add_tail(&newNode -> list , &processList);发布于 2018-04-05 14:55:00
我从来没有做过任何内核编程。但据我所知,内存分配是不正确的:
newNode = kmalloc(sizeof(*newNode), GFP_KERNEL);我觉得应该是:-
newNode = (struct scallNode *)kmalloc(sizeof(struct scallNode), GFP_KERNEL);发布于 2018-04-05 15:02:49
终于找到答案了。
在list_add_tail(&newNode -> list , &processList.list);中,大多数使用&processList而不是&processList.list。
list_add_tail查找processList本身的列表。
https://stackoverflow.com/questions/49674265
复制相似问题