c - 将系统调用添加到 linux 内核

标签 c linux linked-list linux-kernel kernel

我刚接触内核。 我想向我的内核添加一个链表,我尝试像这个链接一样修复它: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/

相关文章:

linux - 我如何并行grep

c++ - 为什么我在这里遇到段错误?

java - Java API中LinkedList类中的 "header"

c - 在 C 中键入强制地址

c - 接受论据并使用它

c - 如何正确地将被杀死的子进程的退出状态传递给外壳程序?

linux - 有没有办法将文件描述符传递给另一个进程?

c - K&R 之后用什么书来学习纯 C 编程?

c - 将大型 (~4MB) 文件上传到 boa 网络服务器时出现不可预测的行为

performance - OCaml 中的恒定时间列表串联