Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reserve bottom 4GB VM in an x64 C++ app

Working on porting a 32bit Windows C++ app to 64 bit. Unfortunately, the code uses frequent casting in both directions between DWORD and pointer values.

One of the ideas is to reserve the first 4GB of virtual process space as early as possible during process startup so that all subsequent calls to reserve memory will be from virtual addresses greater than 4 GB. This would cause an access violation error any unsafe cast from pointer to DWORD and then back to pointer and would help catch errors early.

When I look at the memory map of a very simple one line C++ program, there are many libraries loaded within bottom 4GB? Is there a way to make sure that all libraries, etc get loaded only above 4GB?

Thanks

like image 537
CeeMan Avatar asked Dec 08 '22 06:12

CeeMan


1 Answers

Compile your project with /Wp64 switch (Detect 64-bit Portability Issues) and fix all warnings.

like image 61
Paul Avatar answered Dec 23 '22 12:12

Paul