Access Violation in DllMain of coherence.dll
882397Aug 15 2011 — edited Nov 18 2011I have an issue with C++ project, that using coherence (version 3.7). During loading the exe file dialog box is shown with the message: "The application failed to initialize properly (0xc0000005)". After clicking "OK" the process terminates.
Running under debugger I discovered the error place:
The error: 0xC0000005: Access violation writing location 0x00000010.
The call stack:
-----
ntdll.dll!_RtlpWaitForCriticalSection@4() + 0x5b bytes
ntdll.dll!_RtlEnterCriticalSection@4() + 0x46 bytes
iphlpapi.dll!76d626fd()
[Frames below may be incorrect and/or missing, no symbols loaded for iphlpapi.dll]
iphlpapi.dll!76d6605b()
dnsapi.dll!_IpHelp_GetAdaptersInfo@4() + 0x32 bytes
dnsapi.dll!_NetInfo_Build@4() + 0x2c bytes
dnsapi.dll!_NetInfo_Get@8() + 0x28 bytes
dnsapi.dll!_GetDnsServerRRSet@8() + 0x36 bytes
dnsapi.dll!_DnsQuery_W@24() + 0xa8 bytes
mswsock.dll!_myhostent_W@0() + 0xf8 bytes
mswsock.dll!_RNRPROV_NSPStartup@8() + 0x47 bytes
mswsock.dll!_NSPStartup@8() + 0x20dc bytes
ws2_32.dll!NSPROVIDER::Initialize() + 0xa7 bytes
ws2_32.dll!NSCATALOG::LoadProvider() + 0x4a bytes
ws2_32.dll!LookupBeginEnumerationProc() + 0x154e bytes
ws2_32.dll!DCATALOG::EnumerateCatalogItems() + 0x25 bytes
ws2_32.dll!NSQUERY::LookupServiceBegin() + 0x98 bytes
ws2_32.dll!_WSALookupServiceBeginW@12() + 0x84 bytes
ws2_32.dll!_WSALookupServiceBeginA@12() + 0x6f bytes
ws2_32.dll!getxyDataEnt() + 0x5d bytes
ws2_32.dll!_gethostname@8() + 0xa7 bytes
coherence.dll!coherence::native::NativeInetHelper::getLocalHostName() Line 250 + 0x43 bytes C++
coherence.dll!coherence::net::InetAddress::getLocalHost() Line 84 + 0x10 bytes C++
coherence.dll!coherence::util::`anonymous namespace'::InetAddressInfo::InetAddressInfo() Line 56 + 0xd bytes C++
coherence.dll!coherence::lang::factory<coherence::util::`anonymous namespace'::InetAddressInfo>::create() Line 389 + 0x44 bytes C++
coherence.dll!coherence::lang::class_spec<coherence::util::`anonymous namespace'::InetAddressInfo,coherence::lang::extends<coherence::lang::Object,void>,coherence::lang::implements<void,void,void,void,void,void,void,void,void,void,void,void,void,void,void,void> >::create() Line 143 + 0x12 bytes C++
coherence.dll!coherence::util::`anonymous namespace'::getInetAddressInfo() Line 252 + 0x2a bytes C++
coherence.dll!coherence::util::`anonymous namespace'::`dynamic initializer for 'coh_static_init_func255''() Line 255 + 0xf bytes C++
msvcr80.dll!78131742()
coherence.dll!_CRT_INIT(void * hDllHandle=0x00440000, unsigned long dwReason=0, void * lpreserved=0x0012fd30) Line 316 + 0xf bytes C
coherence.dll!__DllMainCRTStartup(void * hDllHandle=0x00440000, unsigned long dwReason=0, void * lpreserved=0x00000000) Line 492 + 0x8 bytes C
coherence.dll!_DllMainCRTStartup(void * hDllHandle=0x00440000, unsigned long dwReason=1, void * lpreserved=0x0012fd30) Line 462 + 0x11 bytes C
ntdll.dll!_LdrpCallInitRoutine@16() + 0x14 bytes
ntdll.dll!_LdrpRunInitializeRoutines@4() + 0x205 bytes
ntdll.dll!_LdrpInitializeProcess@20() - 0x96d bytes
ntdll.dll!__LdrpInitialize@12() + 0x6269 bytes
ntdll.dll!_KiUserApcDispatcher@20() + 0x7 bytes
-----
According to [http://msdn.microsoft.com/en-us/library/ms682583(v=vs.85).aspx] :
-----
The entry-point function should perform only simple initialization or termination tasks. It must not call the LoadLibrary or LoadLibraryEx function (or a function that calls these functions), because this may create dependency loops in the DLL load order. This can result in a DLL being used before the system has executed its initialization code. Similarly, the entry-point function must not call the FreeLibrary function (or a function that calls FreeLibrary) during process termination, because this can result in a DLL being used after the system has executed its termination code.
Because Kernel32.dll is guaranteed to be loaded in the process address space when the entry-point function is called, calling functions in Kernel32.dll does not result in the DLL being used before its initialization code has been executed. Therefore, the entry-point function can call functions in Kernel32.dll that do not load other DLLs. For example, DllMain can create synchronization objects such as critical sections and mutexes, and use TLS. Unfortunately, there is not a comprehensive list of safe functions in Kernel32.dll.
Windows 2000: Do not create a named synchronization object in DllMain because the system will then load an additional DLL.
Calling functions that require DLLs other than Kernel32.dll may result in problems that are difficult to diagnose. For example, calling User, Shell, and COM functions can cause access violation errors, because some functions load other system components. Conversely, calling functions such as these during termination can cause access violation errors because the corresponding component may already have been unloaded or uninitialized.
-----
Perhaps the coherence developers should define init/cleanup functions (i.e. coherence_init(), coherence_cleanup()) and perform all initialization/cleanup actions there.