I have two console applications A1.exe A2.exe and one DLL. Both run in debug mode, optmization turned off. There is global const char* variable which I export from this dll and import back in A1 and A2:
//dll.h
extern "C" {DLLEXPORT extern const char* str;}
//dll.cpp
const char *str = "qwerty123";
I expect "qwerty123" to be created in read-only section of DLL and I expect that memory manager of Windows will map real memory with this string to some virtual memory address of A1.exe and different virtual address of A2.exe and do not create real copy of data. I expect that to happen also for all function definitions from that dll.
I run both applications at the same time and they both print correct strings imported from DLL. However I want some proof so I brutally use Cheat Engine to attach to A1.exe process and change that read-only string to some different value. Result is that A1.exe prints new value and A2.exe still prints old value. How to explain this? 1. I thought it is read-only memory and it will be shared to save real memory so why value changed only for one application? 2. How can I get proof that sections with program code (exported functions) are not duplicated for both processes?