Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:mm\mremap.c Create Date:2022-07-28 14:53:41
Last Modify:2020-03-12 14:18:49 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:Expand (or shrink) an existing mapping, potentially moving it at the* same time (controlled by the MREMAP_MAYMOVE flag and available VM space)* MREMAP_FIXED option added 5-Dec-1999 by Benjamin LaHaise* This option implies MREMAP_MAYMOVE.

Proto:SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len, unsigned long, new_len, unsigned long, flags, unsigned long, new_addr)

Type:

Parameter:Nothing

599  mm = mm
601  ret = -EINVAL
602  charged = 0
603  bool locked = false
604  bool downgraded = false
605  uf = NULL_VM_UFFD_CTX
606  LIST_HEAD(uf_unmap_early)
607  LIST_HEAD(uf_unmap)
609  addr = Architectures that support memory tagging (assigning tags to memory regions,* embedding these tags into addresses that point to these memory regions, and* checking that the memory and the pointer tags match on memory accesses)(addr)
611  If flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE) Then Return ret
614  If flags & MREMAP_FIXED && Not (flags & MREMAP_MAYMOVE) Then Return ret
617  If offset_in_page(addr) Then Return ret
620  old_len = align the pointer to the (next) page boundary (old_len)
621  new_len = align the pointer to the (next) page boundary (new_len)
628  If Not new_len Then Return ret
631  If lock for writing Then Return -EINTR
634  If flags & MREMAP_FIXED Then
635  ret = mremap_to(addr, old_len, new_addr, new_len, & locked, & uf, & uf_unmap_early, & uf_unmap)
637  Go to out
646  If old_len >= new_len Then
649  retval = Munmap is split into 2 main parts -- this part which finds* what needs doing, and the areas themselves, which do the* work. This now handles partial unmappings.* Jeremy Fitzhardinge
651  If retval < 0 && old_len != new_len Then
652  ret = retval
653  Go to out
655  Else if retval == 1 Then downgraded = true
657  ret = addr
658  Go to out
664  vma = vma_to_resize(addr, old_len, new_len, & charged)
665  If IS_ERR(vma) Then
666  ret = PTR_ERR(vma)
667  Go to out
672  If old_len == The first byte after our end addresswithin vm_mm. - addr Then
674  If vma_expandable(vma, new_len - old_len) Then
679  ret = -ENOMEM
680  Go to out
684  If Flags, see mm.h. & VM_LOCKED Then
689  ret = addr
690  Go to out
698  ret = -ENOMEM
699  If flags & MREMAP_MAYMOVE Then
700  map_flags = 0
701  If Flags, see mm.h. & VM_MAYSHARE Then map_flags |= Share changes
704  new_addr = get_unmapped_area(File we map to (can be NULL). , 0, new_len, Offset (within vm_file) in PAGE_SIZEunits + ((addr - Our start address within vm_mm. ) >> PAGE_SHIFT determines the page size ), map_flags)
708  If IS_ERR_VALUE(new_addr) Then
709  ret = new_addr
710  Go to out
713  ret = move_vma(vma, addr, old_len, new_len, new_addr, & locked, & uf, & uf_unmap)
716  out :
717  If offset_in_page(ret) Then
718  vm_unacct_memory(charged)
719  locked = 0
721  If downgraded Then lease a read lock
723  Else lease a write lock
725  If locked && new_len > old_len Then mm_populate(new_addr + old_len, new_len - old_len)
727  userfaultfd_unmap_complete(mm, & uf_unmap_early)
728  mremap_userfaultfd_complete( & uf, addr, new_addr, old_len)
729  userfaultfd_unmap_complete(mm, & uf_unmap)
730  Return ret