linux内核中带有vm_insert_page()的mmap

linux内核中带有vm_insert_page()的mmap,linux,linux-kernel,Linux,Linux Kernel,我试图理解mmap()功能,它可以逐页映射到用户空间地址。我使用vm_insert_page()映射这些页面。返回时没有任何错误。但是当从用户空间尝试写入映射内存时,我得到了空指针解引用。我把代码贴在下面。系统为x86,32位系统 将发布mmap()和fault()函数 static int mmap(struct file *filp , struct vm_area_struct *vma) { vma->vm_ops = &vm_ops; vm

我试图理解mmap()功能,它可以逐页映射到用户空间地址。我使用vm_insert_page()映射这些页面。返回时没有任何错误。但是当从用户空间尝试写入映射内存时,我得到了空指针解引用。我把代码贴在下面。系统为x86,32位系统

将发布mmap()和fault()函数

static int mmap(struct file *filp , struct vm_area_struct *vma)
{
        vma->vm_ops = &vm_ops;
        vma->vm_flags |= VM_MIXEDMAP;
        vm_open(vma);
        return 0;
}


static int vm_fault(struct vm_area_struct *vma,struct vm_fault *vmf)
{
        struct page *page=NULL;
        page = alloc_page(GFP_HIGHUSER);//Both the alloc_pages() are working fine.
        if(!page)
        {
                printk("The allocation of pagee memory is failed\n");
                return -VM_FAULT_OOM;
        }

//        get_page(page);
        if(vm_insert_page(vma,vmf->virtual_address,(page)))
                printk("Thepage table creation is failed\n");
        printk("The vm_insert of page is done\n");
        return 0;
}
提前谢谢