pte_present 宏 不理解
时间:2010-05-07
来源:互联网
读内存管理时,有些不明白,请教一下:
==================== include/asmi386/
pgtable.h 248 248 ====================
#define pte_present(x) ((x).pte_low & (_PAGE_PRESENT | _PAGE_PROTNONE))
其中_PAGE_PRESENT,_PAGE_PROTNONE分别定义如下:
162 #define _PAGE_PRESENT 0x001
172 #define _PAGE_PROTNONE 0x080 /* If not present */
我们知道_PAGE_PRESENT用来表明是否在内存中对应0位,但是_PAGE_PROTNONE对应第7位,
而宏pte_present(x)表明,只要_PAGE_PRESENT,_PAGE_PROTNONE有一个置位,就说明该映射有效,
也就是说,如果_PAGE_PROTNONE为1,而_PAGE_PRESENT为0,那么该页表也是有效的,
如果这个页面交换到了磁盘,P位为0,而其他31位指向了该页面交换到的磁盘位置,就有可能出现对应于_PAGE_PROTNONE
位置的值是1,通过上面的宏,得到的这个页表是有效的错误结果,而实际页面已经交换到了磁盘。
不知道我这样理解哪里有错误?
请教了
==================== include/asmi386/
pgtable.h 248 248 ====================
#define pte_present(x) ((x).pte_low & (_PAGE_PRESENT | _PAGE_PROTNONE))
其中_PAGE_PRESENT,_PAGE_PROTNONE分别定义如下:
162 #define _PAGE_PRESENT 0x001
172 #define _PAGE_PROTNONE 0x080 /* If not present */
我们知道_PAGE_PRESENT用来表明是否在内存中对应0位,但是_PAGE_PROTNONE对应第7位,
而宏pte_present(x)表明,只要_PAGE_PRESENT,_PAGE_PROTNONE有一个置位,就说明该映射有效,
也就是说,如果_PAGE_PROTNONE为1,而_PAGE_PRESENT为0,那么该页表也是有效的,
如果这个页面交换到了磁盘,P位为0,而其他31位指向了该页面交换到的磁盘位置,就有可能出现对应于_PAGE_PROTNONE
位置的值是1,通过上面的宏,得到的这个页表是有效的错误结果,而实际页面已经交换到了磁盘。
不知道我这样理解哪里有错误?
请教了
作者: tianhailong 发布时间: 2010-05-07
#define pte_present(x) ((x).pte_low & (_PAGE_PRESENT | _PAGE_PROTNONE))
(x)是个结构
(x).pte_low是结构中的pte_low的值
pte_present(x)的值是(x).pte_low&(0x001|0x080)
(x)是个结构
(x).pte_low是结构中的pte_low的值
pte_present(x)的值是(x).pte_low&(0x001|0x080)
作者: ouyangjinlin 发布时间: 2010-05-07
回复 ouyangjinlin
pte_present(x)的值是(x).pte_low&(0x001|0x080)
如你所说,那么pte_present取决于0,7位的值,其中只要有一个为一,宏就返回真,假设pte_low 值为0x XXXXXX80,其中X指代16进制数字,那么这个数的P位0,表明该页不在内存中,
但是使用pte_present(x)返回结果表明该页在内存中,应为其第7位是1
pte_present(x)的值是(x).pte_low&(0x001|0x080)
如你所说,那么pte_present取决于0,7位的值,其中只要有一个为一,宏就返回真,假设pte_low 值为0x XXXXXX80,其中X指代16进制数字,那么这个数的P位0,表明该页不在内存中,
但是使用pte_present(x)返回结果表明该页在内存中,应为其第7位是1
作者: tianhailong 发布时间: 2010-05-07
回复 tianhailong
怎么没有人解答呢,是我说的不清楚吗?
怎么没有人解答呢,是我说的不清楚吗?
作者: tianhailong 发布时间: 2010-05-07
"注意这里的_PAGE_PROTNONE对应于页面表项中的bit7,在Intel手册中说这一位保留不用,所以对MMU不起作用" 这是情景分析里的一句话,应该可以解释你的问题,但是为什么要把_PAGE_PROTNONE加进去呢?不知道楼主现在弄的怎么样了?
作者: stone421 发布时间: 2010-12-07
本帖最后由 stone421 于 2010-12-07 19:49 编辑
http://forum.ubuntu.org.cn/viewtopic.php?t=276328 这里讨论了这个问题
#define __swp_type(x) (((x).val >> 1) & 0x1f)
#define __swp_offset(x) ((x).val >> 8 )
#define __swp_entry(type, offset) ((swp_entry_t) { ((type) << 1) | ((offset) << 8 ) })
1. according to this, the swap entry's bit0, bit6~bit7 equal to 0.
2. the kernel, however, marks Present equal to 0 and Page Size equal to 1(_PAGE_PROTNONE) for the pages present in main memory but without read, write, or execute privileges. In this way, any access to such pages triggers a Page Fault exception because Present is cleared, and the kernel can detect that the fault is not due to a missing page by checking the value of Page Size.
http://forum.ubuntu.org.cn/viewtopic.php?t=276328 这里讨论了这个问题
#define __swp_type(x) (((x).val >> 1) & 0x1f)
#define __swp_offset(x) ((x).val >> 8 )
#define __swp_entry(type, offset) ((swp_entry_t) { ((type) << 1) | ((offset) << 8 ) })
1. according to this, the swap entry's bit0, bit6~bit7 equal to 0.
2. the kernel, however, marks Present equal to 0 and Page Size equal to 1(_PAGE_PROTNONE) for the pages present in main memory but without read, write, or execute privileges. In this way, any access to such pages triggers a Page Fault exception because Present is cleared, and the kernel can detect that the fault is not due to a missing page by checking the value of Page Size.
作者: stone421 发布时间: 2010-12-07
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28