question about nopage sample code

Ali Aminian aminian.opensource at gmail.com
Wed Feb 22 08:31:38 EST 2017


in ldd3 no page is implemented as the code posted below (page 428).
can someone explain why should we subtract vma->vm_start?

struct page *simple_vma_nopage(struct vm_area_struct *vma,
                unsigned long address, int *type)
{
    struct page *pageptr;
    unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
    unsigned long physaddr = address - vma->vm_start + offset;  // why
should we subtract vma->vm_start ?
    unsigned long pageframe = physaddr >> PAGE_SHIFT;

    if (!pfn_valid(pageframe))
        return NOPAGE_SIGBUS;
    pageptr = pfn_to_page(pageframe);
    get_page(pageptr);
    if (type)
        *type = VM_FAULT_MINOR;
    return pageptr;

}

thank you
Ali Aminian.



More information about the Kernelnewbies mailing list