Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

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

Name:The caller must hold down_write(&current->mm->mmap_sem).

Proto:unsigned long do_mmap(struct file *file, unsigned long addr, unsigned long len, unsigned long prot, unsigned long flags, vm_flags_t vm_flags, unsigned long pgoff, unsigned long *populate, struct list_head *uf)

Type:unsigned long

Parameter:

TypeParameterName
struct file *file
unsigned longaddr
unsigned longlen
unsigned longprot
unsigned longflags
vm_flags_tvm_flags
unsigned longpgoff
unsigned long *populate
struct list_head *uf
1373  mm = mm
1374  pkey = 0
1376  populate = 0
1378  If Not len Then Return -EINVAL
1387  If prot & page can be read && personality & READ_IMPLIES_EXEC Then If Not (file && path_noexec( & f_path)) Then
1389  prot |= page can be executed
1392  If flags & MAP_FIXED which doesn't unmap underlying mapping Then flags |= Interpret addr exactly
1395  If Not (flags & Interpret addr exactly ) Then addr = If a hint addr is less than mmap_min_addr change hint to be as* low as possible but still greater than mmap_min_addr
1399  len = align the pointer to the (next) page boundary (len)
1400  If Not len Then Return -ENOMEM
1404  If pgoff + (len >> PAGE_SHIFT determines the page size ) < pgoff Then Return -EOVERFLOW
1408  If number of VMAs > sysctl_max_map_count Then Return -ENOMEM
1414  addr = get_unmapped_area(file, addr, len, pgoff, flags)
1415  If IS_ERR_VALUE(addr) Then Return addr
1418  If flags & MAP_FIXED which doesn't unmap underlying mapping Then
1419  vma = Look up the first VMA which satisfies addr < vm_end, NULL if none.
1421  If vma && Our start address within vm_mm. < addr + len Then Return -EEXIST
1425  If prot == page can be executed Then
1426  pkey = execute_only_pkey(mm)
1427  If pkey < 0 Then pkey = 0
1435  vm_flags |= Combine the mmap "prot" argument into "vm_flags" used internally. | Combine the mmap "flags" argument into "vm_flags" used internally. | def_flags | limits for mprotect() etc | VM_MAYWRITE | VM_MAYEXEC
1438  If flags & pages are locked Then If Not can_do_mlock() Then
1440  Return -EPERM
1442  If mlock_future_check(mm, vm_flags, len) Then Return -EAGAIN
1445  If file Then
1446  inode = file_inode(file)
1449  If Not file_mmap_ok(file, inode, pgoff, len) Then Return -EOVERFLOW
1452  flags_mask = The historical set of flags that all mmap implementations implicitly* support when a ->mmap_validate() op is not provided in file_operations. | mmap_supported_flags
1455  Case & == Share changes
1466  If flags & ~flags_mask Then Return -EOPNOTSUPP
1468  If prot & page can be written Then
1469  If Not (f_mode & le is open for writing ) Then Return -EACCES
1471  If IS_SWAPFILE(host) Then Return -ETXTBSY
1479  If IS_APPEND(inode) && f_mode & le is open for writing Then Return -EACCES
1485  If locks_verify_locked(file) Then Return -EAGAIN
1493  Case & == Changes are private
1494  If Not (f_mode & le is open for reading ) Then Return -EACCES
1496  If path_noexec( & f_path) Then
1497  If vm_flags & VM_EXEC Then Return -EPERM
1499  vm_flags &= ~VM_MAYEXEC
1502  If Not mmap Then Return -ENODEV
1506  Break
1508  Default
1509  Return -EINVAL
1511  Else
1513  Case & == Share changes
1519  pgoff = 0
1521  Break
1522  Case & == Changes are private
1527  Break
1528  Default
1529  Return -EINVAL
1537  If flags & don't check for reservations Then
1539  If sysctl_overcommit_memory != OVERCOMMIT_NEVER Then vm_flags |= should the VM suppress accounting
1543  If file && is_file_hugepages(file) Then vm_flags |= should the VM suppress accounting
1547  addr = mmap_region(file, addr, len, vm_flags, pgoff, uf)
1548  If Not IS_ERR_VALUE(addr) && ( vm_flags & VM_LOCKED || (flags & (populate (prefault) pagetables | do not block on IO )) == populate (prefault) pagetables ) Then populate = len
1552  Return addr
Caller
NameDescribe
do_mmap_pgoff