Use do_mmap () in Linux device driver

Now the device in which we are working should have a virtual memory address for user space, we are trying to use do_mmap (), as shown below:

*uvaddr = (void *)do_mmap(0, 0, size, PROT_READ|PROT_WRITE, MAP_ANONYMOUS, 0); 

But we got the following error:

 Unable to handle kernel paging request for data at ad8 

Can I use "do_mmap ()" in the device driver? If not, the right way to do this?

+4
source share
1 answer

It is possible that do_mmap succeeds, but uvaddr does not indicate a valid place to store the result. To make sure of this, do something like:

 void *mmap_result; printk(KERN_DEBUG "uvaddr = %p", uvaddr); mmap_result = (void *)do_mmap(0, 0, size, PROT_READ|PROT_WRITE, MAP_ANONYMOUS, 0); printk(KERN_DEBUG "mmap_result = %p", mmap_result); *uvaddr = mmap_result; 

This should tell you for sure what fails: calling do_mmap or assigning *uvaddr .

+1
source

Source: https://habr.com/ru/post/1343749/


All Articles