summaryrefslogtreecommitdiff
path: root/user/wine/dlclose.patch
blob: a9844ff687325a766aabf0d5eb55a57bbb74f412 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
--- 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");