Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:mm\nommu.c Create Date:2022-07-28 14:37:31
Last Modify:2020-03-17 21:26:27 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:handle mapping creation for uClinux

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
1115  populate = 0
1119  ret = determine whether a mapping should be permitted and, if so, what sort of* mapping we're capable of supporting
1121  If ret < 0 Then Return ret
1125  addr = 0
1126  len = align the pointer to the (next) page boundary (len)
1130  vm_flags |= we've determined that we can make the mapping, now translate what we* now know into VMA flags
1133  region = Shortcuts
1134  If Not region Then Go to error_getting_region
1137  vma = vm_area_alloc(mm)
1138  If Not vma Then Go to error_getting_vma
1141  gion usage count (access under nommu_region_sem) = 1
1142  VMA vm_flags = vm_flags
1143  he offset in vm_file corresponding to vm_start = pgoff
1145  Flags, see mm.h. = vm_flags
1146  Offset (within vm_file) in PAGE_SIZEunits = pgoff
1148  If file Then
1149  he backing file or NULL = get_file(file)
1150  File we map to (can be NULL). = get_file(file)
1153  lock for writing
1163  If vm_flags & VM_MAYSHARE Then
1167  pglen = len + PAGE_SIZE - 1 >> PAGE_SHIFT determines the page size
1168  pgend = pgoff + pglen
1170  When rb cycle
1171  pregion = rb_entry(rb, structvm_region, vm_rb)
1173  If Not (VMA vm_flags & VM_MAYSHARE) Then Continue
1177  If file_inode(he backing file or NULL ) != file_inode(file) Then Continue
1187  If pgoff >= rpgend Then Continue
1197  Continue
1202  vm_region = pregion
1210  Else
1223  region = pregion
1224  result = start
1225  Go to share
1235  If IS_ERR_VALUE(addr) Then
1248  Else
1255  vm_region = region
1260  If file && Flags, see mm.h. & VM_SHARED Then ret = set up a shared mapping on a file (the driver or filesystem provides and* pins the storage)
1262  Else ret = set up a private mapping or an anonymous shared mapping
1264  If ret < 0 Then Go to error_just_free
1266  add a region into the global tree
1269  If Not File we map to (can be NULL). && ( Not IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',* 0 otherwise.(CONFIG_MMAP_ALLOW_UNINITIALIZED) || Not (flags & For anonymous mmap, memory could be* uninitialized ) ) Then memset((void * )start address of region , 0, gion initialised to here - start address of region )
1276  result = Our start address within vm_mm.
1278  total_vm += len >> PAGE_SHIFT determines the page size
1280  share :
1281  add a VMA into a process's mm_struct in the appropriate place in the list* and tree and add to the address space's page tree also if not an anonymous* page* - should be called with mm->mmap_sem held writelocked
1285  If Flags, see mm.h. & VM_EXEC && Not rue if the icache has been flushed for* this region Then
1286  flush_icache_range(start address of region , gion initialised to here )
1287  rue if the icache has been flushed for* this region = true
1290  lease a write lock
1292  Return result
1294  error_just_free :
1295  lease a write lock
1296  error :
1297  If he backing file or NULL Then fput(he backing file or NULL )
1299  kmem_cache_free(list of mapped, potentially shareable regions , region)
1300  If File we map to (can be NULL). Then fput(File we map to (can be NULL). )
1302  vm_area_free(vma)
1303  Return ret
1305  sharing_violation :
1306  lease a write lock
1307  pr_warn("Attempt to share mismatched mappings\n")
1308  ret = -EINVAL
1309  Go to error
1311  error_getting_vma :
1312  kmem_cache_free(list of mapped, potentially shareable regions , region)
1313  pr_warn("Allocation of vma for %lu byte allocation from process %d failed\n", len, pid)
1315  Show free area list (used inside shift_scroll-lock stuff)* We also calculate the percentage fragmentation
1316  Return -ENOMEM
1318  error_getting_region :
1319  pr_warn("Allocation of vm region for %lu byte allocation from process %d failed\n", len, pid)
1321  Show free area list (used inside shift_scroll-lock stuff)* We also calculate the percentage fragmentation
1322  Return -ENOMEM