--- a/configure.ac +++ b/configure.ac @@ -1123,6 +1123,12 @@ then dnl *** End of X11/Xlib.h check + dnl Check for the unload_after_dlclose libc + AC_RUN_IFELSE( + [AC_LANG_PROGRAM([[#include <dlfcn.h>]], [[dlclose(dlopen("./conftest", 0)); return 0;]])], + ac_save_CPPFLAGS="$ac_save_CPPFLAGS -DNO_UNLOAD_AFTER_DLCLOSE", + []) + dnl Check for the presence of OpenGL opengl_msg="" if test "x$with_opengl" != "xno" --- a/dlls/ntdll/loader.c +++ b/dlls/ntdll/loader.c @@ -2289,6 +2289,13 @@ if (mod->Flags & LDR_WINE_INTERNAL && mod->SectionHandle == handle) { info.wm = CONTAINING_RECORD(mod, WINE_MODREF, ldr); +#ifdef NO_UNLOAD_AFTER_DLCLOSE + if (info.wm->ldr.LoadCount == 0) { + RtlEnterCriticalSection( &loader_section ); + info.wm->ldr.LoadCount = 1; + RtlLeaveCriticalSection( &loader_section ); + } +#endif TRACE( "Found %s at %p for builtin %s\n", debugstr_w(info.wm->ldr.FullDllName.Buffer), info.wm->ldr.BaseAddress, debugstr_w(path) ); break; @@ -3199,6 +3199,9 @@ * LdrShutdownProcess (NTDLL.@) * */ +#ifdef NO_UNLOAD_AFTER_DLCLOSE +static void MODULE_FlushModrefs(void); +#endif void WINAPI LdrShutdownProcess(void) { TRACE("()\n"); @@ -3194,6 +3203,12 @@ TRACE("()\n"); +#ifdef NO_UNLOAD_AFTER_DLCLOSE + RtlEnterCriticalSection( &loader_section ); + process_detach(); + MODULE_FlushModrefs(); + RtlLeaveCriticalSection( &loader_section ); +#endif process_detaching = TRUE; process_detach(); } @@ -3384,7 +3398,11 @@ if ( free_lib_count <= 1 ) { +#ifdef NO_UNLOAD_AFTER_DLCLOSE + TRACE("apply no-op dlclose hacks on this platform\n"); +#else process_detach(); MODULE_FlushModrefs(); +#endif } TRACE("END\n");