虚拟地址
假设我正在启动同一程序的两个实例。两个程序的文本区域是否具有相同的虚拟地址?
Suppose I'm starting two instances of the same program. Will the text region of both programs have same virtual addresses?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
视情况而定。在大多数系统上,如果您在相同的环境(相同的参数等)中运行相同的程序两次,您将发现相同的地址映射。这只是因为进程所做的大部分操作都是确定性的,仅取决于环境、命令行参数、读取的文件内容,而不取决于日期或进程 ID 等数据的更改。这在调试时非常有用:如果重新启动程序,有时即使在进行小的代码更改和重新编译之后,内存布局也有可能保持不变。当然,并发运行的程序的不同实例可能具有相同的虚拟地址,但它们不会具有相同的物理地址。
某些系统(例如 OpenBSD 或具有各种强化设置的 Linux)实现地址空间布局随机化 (ASLR)。 ASLR意味着每次进程启动时,其代码、数据、堆栈和堆的虚拟地址都是随机确定的。这是一项安全功能,旨在使安全漏洞的利用更加困难:利用代码不能只访问已知地址的已知代码。然而,随着 ASLR 变得越来越流行,解决它的漏洞也变得更加复杂。 ASLR 仍然很有用,因为它增加了漏洞编写者的工作量,而不会增加很多复杂性。
Depends. On most systems, if you run the same program twice in the same environment (same parameters, etc.), you'll find the same address mapping. This is simply because most of what the process does is deterministic, dependent only on the environment, command-line parameters, contents of files read, but not on changing data such as the date or process ID. This is very useful when debugging: if you restart your program, sometimes even after a small code change and recompilation, you have a chance that the memory layout remained the same. Of course, different instances of the program running concurrently may have the same virtual addresses, but they won't have the same physical addresses.
Some systems, such as OpenBSD, or Linux with various hardening settings, implement address space layout randomization (ASLR). ASLR means that each time a process starts, the virtual addresses of its code, data, stack(s) and heap(s) are determined at random. This is a security features, designed to make exploits of security vulnerabilities harder: the exploit code can't just access known code at known addresses. However, as ASLR becomes more popular, exploits also become more sophisticated to work around it. ASLR remains useful because it increases the workload for the exploit writer without adding a lot of complexity.
可能不会,但他们有可能可以。每个进程都有自己独立的内存空间。
Probably not, but it's possible that they could. Each process has its own independent memory space.