Pick a Free OS

User login

Navigation

For Kernel_Newbies By a Kernel_Newbie

verification of the arguments passed from user_space, is to ensure the creation

of a virtual memory area,before calling the Files mmap method. (f_op->mmap)

This method takes charge of actually mapping the pages to the tasks virtual

address space,in order for things to go around smoothly, on access of the

virtual address. Most of the calls to mmap,ask the kernel to resolve a virtual

address by giving a ZERO argument (even shmat for shared memory calls do that)

for the virtual address to be mapped. If the map is not MAP_FIXED,and the

argument is a Zero,do_mmap_pgoff gets a virtual address by calling

get_unmapped_addr,which starts checking from TASK_UNMAPPED_BASE which starts at

TASK_SIZE/3 (1 GIG), to hunt for a virtual address,keeping the upper limit as

TASK_SIZE.If the address is found,a vm_area_struct is created,and gets linked

with the tasks vma before the address is returned,with a call to

insert_vm_struct which also links the vma to the inode address spaces i_mmap or

i_mmap_shared lists,depending on whether VM_SHARED flag is set or not. Try

taking a look at mmap.c,which is quite a useful file, as far as vm_area

management is concerned. I hope by now,you would have visualised the mechanism

of do_munmap,which unmaps the virtual address from the processes virtual address

mapping. do_munmap,is a bit tricky in the sense that there are 4 cases to be

governed,which are elucidated in unmap_fixup.

  • Unmapping a whole vma
  • Unmapping from start of the vma to middle.
  • Unmapping from end to middle.
  • Unmapping intermediate positions thereby creating a HOLE.

The first case, doesnt have to do much other than calling

vm_ops->close,and cleaning up the slab cache entry for the vma.The second

case has to only readjust the vm_end,and the third readjust the vm_start and

vm_pgoff (page offset) fields. But the fourth case,has to bring up a new VMA

based on the ends being freed.So it results in an extra allocation of VMA. Check

out unmap_fixup which is well documented at the beginning,and is pretty simple

to follow. But bear in mind,that the call to unmap_fixup has been preceeded by a

remove_shared_vm_struct and {zap,flush}page_range calls.Hence the unmap_fixup

has to just set up a new VMA and insert the vm struct,if one of the ends get

changed, which happens in all the cases except the first. do_munmap,builds up a