Hi all,
I want to write a function that set write protection to all page in Virtual memory. I that moment, I do like that:
Code:
mm = task->mm;
spin_lock(&mm->page_table_lock);
for (vma = mm->mmap ; vma ; vma = vma->vm_next) { //loop for all vmas
vma->vm_flags, (int) vma->vm_flags & VM_WRITE);
addr = vma->vm_start;
vma->vm_flags &= ~VM_WRITE;
while(addr < vma->vm_end){ //loop for each page
pgd = pgd_offset(mm, addr);
if (pgd_none(*pgd)) { addr += PAGE_SIZE; continue; }
pud = pud_offset(pgd, addr);
if (pud_none(*pud)) { addr += PAGE_SIZE; continue; }
pmd = pmd_offset(pud, addr);
if (pmd_none(*pmd)) { addr += PAGE_SIZE; continue; }
pte = pte_offset_map(pmd, addr);
if (pte_present(*pte)){
*pte = pte_wrprotect(*pte);
flush_tlb_page(vma, addr);
}
spin_unlock(&mm->page_table_lock);
...........
My program work in kernel level.
But it just set write protection for a part of memory, it does't set write protection to all page that process is using.
Somebody can help me, please!