gpt4 book ai didi

c - 遍历进程的 `vm_area_struct`

转载 作者:行者123 更新时间:2023-11-30 17:13:44 25 4
gpt4 key购买 nike

作为 Traversing all the physical pages of a process 答案的扩展和数据在这里http://www.makelinux.net/ldd3/chp-15-sect-1 ,我有一个小问题。在第一个答案中建议遍历进程的物理页面,

struct vm_area_struct *vma = 0;
unsigned long vpage;
if (task->mm && task->mm->mmap)
for (vma = task->mm->mmap; vma; vma = vma->vm_next)
for (vpage = vma->vm_start; vpage < vma->vm_end; vpage += PAGE_SIZE)
unsigned long phys = virt2phys(task->mm, vpage);

并引用标题“15.1.6.虚拟内存区域”下的第二个链接中给出的示例,即

# cat /proc/1/maps     look at init
08048000-0804e000 r-xp 00000000 03:01 64652 /sbin/init text
0804e000-0804f000 rw-p 00006000 03:01 64652 /sbin/init data
0804f000-08053000 rwxp 00000000 00:00 0 zero-mapped BSS
40000000-40015000 r-xp 00000000 03:01 96278 /lib/ld-2.3.2.so text
40015000-40016000 rw-p 00014000 03:01 96278 /lib/ld-2.3.2.so data

现在我的问题是,当我遍历时,第一个区域的 vm_startvm_end 的值将是 080480000804e000 ,或者是 0804800008053000(一 block 连续的内存)。我可能应该编写一个程序并自己尝试一下,但我正在将这些数据用于另一个项目,如果有人可以帮助理解这一点,那将非常有帮助。我基本上想知道,如果

08048000-0804e000 r-xp 00000000 03:01 64652      /sbin/init   text
0804e000-0804f000 rw-p 00006000 03:01 64652 /sbin/init data
0804f000-08053000 rwxp 00000000 00:00 0 zero-mapped BSS

是属于进程的一个“模块”,它是否有一个或多个vm_area_struct数据结构。

谢谢。

最佳答案

每个 map 部分都有一个单独的vm_area_struct。如果您查看 fs/proc/task_mmu.c 中的代码、函数 m_start()m_next,您会看到以下行maps 伪文件中的内容是通过迭代遍历进程 vma 列表来创建的。另外,请注意 struct vm_area_struct 声明的注释:

/*
* This struct defines a memory VMM memory area. There is one of these
* per VM-area/task. A VM area is any part of the process virtual memory
* space that has a special rule for the page-fault handlers (ie a shared
* library, the executable area etc).
*/

显然,文本、数据和 BSS 部分具有不同的页错误处理规则:文本根本无法写入。数据在首次访问时读取,然后在写入时复制。 BSS 首次访问归零。

关于c - 遍历进程的 `vm_area_struct`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30604506/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com