linux - How can I use the vm_operations struct to intercept page faults to a particular set of pages? -


i create kernel module when given id of process can lookup task struct , memory map. when finds should attach function serve page faults particular set of pages (namely heap pages).

set vma->vm_ops->fault of needed vma. can easier, if hack heap allocator , replace mmaps mmap_anonymous mmap of special device.

code related: http://lxr.free-electrons.com/source/mm/memory.c?v=3.12#l3676

3689 static int handle_pte_fault(struct mm_struct *mm, 3690                      struct vm_area_struct *vma, unsigned long address, 3691                      pte_t *pte, pmd_t *pmd, unsigned int flags) 3692 { 3693         pte_t entry; 3694         spinlock_t *ptl; 3695  3696         entry = *pte; 3697         if (!pte_present(entry)) { 3698                 if (pte_none(entry)) { 3699                         if (vma->vm_ops) { 3700                                 if (likely(vma->vm_ops->fault))  /* here */ 3701                                         return do_linear_fault(mm, vma, address, 3702                                                 pte, pmd, flags, entry); 3703                         } 3704                         return do_anonymous_page(mm, vma, address, 3705                                                  pte, pmd, flags); 3706                 } 3707                 if (pte_file(entry)) 3708                         return do_nonlinear_fault(mm, vma, address, 3709                                         pte, pmd, flags, entry); 3710                 return do_swap_page(mm, vma, address, 3711                                         pte, pmd, flags, entry); 3712         } 

some docs: https://lwn.net/articles/242625/ "fault()" - [posted july 23, 2007 corbet], lwn

you may check ldd book, chapter 15: http://lwn.net/images/pdf/ldd3/ch15.pdf (bit outdated, uses nopage hanlder was replaced fault() handler in 2007)


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -