PR/other 30335
authorChristoph von Wittich <Christoph_vW@reactos.org>
Wed, 18 Jul 2007 11:39:01 +0000 (11:39 +0000)
committerDanny Smith <dannysmith@gcc.gnu.org>
Wed, 18 Jul 2007 11:39:01 +0000 (11:39 +0000)
2007-07-19  Christoph von Wittich  <Christoph_vW@reactos.org>
    Danny Smith  <dannysmith@users.sourceforge.net>

PR/other 30335
* config/i386/host-mingw32.c (mingw32_gt_pch_use_address): Put
file mapping object in local namespace if Windows version later
than NT4

Co-Authored-By: Danny Smith <dannysmith@users.sourceforge.net>
From-SVN: r126719

gcc/ChangeLog
gcc/config/i386/host-mingw32.c

index 6ef674d9ecd95a7f0493927a53b98a2b7151b8c7..e39ccd6a5796e2967f7dda24b4c4ef21968326d3 100644 (file)
@@ -1,3 +1,11 @@
+2007-07-19  Christoph von Wittich  <Christoph_vW@reactos.org>
+           Danny Smith  <dannysmith@users.sourceforge.net>
+
+       PR/other 30335
+       * config/i386/host-mingw32.c (mingw32_gt_pch_use_address): Put
+       file mapping object in local namespace if Windows version later
+       than NT4
+
 2007-07-18  Richard Sandiford  <richard@codesourcery.com>
 
        * config/arm/arm-protos.h (arm_cannot_force_const_mem): Declare.
index a341e27c084ab7f9603c4cd00026432ef974d094..fbd866a8f8b6541023602f7f181e6eb433085a51 100644 (file)
@@ -1,5 +1,5 @@
 /* mingw32 host-specific hook definitions.
-   Copyright (C) 2004 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2007 Free Software Foundation, Inc.
 
    This file is part of GCC.
 
@@ -87,11 +87,11 @@ mingw32_gt_pch_get_address (size_t size, int fd  ATTRIBUTE_UNUSED)
 
   /* FIXME: We let system determine base by setting first arg to NULL.
      Allocating at top of available address space avoids unnecessary
-     fragmentation of "ordinary" (malloc's)  address space but may not be safe
-     with delayed load of system dll's. Preferred addresses for NT system
-     dlls is in 0x70000000 to 0x78000000 range.
-     If we allocate at bottom we need to reserve the address as early as possible
-     and at the same point in each invocation. */
+     fragmentation of "ordinary" (malloc's)  address space but may not
+     be safe  with delayed load of system dll's. Preferred addresses
+     for NT system dlls is in 0x70000000 to 0x78000000 range.
+     If we allocate at bottom we need to reserve the address as early
+     as possible and at the same point in each invocation. */
  
   res = VirtualAlloc (NULL, pch_VA_max_size,
                      MEM_RESERVE | MEM_TOP_DOWN,
@@ -115,19 +115,36 @@ mingw32_gt_pch_use_address (void *addr, size_t size, int fd,
                            size_t offset)
 {
   void * mmap_addr;
-  static HANDLE mmap_handle;
-
-  if (size == 0)
-    return 0;
+  HANDLE mmap_handle;
+
+  /* Apparently, MS Vista puts unnamed file mapping objects into Global
+     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";
+
+  /* However, the documentation for CreateFileMapping says that on NT4
+     and earlier, backslashes are invalid in object name.  So, we need
+     to check if we are on Windows2000 or higher.  */
+  OSVERSIONINFO version_info;
   
+  if (size == 0)
+    return 0; 
+
   /* Offset must be also be a multiple of allocation granularity for
      this to work.  We can't change the offset. */ 
   if ((offset & (va_granularity - 1)) != 0 || size > pch_VA_max_size)
     return -1;
 
-  mmap_handle = CreateFileMapping ((HANDLE) _get_osfhandle (fd),
-                                  NULL, PAGE_WRITECOPY | SEC_COMMIT,
-                                  0, 0,  NULL);
+  /* Determine the version of Windows we are running on.  */
+  version_info.dwOSVersionInfoSize = sizeof (version_info);
+  GetVersionEx (&version_info);
+
+  mmap_handle = CreateFileMappingA ((HANDLE) _get_osfhandle (fd), NULL,
+                                   PAGE_WRITECOPY | SEC_COMMIT, 0, 0,
+                                   version_info.dwMajorVersion > 4
+                                   ? object_name : NULL);
   if (mmap_handle == NULL)
     {
       w32_error (__FUNCTION__,  __FILE__, __LINE__, "CreateFileMapping");