简体   繁体   English

虚拟地址空间的较低保留部分

[英]Lower reserved portion of virtual address space

I have been studying x86-64 assembly and the memory layout of programs.我一直在研究 x86-64 汇编和程序的 memory 布局。

I have run into examples of the virtual address space of a program where the lower portion (0x00000000-0x00010000) is marked as reserved.我遇到了一个程序的虚拟地址空间示例,其中较低部分(0x00000000-0x00010000)被标记为保留。 But I cannot find an explanation for this.但我找不到对此的解释。

I have two questions我有两个问题

  1. Why is this portion reserved.为什么保留这部分。 Can I really not access this from my program?我真的不能从我的程序中访问它吗? This lower portion is counted as user space memory.这个较低的部分算作用户空间 memory。 So I don't understand why I would not be able to use it所以我不明白为什么我无法使用它
  2. What is this reserved portion used for?这个保留部分是做什么用的?

Can I really not access this from my program?我真的不能从我的程序中访问它吗?

In 32-bit mode, x86 CPUs can use "paging", in 64-bit mode (the operating systems of) x86 CPUs must use this feature.在 32 位模式下,x86 CPU可以使用“分页”,在 64 位模式下(操作系统)x86 CPU必须使用此功能。

Greatly simplified, "paging" is a feature of larger CPUs (devices like the "Arduino" don't have this feature) that allows telling the CPU which address in the hardware RAM is actually accessed by some address.大大简化,“分页”是较大 CPU 的一个功能(像“Arduino”这样的设备没有这个功能),它允许告诉 CPU 硬件 RAM 中的哪个地址实际上是由某个地址访问的。

Paging has been invented to handle the following situation:已经发明了分页来处理以下情况:

Let's say you write some application program (maybe a text editor) that stores some value at address 0x123456 and you run this program twice at the same time.假设您编写了一些应用程序(可能是文本编辑器),在地址 0x123456 处存储了一些值,并且您同时运行该程序两次。

In this case you will normally expect that one program does not overwrite the data stored by the other program although both programs store the data at address 0x123456.在这种情况下,您通常会期望一个程序不会覆盖另一个程序存储的数据,尽管两个程序都将数据存储在地址 0x123456 处。

Using "paging" the operating system tells the CPU that one program shall actually access some address (maybe 0x200456) in RAM hardware when accessing address 0x123456 and the other program shall access another address (maybe 0x300456) in RAM hardware when accessing address 0x123456, so the two programs don't overwrite the data of the other program although both programs use the same address (0x123456).操作系统使用“分页”告诉 CPU,一个程序在访问地址 0x123456 时实际上应该访问 RAM 硬件中的某个地址(可能是 0x200456),而另一个程序在访问地址 0x123456 时应该访问 RAM 硬件中的另一个地址(可能是 0x300456),所以尽管两个程序使用相同的地址(0x123456),但这两个程序不会覆盖另一个程序的数据。

The operating system may also tell the CPU that some memory area (for example 0-0x1000) is not used at all.操作系统也可能告诉 CPU 一些 memory 区域(例如 0-0x1000)根本没有使用。 This means that the CPU will not perform any memory access when trying to access that address but it "raises an exception" which means that the operating system is informed by calling some function in the operating system.这意味着 CPU 在尝试访问该地址时不会执行任何 memory 访问,但它“引发异常”,这意味着通过调用操作系统中的某些 function 来通知操作系统。

The operating system may then change the configuration of the "paging" and continue the program or stop the program and print some error message.然后操作系统可能会更改“分页”的配置并继续程序或停止程序并打印一些错误消息。

"Reserved" obviously means, that the operating system will stop the program with some error message. “保留”显然意味着操作系统将停止程序并显示一些错误消息。

What is this reserved portion used for?这个保留部分是做什么用的?

I think that "reserved" here just means: "Not used" and not: "Reserved for future use".我认为这里的“保留”只是意味着:“未使用”而不是:“保留以备将来使用”。

Why is this portion reserved.为什么保留这部分。 ... ...

As user "fuz" already suggested in his comment, in most modern programming languages the address zero is used to specify that an argument is not specified.正如用户“fuz”在他的评论中已经建议的那样,在大多数现代编程语言中,地址零用于指定未指定参数。

Some example:一些例子:

This function returns the length of some file if a file name is specified.如果指定了文件名,则此 function 返回某个文件的长度。 If no file name is specified, the length of the last file opened is returned.如果没有指定文件名,则返回最后打开的文件的长度。 The register rcx shall be the address where the file name is stored;寄存器rcx应该是文件名存放的地址; if the register rcx is zero, this means that no file name is specified.如果寄存器rcx为零,这意味着没有指定文件名。

In this example, you would have a problem if the name of the file you are interested in is stored at address zero.在此示例中,如果您感兴趣的文件名存储在地址 0 处,您将遇到问题。

For this reason many operating systems do not use the "low" memory area (starting at 0) so it is guaranteed that the address "zero" does not specify any valid data.由于这个原因,许多操作系统不使用“低”memory 区域(从 0 开始),因此可以保证地址“零”不指定任何有效数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM