【问题标题】:Traversing `vm_area_struct`'s of a process遍历进程的`vm_area_struct`
【发布时间】:2015-08-16 17:49:48
【问题描述】:

作为对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. Virtual Memory Areas”下第二个链接中给出的示例,即

# 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(一个连续的块内存)。我可能应该编写一个程序并自己尝试,但我正在将这些数据用于另一个项目,如果有人能帮助理解这一点,那将非常有帮助。我基本上想知道,如果

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数据结构。

谢谢。

【问题讨论】:

    标签: c linux linux-kernel filesystems mmap


    【解决方案1】:

    每个地图部分都有一个单独的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 在首次访问时归零。

    【讨论】:

    • 所以您是说每个模块(例如,如果我将一个模块视为具有多个部分的 elf 可执行文件)将具有多个 vm_area_struct 数据结构。 ?
    猜你喜欢
    • 1970-01-01
    • 2011-09-22
    • 1970-01-01
    • 2011-05-12
    • 1970-01-01
    • 2014-01-19
    • 2013-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多