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.
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.PS. Other answers seems make a confusion on language level pointer and physical address.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With