[patch mingw]: Correct page-size granularity and retry for address-mapping on mingw-hosts.
Kai Tietz
ktietz70@googlemail.com
Thu Nov 29 10:08:00 GMT 2012
Hi,
this patch fixes a latent issue about page-size granularity for
Windows OSes - like Vista, Win7, etc. -
and avoid a race happening for mapping of memory for multiple
instances of compiler.
ChangeLog
2012-11-29 Kai Tietz
* host-mingw32.c (va_granularity): Make none-const.
(mingw32_gt_pch_alloc_granularity): Return OS' allocation
granularity.
(mingw32_gt_pch_use_address): Retry mapping of used address
as multiple instances might interfer.
Tested for i686-w64-mingw32, and x86_64-w64-mingw32. Will apply
tomorrow if there aren't any objections.
Regards,
Kai
Index: host-mingw32.c
===================================================================
--- host-mingw32.c (Revision 193925)
+++ host-mingw32.c (Arbeitskopie)
@@ -27,6 +27,7 @@
#define WIN32_LEAN_AND_MEAN /* Not so important if we have windows.h.gch. */
#include <windows.h>
+#include <stdlib.h>
static void * mingw32_gt_pch_get_address (size_t, int);
static int mingw32_gt_pch_use_address (void *, size_t, int, size_t);
@@ -45,7 +46,7 @@
static const size_t pch_VA_max_size = 128 * 1024 * 1024;
/* Granularity for reserving address space. */
-static const size_t va_granularity = 0x10000;
+static size_t va_granularity = 0x10000;
/* Print out the GetLastError() translation. */
static inline void
@@ -66,8 +67,14 @@
}
/* Granularity for reserving address space. */
-static size_t mingw32_gt_pch_alloc_granularity (void)
+static size_t
+mingw32_gt_pch_alloc_granularity (void)
{
+ SYSTEM_INFO si;
+
+ GetSystemInfo (&si);
+ va_granularity = (size_t) si.dwAllocationGranularity;
+
return va_granularity;
}
@@ -132,6 +139,8 @@
and earlier, backslashes are invalid in object name. So, we need
to check if we are on Windows2000 or higher. */
OSVERSIONINFO version_info;
+ int r;
+
version_info.dwOSVersionInfoSize = sizeof (version_info);
if (size == 0)
@@ -154,7 +163,6 @@
OBJECT_NAME_FMT "%lx", GetCurrentProcessId());
object_name = local_object_name;
}
-
mmap_handle = CreateFileMappingA ((HANDLE) _get_osfhandle (fd), NULL,
PAGE_WRITECOPY | SEC_COMMIT, 0, 0,
object_name);
@@ -164,8 +172,19 @@
w32_error (__FUNCTION__, __FILE__, __LINE__, "CreateFileMapping");
return -1;
}
- mmap_addr = MapViewOfFileEx (mmap_handle, FILE_MAP_COPY, 0, offset,
- size, addr);
+
+ /* Retry five times, as here might occure a race with multiple gcc's
+ instances at same time. */
+ for (r = 0; r < 5; r++)
+ {
+ mmap_addr = MapViewOfFileEx (mmap_handle, FILE_MAP_COPY, 0, offset,
+ size, addr);
+ if (mmap_addr == addr)
+ break;
+ if (r != 4)
+ Sleep (500);
+ }
+
if (mmap_addr != addr)
{
w32_error (__FUNCTION__, __FILE__, __LINE__, "MapViewOfFileEx");
More information about the Gcc-patches
mailing list