Ubuntu 9.04, Kernel 2.6.28.10中mmap()使用

来源:互联网 发布:武汉程序员培训机构 编辑:程序博客网 时间:2024/05/18 00:18

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
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 2岁宝宝鼻甲肿大怎么办 感冒10多天不好怎么办 宝妈鼻炎犯了怎么办 鼻炎犯了好多黄鼻涕怎么办 空调吹多了上火怎么办 宝宝感冒鼻塞流鼻涕口臭怎么办 怀孕了有鼻息肉怎么办 孕晚期鼻炎犯了怎么办 孕妇鼻炎犯了头疼怎么办 一岁宝宝有鼻炎怎么办 蒸馒头的面酸了怎么办 dnf点券充错账号了怎么办 英雄联盟点券充错区了怎么办 文玩鼻烟壶盖子松了怎么办 文胸磨腋下的肉怎么办 荷兰在窝里拉屎怎么办 宝宝把泡沫吃了怎么办 荷兰猪一直叫该怎么办 人吃了缓冲泡沫怎么办 不小心吃了泡沫怎么办 不想养荷兰猪了怎么办 刚买的乌龟死了怎么办 剪猫指甲出血了怎么办 猫吃了酸性植物怎么办 金鱼在缸底不动怎么办 野兔子不吃不喝怎么办 让荷兰猪咬了怎么办 仓鼠的脚被棉花怎么办 仓鼠的脚变黑了怎么办 夏天小仓鼠生了怎么办 把仓鼠摔出血了怎么办 仓鼠摔成骨折了怎么办 孩子被仓鼠咬了怎么办 仓鼠不咬磨牙石怎么办 仓鼠妈妈跑了宝宝怎么办 买的仓鼠繁殖了怎么办 仓鼠没有鼠粮了怎么办 仓鼠被踩吐血了怎么办? 买的蓝莓太酸怎么办 荷兰猪夏天掉毛怎么办 被猫抓伤肿了怎么办