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);
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;
Since v5.14-rc1, there is a new API in linux/mm.h
called vma_lookup()
The code can now be reduced to the following:
struct vm_area_struct *vma = vma_lookup(task->mm, 0x13000);
if (!vma)
return -EFAULT;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With