mmap系统调用在内核的入口是sys_mmap_pgoff,主要实现在do_mmap_pgoff函数里。 sys_mmap_pgoff的调用关系如下:
sys_mmap_pgoff->do_mmap_pgoff ->get_unmapped_area
->mmap_region
SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
unsigned long, prot, unsigned long, flags,
unsigned long, fd, unsigned long, pgoff)
{
down_write(¤t->mm->mmap_sem);
retval = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
up_write(¤t->mm->mmap_sem);
}
do_mmap_pgoff函数有两个关键点:
一个是get_unmapped_area函数
一个是mmap_region函数
unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
unsigned long len, unsigned long prot,
unsigned long flags, unsigned long pgoff)
{
....
/* Obtain the address to map to. we verify (or select) it and ensure
* that it represents a valid section of the address space.
*/
addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
if (addr & ~PAGE_MASK)
return addr;
.....
return mmap_region(file, addr, len, flags, vm_flags, pgoff);
}
阅读(1129) | 评论(0) | 转发(0) |