存档

‘Linux Kernel’ 分类的存档

linux下如何获取一段虚拟内存的所有物理地址?

2010年4月11日

也就是类似Windows CE的LockPages+Query那样的作用, 给定一段虚拟地址, 如何获得这段内存都对应到哪些物理地址上面?
linux下面对应的API是get_user_pages().
从这里看到的:
http://www.newsmth.net/bbscon.php?bid=299&id=50940&ftype=3&num=2048

使用get_user_pages()这个函数:
int get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
unsigned long start, int len, int write, int force,
struct page **pages, struct vm_area_struct **vmas)

这个函数的作用是根据用户空间start开始的len个页面,从页表中找到这些页面对应
的真正物理页面,保存在pages[]数组中返回。

其中主要的参数:
Start为用户空间内存的起始地址(页面对齐)
Len 为从start开始的页面的个数,注意单位为page
Write如果为1表示对这些页面具有写权限

zhangxuecheng Linux Kernel