|
Hello, All!
We made analysis and found the problem reason:
The problem happen because cryptoopp is trying to allocate memory using
debug
version of runtime library, but the last one is still not
initialized. This is because cryptopp
using hack during initialization process, by searching for debug CRT (C Runtime) in process address space and if found getting addresses of global new/delete operators (if debug CRT not found cryptoPP is getting addresses from release one) for future memory allocation. Then after address of new and delete operators were resolved they are used during global variable initialization. So we
have follwing
situation:
1. debug.exe starting 2. OS is loading all DLLs dependance tree debug.exe depends on. 3. releaseCryptoPP is loading and resolving addresses of new/delete from debugCRT (releaseCRT already initialized, but debug one not) 4. cryptoPP using resolved addresses to allocate memory 5. we have access violation 6. here debugCRT will only initialize Note: debugCRT *should* be initialized before its first usage in application, so compiler absolutely sure that debugCRT is still not used, but cryptoPP is cheating by resolving addresses manually. If there would be at least one debugDLL loaded before cryptoPP then debugCRT would be initialized already... ================================ One more analysis (the same):
The reason of the problem:
- the msvcrtd.dll is not initialized in CryptoPP, but loaded on CryptoPP initialization when new operator is called from msvcrtd.dll at this moment - this (loaded, but not initialized msvcrtd.dll) happens on some conditions - depends on the order of dll initialization, that is why problem is not easy to reproduce - the new is called, but because msvcrtd.dll is not initialized it tries to read some non-initialized memory ================================
compiler options for application:
/nologo /MDd /W3 /GR /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_AFXDLL" /FR"debug/" /Fp"debug/Messanger.pch" /Yu"stdafx.h" /Fo"debug/" /Fd"debug/" /FD /GZ /Zm200 /c here is the stack:
NTDLL! 77f92373() NTDLL! 77f922f8() _nh_malloc_dbg(unsigned int 56, int 1, int 1, const char * 0x00000000, int 0) line 242 + 7 bytes _nh_malloc(unsigned int 56, int 1) line 197 + 19 bytes operator new(unsigned int 56) line 24 + 11 bytes CRYPTOPP! 4292a519() CRYPTOPP! 429492cc() NTDLL! 77f86215() NTDLL! 77f86f17() NTDLL! 77f8b845() NTDLL! 77f8c295() NTDLL! 77fa15d3() We work around the problem by:
- removed from CryptoPP new and delete finding mechanism
and linked all our
applications and dlls to release run-time library (even debug
configuration).
Best Regards,
Voronkov Konstantin
|
- linking release cryptoPP dll to debug application resu... Voronkov Konstantin
- Voronkov Konstantin
