-1

So I am doing some work on a linux kernel for class and I am trying to implement a function but first I must define a struct in kernel space. I am getting an error but I am not too sure the cause.

I assume it has something to do with the struct I defined at the beginning but I can't seem to find any issues with it.

UPDATE: Ok I have solved one of the problems. So I will be updating my code snippet and marking lines that are specified in the errors. Line 24 is the line right after the end of the struct.

Here is what I am doing:

#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;
}

And I am getting the following errors when I run the make command:

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

Any idea what I'm doing wrong?

4

2 回答 2

2

您现在遇到的问题(因为还有其他问题,其中一些已经被指出)是您缺少 a;来关闭您的struct声明:

struct dataNode
{
void *data;
int length;
struct list_head * mylist;
}

asmlinkage long sys_writeMsgQueue421(const void __user *data, long len)

编译器试图解析这段代码,认为asmlinkage long ...等等是变量名,它们将是struct dataNode. 当然,asmlinkage几乎可以肯定是一个扩展为谁知道什么的宏,并且long是一个不能作为变量名的保留字。

所以你会得到错误。很多很多的错误。

一般而言,当您在行中遇到错误N并且您没有发现该行有任何问题时,请始终查看错误之前的最后几行代码,以查看是否缺少某些内容。

于 2013-10-30T02:01:48.800 回答
1

很高兴知道第 24 + 73 行是什么,但“const”的事情可能是由

  newNode->data = data;

你想在pdata这里分配(不是 __user 指针)。

关于第一个错误组的盲目猜测:缺少#include,因此未定义 __user。

顺便说一句:

struct list_head * mylist;

在您的严格中很可能是错误的,因为您不能取消引用它。使用普通struct list_head mylist;的而不是

于 2013-10-30T01:55:05.113 回答