From 3225fc5b602f25a2d17ee68b732ec2a59fb29c0f Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Thu, 19 Mar 2015 02:55:36 +0100
Subject: [PATCH] ntdll: Only enable wineserver shared memory communication
 when a special environment variable is set.

---
 dlls/ntdll/server.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/dlls/ntdll/server.c b/dlls/ntdll/server.c
index 749e753ae5a..c3f9d11c760 100644
--- a/dlls/ntdll/server.c
+++ b/dlls/ntdll/server.c
@@ -100,6 +100,7 @@
 #include "ddk/wdm.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(server);
+WINE_DECLARE_DEBUG_CHANNEL(winediag);
 
 /* just in case... */
 #undef EXT2_IOC_GETFLAGS
@@ -1177,6 +1178,21 @@ static int server_get_shared_memory_fd( HANDLE thread, int *unix_fd )
     return ret;
 }
 
+/* The shared memory wineserver communication is still highly experimental
+ * and might cause unexpected results when the client/server status gets
+ * out of synchronization. The feature will be disabled by default until it
+ * is tested a bit more. */
+static inline BOOL experimental_SHARED_MEMORY( void )
+{
+    static int enabled = -1;
+    if (enabled == -1)
+    {
+        const char *str = getenv( "STAGING_SHARED_MEMORY" );
+        enabled = str && (atoi(str) != 0);
+    }
+    return enabled;
+}
+
 
 /***********************************************************************
  *           server_get_shared_memory
@@ -1189,6 +1205,9 @@ void *server_get_shared_memory( HANDLE thread )
     void *mem = NULL;
     int fd = -1;
 
+    if (!experimental_SHARED_MEMORY())
+        return NULL;
+
     /* The global memory block is only requested once. No locking is
      * required because this function is called very early during the
      * process initialization for the first time. */
@@ -1203,7 +1222,10 @@ void *server_get_shared_memory( HANDLE thread )
     }
 
     if (!thread)
+    {
+        if (mem) WARN_(winediag)("Using shared memory wineserver communication\n");
         shmglobal = mem;
+    }
 
     return mem;
 }
-- 
2.26.2

