- 论坛徽章:
- 0
|
进程匿名空间未分配页帧时,对匿名空间读操作会引发缺页异常,对应缺页异常处理函数为:- static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
- unsigned long address, pte_t *page_table, pmd_t *pmd,
- unsigned int flags)
- {
- struct page *page;
- spinlock_t *ptl;
- pte_t entry;
- pte_unmap(page_table);
- /* Check if we need to add a guard page to the stack */
- if (check_stack_guard_page(vma, address) < 0)
- return VM_FAULT_SIGBUS;
- /* Use the zero-page for reads */
- if (!(flags & FAULT_FLAG_WRITE)) {
- entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
- vma->vm_page_prot));
- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
- if (!pte_none(*page_table))
- goto unlock;
- goto setpte;
- }
复制代码 正常情况应该是设置页表项为只读的,对匿名区间进行写操作时引发缺页异常;此时会作COW操作,申请一个页帧,并将页帧清0。
ULK中看到的代码会作页表项写保护:
entry = pte_wrprotect(mk_pte(virt_to_page(empty_zero_page),
vma->vm_page_prot));
但是2.6.32.60代码是用pte_mkspecial:
pte_mkspecial只是把pte的第9位置1,而页表项第9位是ignore的。
Table 4-6. Format of a 32-Bit Page-Table Entry that Maps a 4-KByte Page
11:9 Ignored
但此处页表项权限是vma的权限,而没有写保护,此处怎样引发缺页异常进而作COW操作呢?
|
|