当我使用以下命令查看进程的内存映射时
cat/proc/pid/ map
有这样的条目:
40321000-40336000 r-xp 00000000 b3:15 875 /system/lib/libm.so
40336000-40337000 r--p 00014000 b3:15 875 /system/lib/libm.so
40337000-40338000 rw-p 00015000 b3:15 875 /system/lib/libm.so
40338000-40345000 r-xp 00000000 b3:15 789 /system/lib/libcutils.so
40345000-40346000 r--p 0000c000 b3:15 789 /system/lib/libcutils.so
40346000-40347000 rw-p 0000d000 b3:15 789 /system/lib/libcutils.so
40347000-40355000 rw-p 00000000 00:00 0
40355000-403bc000 r-xp 00000000 b3:15 877 /system/lib/libmedia.so
403bc000-403bd000 ---p 00000000 00:00 0
403bd000-403d0000 r--p 00067000 b3:15 877 /system/lib/libmedia.so
403d0000-403d1000 rw-p 0007a000 b3:15 877 /system/lib/libmedia.so
403d1000-403d5000 rw-p 00000000 00:00 0
403d5000-403d8000 rw-p 00000000 00:00 0
我理解 .so 代表进程映射的共享库。似乎每个 .so 都有 3 个条目,它们的权限是 r-xp r--p rw-p
那么我该如何解释呢?我可以假设 r-xp 是库的代码部分,因为它具有 x(执行)权限吗? r--p 和 rw-p 怎么样,它们是数据部分吗?
空条目怎么办?例如,关于 libmedia 的最后 6 个条目有三个空的整体 (00:00 0)。这些是什么?
403bc000-403bd000 ---p 00000000 00:00 0
403bd000-403d0000 r--p 00067000 b3:15 877 /system/lib/libmedia.so
403d0000-403d1000 rw-p 0007a000 b3:15 877 /system/lib/libmedia.so
403d1000-403d5000 rw-p 00000000 00:00 0
403d5000-403d8000 rw-p 00000000 00:00 0
最佳答案
Can I assume the r-xp is the code section of the library, since it has the x (execute) permission?
是的,但这被称为文本段(存储指令)。您还应该注意它没有写权限,因为它不应该有。
How about the r--p and rw-p, are they the data sections?
是的,这些段存储静态/全局变量。然而,常量全局变量将存储到 r--p 段中,因为它不应该被任何程序修改。
What about the empty entries? For example, the last 6 entries about libmedia have three empty entires (00:00 0). What are these? These might be the guard segment(kernel inserts these segments to protect the overflow scenario). The "p" indicates that its private.
编辑 有关完整信息,您可能需要引用以下链接:
关于linux - Linux 中共享库的内存映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22775570/