为什么我可以在/ proc / pid / maps输出中看到几个相同的段? [英] Why I can see the several same segments in the /proc/pid/maps output?

查看:170
本文介绍了为什么我可以在/ proc / pid / maps输出中看到几个相同的段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

测试是在32位Linux上

Test is on the 32 bit Linux

代码如下:

int foo(int a, int b)
{
    int c = a + b;
    return c;
}

int main()
{
    int e = 0;
    int d = foo(1, 2);
    printf("%d\n", d);
    scanf("%d", &e);

    return 0;
}

当我使用cat / proc / pid / maps查看内存布局时,似乎我可以看到我的代码和库中有三个
text 段。

and when I use cat /proc/pid/maps to see the memory layout, it seems that I can see three text segment for my code and the library.

ubuntu% cat /proc/2191/maps
08048000-08049000 r-xp 00000000 08:01 1467306    /home/shuai/work/asm/test1
08049000-0804a000 r--p 00000000 08:01 1467306    /home/shuai/work/asm/test1
0804a000-0804b000 rw-p 00001000 08:01 1467306    /home/shuai/work/asm/test1
09137000-09158000 rw-p 00000000 00:00 0          [heap]
b75c6000-b75c7000 rw-p 00000000 00:00 0
b75c7000-b776b000 r-xp 00000000 08:01 3149924    /lib/i386-linux-gnu/libc-2.15.so
b776b000-b776d000 r--p 001a4000 08:01 3149924    /lib/i386-linux-gnu/libc-2.15.so
b776d000-b776e000 rw-p 001a6000 08:01 3149924    /lib/i386-linux-gnu/libc-2.15.so
b776e000-b7771000 rw-p 00000000 00:00 0
b7780000-b7784000 rw-p 00000000 00:00 0
b7784000-b7785000 r-xp 00000000 00:00 0          [vdso]
b7785000-b77a5000 r-xp 00000000 08:01 3149914    /lib/i386-linux-gnu/ld-2.15.so
b77a5000-b77a6000 r--p 0001f000 08:01 3149914    /lib/i386-linux-gnu/ld-2.15.so
b77a6000-b77a7000 rw-p 00020000 08:01 3149914    /lib/i386-linux-gnu/ld-2.15.so
bfd47000-bfd68000 rw-p 00000000 00:00 0          [stack]

有人可以给我一些关于这个问题的指南吗?非常感谢!

Could any one give me some guide about this issue? Thank you a lot!

推荐答案

请注意第3列(起始偏移)和2(权限)中的值。实际上你有相同的部分映射两次,在你的二进制文件的第1行和第2行,但是,在第3行,它是不同的。允许多次分别映射同一个文件;不同的系统可以跳过将其合并到一个VM映射条目中,因此它可以反映映射历史记录而不是当前状态jist。

Please mind the values in columns 3 (starting offset) and 2 (permissions). Really you have the same part mapped twice, in lines 1 and 2 for your binary file, but, in line 3, it's different. It's permitted to map the same file separately multiple times; different systems could skip merging this into one VM map entry, so it could reflect mapping history but not the current state jist.

如果您看到库映射,您可以轻松找到任何库分别映射的法则:

If you see at library mappings you could easily find the law that any library is mapped separately:


  • 具有读取和执行权限:不应更改的主要代码。

  • 具有读取权限:不允许代码的常量数据区。

  • 具有读写权限:它结合了非常量数据区和重定位表共享对象。

具有相同的起始4K二进制文件区域映射两次可以使用RTLD逻辑来解释,该逻辑与任意库逻辑到期不同引导需求。我并不认为它如此重要,因此它可能很容易因平台细节而异。

Having the same starting 4K binary file area mapped twice could be explained with RTLD logic which differs from an arbitrary library logic due to bootstrapping needs. I don't treat it so important, more so it could easily differ on platform specifics.

这篇关于为什么我可以在/ proc / pid / maps输出中看到几个相同的段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆