xmllmx xmllmx - 6 months ago 31
C Question

Is it possible to access physical address 0?

In C/C++, it is not allowed to access data at address 0.

However, the physical memory are numbered from 0. And, in DOS era, the interrupt vector table was located at physical address 0. The first interrupt vector was the handler of the division-by-zero exception.

My question is:

Under what cases is it allowed to access physical address 0?


To access physical address zero, it depends on which platform you are talking. The language has no idea on the underlying addressing model, it depends on the OS.

  • On bare metal environment, you have total control on the page table if paging is enabled, or just de-reference zero if paging is not enabled.
  • On some Unix and Linux variation, you do mmap and perhaps also open /dev/mem to get a non-null pointer with logical address non-zero but physical address zero, it may require some access rights.
  • I'm not sure on Windows.

PS. Other answers seems make a confusion on language level pointer and physical address.