Function Report

Linux Kernel (v4.4)

Source File:mm\mmap.c Create Date:2016-01-14 12:34:09
Last Modify:2016-01-11 07:01:32 Copyright©Brick
home page Tree
Annotate the kernelChinese

Function Name:vma_adjust

Function:int vma_adjust(struct vm_area_struct *vma, unsigned long start, unsigned long end, unsigned long pgoff, struct vm_area_struct *insert)

Return Type:int

Parameter:

Type Parameter NameRemarks
struct vm_area_struct * vma
unsigned long start
unsigned long end
unsigned long pgoff
struct vm_area_struct * insert

Function description:We cannot adjust vm_start, vm_end, vm_pgoff fields of a vma that is already present in an i_mmap tree without adjusting the tree

726  *mm = The address space we belong to.
727  *next = linked list of VM areas per task, sorted by address
728  *importer = NULL
729  *mapping = NULL
730  *The alignment might seem pointless, but allegedly CRIS needs it = NULL
731  *anon_vma = NULL
732  *file = File we map to(can be NULL).
733  start_changed = false, end_changed = false
734  adjust_next = 0
735  remove_next = 0
737  If next && !insert then
738  *exporter = NULL
745  again
747  exporter = next
748  importer = vma
755  exporter = next
756  importer = vma
764  exporter = vma
765  importer = next
783  If file then
784  mapping = f_mapping
785  The alignment might seem pointless, but allegedly CRIS needs it = & tree of private and shared mappings
786  Called in context of a munmap of a vma.
788  If adjust_next then Called in context of a munmap of a vma.
791  i_mmap_lock_write(mapping)
792  If insert then
803  vma_adjust_trans_huge(vma, start, end, adjust_next)
805  anon_vma = Serialized by page_table_lock
806  If !anon_vma && adjust_next then anon_vma = Serialized by page_table_lock
808  If anon_vma then
810  VM_BUG_ON_VMA
811  anon_vma_lock_write(anon_vma)
812  vma has some anon_vma assigned, and is already inserted on that anon_vma's interval trees.
813  If adjust_next then vma has some anon_vma assigned, and is already inserted on that anon_vma's interval trees.
817  If The alignment might seem pointless, but allegedly CRIS needs it then
818  flush_dcache_mmap_lock
819  vma_interval_tree_remove(vma, The alignment might seem pointless, but allegedly CRIS needs it)
820  If adjust_next then vma_interval_tree_remove(next, The alignment might seem pointless, but allegedly CRIS needs it)
824  If start != Our start address within vm_mm. then
825  Our start address within vm_mm. = start
826  start_changed = true
828  If end != The first byte after our end address within vm_mm. then
829  The first byte after our end address within vm_mm. = end
830  end_changed = true
832  Offset(within vm_file) in PAGE_SIZE units,*not* PAGE_CACHE_SIZE = pgoff
833  If adjust_next then
834  Our start address within vm_mm. += adjust_next << determines the page size
835  Offset(within vm_file) in PAGE_SIZE units,*not* PAGE_CACHE_SIZE += adjust_next
838  If The alignment might seem pointless, but allegedly CRIS needs it then
839  If adjust_next then vma_interval_tree_insert(next, The alignment might seem pointless, but allegedly CRIS needs it)
841  vma_interval_tree_insert(vma, The alignment might seem pointless, but allegedly CRIS needs it)
842  flush_dcache_mmap_unlock
845  If remove_next then
850  __vma_unlink(mm, next, vma)
851  If file then Requires inode->i_mapping->i_mmap_rwsem
853  Else if insert then
859  Helper for vma_adjust() in the split_vma insert case: insert a vma into the mm's list and rbtree. It has already been inserted into the interval tree.
860  Else
861  If start_changed then Update augmented rbtree rb_subtree_gap values after vma->vm_start or vma->vm_prev->vm_end values changed, without modifying the vma's position in the rbtree.
863  If end_changed then
871  If anon_vma then
872  anon_vma_interval_tree_post_update_vma(vma)
873  If adjust_next then anon_vma_interval_tree_post_update_vma(next)
875  anon_vma_unlock_write(anon_vma)
877  If mapping then i_mmap_unlock_write(mapping)
880  If The alignment might seem pointless, but allegedly CRIS needs it then
881  Called from mmap_region/vma_adjust with mm->mmap_sem acquired.
883  If adjust_next then Called from mmap_region/vma_adjust with mm->mmap_sem acquired.
887  If remove_next then
888  If file then
890  fput(file)
892  If Serialized by page_table_lock then anon_vma_merge(vma, next)
894  number of VMAs--
895  mpol_put(vma_policy)
896  kmem_cache_free(Linux kernel virtual memory manager primitives, next)
902  next = linked list of VM areas per task, sorted by address
903  If remove_next == 2 then Go to again
905  Else if next then Update augmented rbtree rb_subtree_gap values after vma->vm_start or vma->vm_prev->vm_end values changed, without modifying the vma's position in the rbtree.
907  Else highest vma end address = end
910  If insert && file then Called from mmap_region/vma_adjust with mm->mmap_sem acquired.
913  validate_mm
915  Returning 0
Caller
Function NameFunction description
vma_mergeGiven a mapping request(addr,end,vm_flags,file,pgoff), figure out whether that can be merged with its predecessor or its successor. Or both(it neatly fills a hole).
__split_vmabypasses sysctl_max_map_count checking. We use this on the munmap path where it doesn't make sense to fail.
SYSC_mremap
shift_arg_pagesDuring bprm_mm_init(), we create a temporary stack at STACK_TOP_MAX. Once the binfmt code determines where the new stack should reside, we shift it to its final location. The process proceeds as follows: