所以我正在做一些關於linux內核的工作,我正在嘗試實現一個函數,但首先我必須在內核空間中定義一個結構體。我遇到了一個錯誤,但我不太清楚原因。在linux內核空間創建結構體
我認爲它與我在開始定義的結構有關,但我似乎無法找到任何問題。
更新:好的我解決了其中一個問題。所以我會更新我的代碼片段並標記錯誤中指定的行。第24行是結構結束後的行。
下面是我在做什麼:
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/klist.h>
#include <linux/errno.h>
#include <asm/uaccess.h>
#include <linux/slab.h>
/********************************************
*This function adds a new item to the queue
*
*If not enough memory return -ENOMEM
*If there is an error accessing the upper space point return -efault
*If len is negative return -EINVAL
*Returns 0 on success
******************************/
struct dataNode
{
const void * data;
int length;
struct list_head * mylist;
}
asmlinkage long sys_writeMsgQueue421(const void __user *data, long len) //**Line 24**//
{
newNode->data = pdata;
newNode->length = len;
//****Need to add to the linked list****//
printk("This was passed in: %p and %ld \n",data , len);
return 0;
}
asmlinkage long sys_readMsgQueue421(void)
{
printk("This is the read function!\n");
return 0;
}
asmlinkage long sys_emptyMsgQueue421(void)
{
printk("This is the clear function!\n");
return 0;
}
而且我收到以下錯誤,當我運行make命令:
CC msgQueue421/msgQueue421.o msgQueue421/msgQueue421.c:24:1: warning: ‘regparm’ attribute only applies to function types [-Wattributes] msgQueue421/msgQueue421.c:24:12: error: expected ‘;’, identifier or ‘(’ before ‘long’ make[1]: * [msgQueue421/msgQueue421.o] Error 1 make: * [msgQueue421] Error 2
任何想法,我做錯了嗎?
如果你的第二個malloc失敗,你應該從第一個malloc釋放指針。 – ChuckCottrill
請在您的代碼中添加註釋,以突出顯示哪些行是第24行和第73行(您有錯誤的行) –
在行上,「newNode-> data = data;」你可能打算分配pdata – ChuckCottrill