Lower reserved portion of virtual address space

0

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?
assembly
x86-64
virtual-address-space
asked on Stack Overflow Jan 6, 2021 by TPens

1 Answer

0

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.

answered on Stack Overflow Jan 6, 2021 by Martin Rosenau

User contributions licensed under CC BY-SA 3.0