Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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);
like image 825
Abhilash V R Avatar asked Sep 12 '12 12:09

Abhilash V R


2 Answers

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;
like image 117
jleahy Avatar answered Oct 03 '22 18:10

jleahy


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;
like image 36
jedix Avatar answered Oct 03 '22 18:10

jedix