简体   繁体   English

访问内核模块

[英]Access on kernel module

I wrote a linux kernel module char device (SuSE 13.2 Kernel 3.16.6), and an application for using this device. 我编写了一个Linux内核模块char设备(SuSE 13.2 Kernel 3.16.6),以及一个使用该设备的应用程序。

In principle, the driver, the application and the communication works. 原则上,驱动程序,应用程序和通信均有效。 The application can open, read, write and close the char device. 该应用程序可以打开,读取,写入和关闭char设备。

But there is a sporadic issue, that the application somtime 'lost' the reference to the module's write function. 但是有一个零星的问题,即应用程序的“ Somtime”“丢失”了对模块写功能的引用。 After 3 to 4 (sometime much more) write commands from the application to the module, the module's write funtion isn't executed. 在3到4(有时更多)将命令从应用程序写入模块后,将不会执行模块的写功能。

I reduced and the write function inside module: 我减少了模块内部的write函数:

static ssize_t fWrite(struct file *file, const char  *buffer, size_t length, loff_t *offset)
{
  printk(KERN_ERR "INSIDE\n");
  return 0;
}

And I also reduced the applcation: 而且我还减少了申请:

int main (int argc, char **argv)
{
  unsigned short buffer=0xffff;
  fd = open ("/dev/MYPCI" , O_SYNC | O_RDWR );
  OUTPW (0, buffer ,fd );
  OUTPW (2, buffer,fd );
  OUTPW (4, buffer,fd ); 
  OUTPW (196, buffer,fd );
  OUTPW (70000, buffer,fd );   
  OUTPW (400, buffer,fd );

  printf("DEV-Handle: %d\n", fd);  
  close (fd );
}

int OUTPW (unsigned short ByteAddr, unsigned short value, int fd)
{
  int x;  
  int size = (ByteAddr/2) <<16; 
  size +=2;            

  printf ("\nByteAddr:0x%08hX value:0x%08hX size:0x%08hX WRITE-Handle: 0x%04hX\n" , ByteAddr,value,size, &write);

  x= write(fd, &value, size) ;

  return x;
}

The output looks loke this. 输出看起来很奇怪。 sometime I can read 3 times, sometime I can read 4 times, sometimes much more. 有时我可以阅读3次,有时我可以阅读4次,有时甚至更多。 输出画面

The write function handle is still valid. 写入功能句柄仍然有效。 If one write command fails, all following will also fail. 如果一个写命令失败,则随后的所有操作也会失败。 If I close&open the device again (inside the application) the write is temporary fixed. 如果我再次关闭并打开设备(在应用程序内部),则写入是暂时固定的。

The same behaviour exists on read command. 读取命令上存在相同的行为。

Any ideas? 有任何想法吗?

In the driver function fWrite() return length instead of 0. 在驱动程序函数fWrite()中返回长度而不是0。

static ssize_t fWrite(struct file *file, const char  *buffer, size_t length, loff_t *offset)
{
printk(KERN_ERR "INSIDE\n");
return length;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM