Use do_mmap() in Linux device driver

回眸只為那壹抹淺笑 提交于 2020-01-03 18:34:09

问题


The device we work at now need to have a user space virtual memory address, we try to use do_mmap() as below:

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

But we got following error

Unable to handle kernel paging request for data at ad8

Is it okay to use "do_mmap()" in a device driver? If not, any correct way to do it?


回答1:


It's possible that do_mmap is succeeding, but uvaddr does not point to a valid location to store the result. To check this for sure, 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 certain which is failing: the call to do_mmap or the assignment to *uvaddr.



来源:https://stackoverflow.com/questions/5310139/use-do-mmap-in-linux-device-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!