我刚接触内核。 我想向我的内核添加一个链表,我尝试像这个链接一样修复它:Linux Kernel Programming–Linked List
这是我添加到 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;
再次感谢您的回复。
最佳答案
list_add_tail
函数是
void list_add_tail(struct list_head *new, struct list_head *head);
第二个参数应该是指向 struct list_head
的指针,所以只需像这样使用:
list_add_tail(&newNode -> list , &processList);
关于c - 将系统调用添加到 linux 内核,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49674265/