Ubuntu 9.04, Kernel 2.6.28.10中mmap()使用

http://blog.csdn.net/wangjingfei/article/details/4646425

在这里不说语法和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文件中设置:

[c-sharp] view plain copy
  1. CONFIG_X86_PAT=n  
  2. CONFIG_STRICT_DEVMEM=n  

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

[c-sharp] view plain copy
  1. CONFIG_X86_PAT的位置在:  
  2. Processor type and features  —>  
  3. [*]   x86 PAT support  
  4. CONFIG_STRICT_DEVMEM的位置在:  
  5. Kernel hacking  —>  
  6. [ ] Filter access to /dev/mem   



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值