Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 812
xmllmx Avatar asked Nov 04 '14 13:11

xmllmx


2 Answers

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.

like image 128
Non-maskable Interrupt Avatar answered Oct 05 '22 12:10

Non-maskable Interrupt


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

Yes you can, as long as there's addressable memory there. On most platforms, there won't be.

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

You can access any physical address if it's mapped into virtual memory. If there's anything sensitive there, then the OS probably won't allow that in user code. Within the kernel, it's just a case of setting up the page tables to include that address.

like image 42
Mike Seymour Avatar answered Oct 05 '22 13:10

Mike Seymour