1
0
mirror of https://github.com/solemnwarning/ipxwrapper synced 2024-12-30 16:45:37 +01:00

Don't do any cleanup in DllMain() during process termination.

Subtle crashes are fun. I found this to cause a deadlock, but only
after adding lots of extra debug logging to diagnose a DIFFERENT bug
and only when running it on a particular machine.

But once both of those criteria are met? It crashes pretty reliably.
This commit is contained in:
Daniel Collins 2017-06-18 02:47:51 +01:00
parent d65fb92480
commit 4cdca80c4b
3 changed files with 39 additions and 9 deletions

View File

@ -722,15 +722,25 @@ HRESULT WINAPI SPInit(LPSPINITDATA data) {
return DPERR_UNAVAILABLE;
}
BOOL WINAPI DllMain(HINSTANCE me, DWORD why, LPVOID res) {
if(why == DLL_PROCESS_ATTACH)
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
if(fdwReason == DLL_PROCESS_ATTACH)
{
log_open("ipxwrapper.log");
min_log_level = get_main_config().log_level;
}
else if(why == DLL_PROCESS_DETACH)
else if(fdwReason == DLL_PROCESS_DETACH)
{
/* When the "lpvReserved" parameter is non-NULL, the process is terminating rather
* than the DLL being unloaded dynamically and any threads will have been terminated
* at unknown points, meaning any global data may be in an inconsistent state and we
* cannot (safely) clean up. MSDN states we should do nothing.
*/
if(lpvReserved != NULL)
{
return TRUE;
}
unload_dlls();
log_close();
}

View File

@ -59,9 +59,9 @@ static void init_cs(CRITICAL_SECTION *cs)
}
}
BOOL WINAPI DllMain(HINSTANCE me, DWORD why, LPVOID res)
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
if(why == DLL_PROCESS_ATTACH)
if(fdwReason == DLL_PROCESS_ATTACH)
{
log_open("ipxwrapper.log");
@ -105,8 +105,18 @@ BOOL WINAPI DllMain(HINSTANCE me, DWORD why, LPVOID res)
router_init();
}
else if(why == DLL_PROCESS_DETACH)
else if(fdwReason == DLL_PROCESS_DETACH)
{
/* When the "lpvReserved" parameter is non-NULL, the process is terminating rather
* than the DLL being unloaded dynamically and any threads will have been terminated
* at unknown points, meaning any global data may be in an inconsistent state and we
* cannot (safely) clean up. MSDN states we should do nothing.
*/
if(lpvReserved != NULL)
{
return TRUE;
}
router_cleanup();
WSACleanup();

View File

@ -22,15 +22,25 @@
#include "common.h"
#include "config.h"
BOOL WINAPI DllMain(HINSTANCE me, DWORD why, LPVOID res) {
if(why == DLL_PROCESS_ATTACH)
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
if(fdwReason == DLL_PROCESS_ATTACH)
{
log_open("ipxwrapper.log");
min_log_level = get_main_config().log_level;
}
else if(why == DLL_PROCESS_DETACH)
else if(fdwReason == DLL_PROCESS_DETACH)
{
/* When the "lpvReserved" parameter is non-NULL, the process is terminating rather
* than the DLL being unloaded dynamically and any threads will have been terminated
* at unknown points, meaning any global data may be in an inconsistent state and we
* cannot (safely) clean up. MSDN states we should do nothing.
*/
if(lpvReserved != NULL)
{
return TRUE;
}
unload_dlls();
log_close();
}