Connecting the mmap user call to the mmap kernel call

I am trying to understand how mmap works. The user level call mmap is as follows.

void *mmap(void *addr, size_t len, int prot, int flags,
       int fildes, off_t off); 

but the mmap level for a specific device driver is as follows:

int <device_name>_mmap(struct file*fp, struct vm_area_struct *vma)

I also looked at the source code, but I can not find the connection between them.

How does mmap for a particular device get its arguments "struct vm_area_struct * vma"? Could you help me figure this out? Appreciate your help.

+5
source share
1 answer

The library call mmap()is implemented by libc, which converts the offset in bytes into the offset on the pages, and then calls the system call mmap_pgoff().

mmap_pgoff() struct file *, , do_mmap_pgoff().

do_mmap_pgoff() , , VM . mmap_region().

mmap_region() , , struct vm_area_struct, ( , , VM ). ->mmap(), struct file * struct vm_area_struct *. mmap .

+12

All Articles