diff --git a/include/process.h b/include/process.h index 55b11ed0b86..b7486dc4735 100644 --- a/include/process.h +++ b/include/process.h @@ -57,7 +57,7 @@ typedef struct _PDB WORD module; /* 2a IMTE for the process module */ WORD threads; /* 2c Number of threads */ WORD running_threads; /* 2e Number of running threads */ - WORD unknown3; /* 30 Unknown */ + WORD free_lib_count; /* 30 Recursion depth of FreeLibrary calls */ WORD ring0_threads; /* 32 Number of ring 0 threads */ HANDLE system_heap; /* 34 System heap to allocate handles */ HTASK task; /* 38 Win16 task */ @@ -96,6 +96,7 @@ typedef struct _PDB } PDB; /* Process flags */ +#define PDB32_DEBUGGED 0x0001 /* Process is being debugged */ #define PDB32_WIN16_PROC 0x0008 /* Win16 process */ #define PDB32_DOS_PROC 0x0010 /* Dos process */ #define PDB32_CONSOLE_PROC 0x0020 /* Console process */ diff --git a/loader/module.c b/loader/module.c index 4ea51e0b4f9..618ec5eb433 100644 --- a/loader/module.c +++ b/loader/module.c @@ -1529,17 +1529,19 @@ static void MODULE_FlushModrefs(void) */ BOOL WINAPI FreeLibrary(HINSTANCE hLibModule) { - BOOL retv = TRUE; + BOOL retv = FALSE; WINE_MODREF *wm; EnterCriticalSection( &PROCESS_Current()->crit_section ); + PROCESS_Current()->free_lib_count++; wm = MODULE32_LookupHMODULE( hLibModule ); - if ( !wm ) + if ( !wm || !hLibModule ) SetLastError( ERROR_INVALID_HANDLE ); else retv = MODULE_FreeLibrary( wm ); + PROCESS_Current()->free_lib_count--; LeaveCriticalSection( &PROCESS_Current()->crit_section ); return retv; @@ -1588,13 +1590,14 @@ BOOL MODULE_FreeLibrary( WINE_MODREF *wm ) MODULE_DecRefCount( wm ); /* Call process detach notifications */ - MODULE_DllProcessDetach( FALSE, NULL ); + if ( PROCESS_Current()->free_lib_count <= 1 ) + MODULE_DllProcessDetach( FALSE, NULL ); MODULE_FlushModrefs(); TRACE_(module)("(%s) - END\n", wm->modname ); - return FALSE; + return TRUE; }