LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-13-2015, 10:59 AM   #1
helloworld2008
LQ Newbie
 
Registered: Mar 2015
Posts: 1

Rep: Reputation: Disabled
Question How to set write protection to all page in Virtual memory of a process?


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!
 
Old 03-27-2015, 08:54 AM   #2
KelvinS687
LQ Newbie
 
Registered: Dec 2014
Location: UK
Posts: 5

Rep: Reputation: Disabled
Hi,
Can you specify, which type of operating system are you using of Linux? Is it RHEL, Ubuntu, Centos, Fedora etc....
 
Old 03-27-2015, 09:48 AM   #3
genss
Member
 
Registered: Nov 2013
Posts: 741

Rep: Reputation: Disabled
@OP memory is in pages, as far as the OS is concerned

@Kelvin try "man mprotect"
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
see how much virtual memory is assigned to a process rmcateer Programming 5 03-01-2015 09:53 AM
In Linux, apart from malloc() what can increase the virtual memory of a process? gmwebway Programming 3 10-27-2010 09:37 AM
why is process's maximum virtual memory size limited to 1.2GB on PPC64 wagaboy Linux - Software 3 06-26-2010 06:50 AM
process, memory, swap, virtual memory wakatana Linux - Hardware 1 08-31-2009 07:55 AM
Would you please tell me that how can i set virtual memory in linux Red Hat 8.0 i.e. feda82 Linux - Newbie 1 02-09-2006 01:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration