This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] PR pch/39492 - MinGW memory mapping fix


Hello,


Below is the patch for GCC 4.3 branch. It fixes PR pch/39492 (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39492).

Tested on several Microsoft Window XP SP2 hosts, while it was patched against GCC 4.3.2 source and built on GNU/Linux using GCC 3.4.6 cross-toolchain.

One thing I don't like very much is "+ 10" in buffer size, but it's safe as the DWORD type is always a 32-bit unsigned int on MinGW. If there is a suitable constant/feature to use in GCC source it can be used there.

---
Andrey


2009-03-21  Andrey Galkin  <agalkin@hypercom.com>

        PR pch/39492
        * gcc/config/i386/host-mingw32.c: Changed to append current process ID
        to session-wide memory mapping object name to make it unique.

Index: gcc/config/i386/host-mingw32.c
===================================================================
--- gcc/config/i386/host-mingw32.c      (revision 144987)
+++ gcc/config/i386/host-mingw32.c      (working copy)
@@ -120,8 +120,19 @@
      namespace when running an application in a Terminal Server
      session.  This causes failure since, by default, applications
      don't get SeCreateGlobalPrivilege. We don't need global
-     memory sharing so explicitly put object into Local namespace.  */
-   const char object_name[] = "Local\\MinGWGCCPCH";
+     memory sharing so explicitly put object into Local namespace.
+
+     There is also another issue, which appears if multiple concurrent
+     GCC processes use PCH functionality. MapViewOfFileEx returns
+     "Access Denied" error. So we need to make the session-wide mapping
+     name unique. Let's use current process ID for that. */
+  const char object_name_prefix[] = "Local\\MinGWGCCPCH-";
+
+  /* Allocate enough space for name prefix and max possible DWORD decimal
+     representation */
+  char object_name[sizeof (object_name_prefix) + 10];
+  snprintf (object_name, sizeof(object_name), "%s%lu", object_name_prefix,
+            GetCurrentProcessId());

   /* However, the documentation for CreateFileMapping says that on NT4
      and earlier, backslashes are invalid in object name.  So, we need


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]