我正在尝试在内核级别使用 linux/list.h 创建链接列表。我的代码可以编译,但是当我尝试将多个节点添加到链表中时,它会导致内核错误。这是我的内核级代码:
//global defs
struct Node {
char *data;
struct list_head list;
};
LIST_HEAD(mylinkedlist);
DEFINE_MUTEX(mut);
asmlinkage long write(const void __user *data, long len){
//create new space in memory enough to fit data
void *ptr = kmalloc(len, GFP_KERNEL);
//create the user space pointer to kernel space pointer
int verif = copy_from_user(ptr, data, len);
if(verif != 0){
return -EFAULT;
}
struct Node first = {ptr, LIST_HEAD_INIT(first.list)};
//wait for mutex to be available
mutex_lock_interruptible(&mut);
list_add_tail(&first.list, &mylinkedlist);
//release the mutex
mutex_unlock(&mut);
return 0;
我的用户态程序看起来像:
long hello_syscall(void) {
char *arg = "Hello";
return syscall(351, "Hello", sizeof(arg));
}
这一切都可以编译,但是当我多次尝试运行用户态程序时,它显示我有一个内核 oops。我已经创建了操作系统在它发生时给我的错误消息的要点:https ://gist.github.com/anonymous/7217210