Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
215 views
in Technique[技术] by (71.8m points)

assembly - Lower reserved portion of virtual address space

I have been studying x86-64 assembly and the memory layout of programs.

I have run into examples of the virtual address space of a program where the lower portion (0x00000000-0x00010000) is marked as reserved. 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. So I don't understand why I would not be able to use it
  2. What is this reserved portion used for?

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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.

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.

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.

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).

The operating system may also tell the CPU that some memory area (for example 0-0x1000) is not used at all. 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.

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.

Some example:

This function returns the length of some file if a file name is specified. 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; if the register rcx is zero, this means that no file name is specified.

In this example, you would have a problem if the name of the file you are interested in is stored at address zero.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...