LInux Kernel API to find the vma corresponds to a virtual address

三世轮回 提交于 2021-01-27 10:29:25

问题


Is there any Kernel API to find the VMA corresponds to virtual address?

Example : if a have an address 0x13000 i need some function like below

 struct vm_area_struct *vma =  vma_corresponds_to (0x13000,task);

回答1:


You're looking for find_vma in linux/mm.h.

/* Look up the first VMA which satisfies  addr < vm_end,  NULL if none. */
extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long addr);

This should do the trick:

struct vm_area_struct *vma = find_vma(task->mm, 0x13000);
if (vma == NULL)
    return -EFAULT;
if (0x13000 >= vma->vm_end)
    return -EFAULT;


来源:https://stackoverflow.com/questions/12388403/linux-kernel-api-to-find-the-vma-corresponds-to-a-virtual-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!