How to tell if we are really using 48, 56 or 64 bit pointers

I use tricks for storing additional information in pointers. At the moment, some of the bits are not used in pointers (the highest 16 bits), but this will change in the future. I would like to have a way to detect if we are compiling or working on a platform that will use more than 48 bits for pointers.

related stuff: Why can't OS use whole 64-bit addresses for addressing? Why only 48 bits? http://developer.amd.com/wordpress/media/2012/10/24593_APM_v2.pdf

The solution is needed for x86-64, Windows, C / C ++, preferably something that can be compiled. Solutions for other platforms are also of interest, but will not be flagged as the correct answer.

+3


source to share


1 answer


Windows has exactly one switch for 32-bit and 64-bit programs to define the top of its virtual address space :

IMAGE_FILE_LARGE_ADDRESS_AWARE

      

For both types, the exclusion limits the program to the bottom 2 GB of address space, greatly reducing the amount of memory the application can display, and therefore also reduces the effectiveness of address-space-layout randomization (ASLR, an attack prevention mechanism).

However, there is one drawback, and exactly what you think you want: only the lower 31 bits of the pointer can be set, so pointers can be safely rounded with int

(32-bit integer, or null expansion).




At runtime, the situation is slightly better:

Just use the cpuid

-instruction from intel, function EAX = 80000008H and read the maximum number of usable address bits for virtual addresses from bits 8-15.

The OS cannot use more than the processor supports, remember that Intel insists on canonical addresses (extended sign).

See here how to use cpuid

from C ++: CPUID implementations in C ++

+4


source







All Articles