Ubuntu 9.04 Kernel 2.6.28.10中mmap()使用

环境:Ubuntu 9.04

在这里不说语法和API,就说说在2.6.28.10内核(好像在2.6.25+的内核中就是这样了)中使用mmap()注意的事项。

在新的内核中,有两个选项和mmap()映射内存/dev/mem有关:CONFIG_X86_PAT和CONFIG_STRICT_DEVMEM,内核中有这样一段话:

CONFIG_STRICT_DEVMEM:

If this option is disabled, you allow userspace (root) access to all

of memory, including kernel and userspace memory. Accidental

access to this is obviously disastrous, but specific access can

be used by people debugging the kernel. Note that with PAT support

enabled, even in this case there are restrictions on /dev/mem

use due to the cache aliasing requirements.

If this option is switched on, the /dev/mem file only allows

userspace access to PCI space and the BIOS code and data regions.

This is sufficient for dosemu and X and all common users of    /dev/mem.

所以,如果要使用mmap映射/dev/mem文件的话,必须将这两个量取消。如果不取消CONFIG_X86_PAT,则/dev/mem不允许映射;如果不取消CONFIG_STRICT_DEVMEM,则内核空间不能映射,调用mmap()的时候会出现Invalid Parameter错误

在.config文件中设置:

CONFIG_X86_PAT=n  
CONFIG_STRICT_DEVMEM=n 
CONFIG_X86_PAT=n
CONFIG_STRICT_DEVMEM=n

或者在以下路径中设置取消两个选项:

CONFIG_X86_PAT的位置在:  
Processor type and features  —>  
[*]   x86 PAT support  
CONFIG_STRICT_DEVMEM的位置在:  
Kernel hacking  —>  
[ ] Filter access to /dev/mem  

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwpxds.html