Environment:
Windows x64 bit with 5GB RAM. My binary is a 64bit one built with compiler of version - "Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x64"
Environment setting:
Microsoft suggests to set the below registry key to test 64 bit applications and I have set the same in my box. The problem doesn't occur if i don't set the below registry because the program is placed at a low address. The same registry key is mentioned in the discussion - As a programmer, what do I need to worry about when moving to 64-bit windows?
To force allocations to allocate from higher addresses before lower addresses for testing purposes, specify MEM_TOP_DOWN when calling VirtualAlloc or set the following registry value to 0x100000:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Memory Management\AllocationPreference
Sample code:
char *alloc_str()
{
char *temp;
temp = (char *) malloc(60);
/* copy some data to temp */
return temp;
}
main()
{
char *str;
str = (char *)alloc_str();
}
Analysis:
malloc
returns address 0x000007fffe999b40
which is stored in temp
but when the pointer is returned to main()
, str
gets only the second half - 0xfffffffffe999b40
and I am not able to access the data at that location.