Commit e7b0b62d by Kai Tietz Committed by Kai Tietz

host-mingw32.c (va_granularity): Make none-const.

        * config/i386/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.

From-SVN: r193987
parent d71576d6
2012-11-30 Kai Tietz <ktietz@redhat.com> 2012-11-30 Kai Tietz <ktietz@redhat.com>
* config/i386/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.
* config/i386/mingw32.h (SHARED_LIBGCC_SPEC): Synchronize with * config/i386/mingw32.h (SHARED_LIBGCC_SPEC): Synchronize with
cygwin-host. cygwin-host.
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#define WIN32_LEAN_AND_MEAN /* Not so important if we have windows.h.gch. */ #define WIN32_LEAN_AND_MEAN /* Not so important if we have windows.h.gch. */
#include <windows.h> #include <windows.h>
#include <stdlib.h>
static void * mingw32_gt_pch_get_address (size_t, int); static void * mingw32_gt_pch_get_address (size_t, int);
static int mingw32_gt_pch_use_address (void *, size_t, int, size_t); static int mingw32_gt_pch_use_address (void *, size_t, int, size_t);
...@@ -45,7 +46,7 @@ static inline void w32_error(const char*, const char*, int, const char*); ...@@ -45,7 +46,7 @@ static inline void w32_error(const char*, const char*, int, const char*);
static const size_t pch_VA_max_size = 128 * 1024 * 1024; static const size_t pch_VA_max_size = 128 * 1024 * 1024;
/* Granularity for reserving address space. */ /* Granularity for reserving address space. */
static const size_t va_granularity = 0x10000; static size_t va_granularity = 0x10000;
/* Print out the GetLastError() translation. */ /* Print out the GetLastError() translation. */
static inline void static inline void
...@@ -66,8 +67,14 @@ w32_error (const char* function, const char* file, int line, ...@@ -66,8 +67,14 @@ w32_error (const char* function, const char* file, int line,
} }
/* Granularity for reserving address space. */ /* 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; return va_granularity;
} }
...@@ -114,7 +121,7 @@ mingw32_gt_pch_use_address (void *addr, size_t size, int fd, ...@@ -114,7 +121,7 @@ mingw32_gt_pch_use_address (void *addr, size_t size, int fd,
{ {
void * mmap_addr; void * mmap_addr;
HANDLE mmap_handle; HANDLE mmap_handle;
/* Apparently, MS Vista puts unnamed file mapping objects into Global /* Apparently, MS Vista puts unnamed file mapping objects into Global
namespace when running an application in a Terminal Server namespace when running an application in a Terminal Server
session. This causes failure since, by default, applications session. This causes failure since, by default, applications
...@@ -132,6 +139,8 @@ mingw32_gt_pch_use_address (void *addr, size_t size, int fd, ...@@ -132,6 +139,8 @@ mingw32_gt_pch_use_address (void *addr, size_t size, int fd,
and earlier, backslashes are invalid in object name. So, we need and earlier, backslashes are invalid in object name. So, we need
to check if we are on Windows2000 or higher. */ to check if we are on Windows2000 or higher. */
OSVERSIONINFO version_info; OSVERSIONINFO version_info;
int r;
version_info.dwOSVersionInfoSize = sizeof (version_info); version_info.dwOSVersionInfoSize = sizeof (version_info);
if (size == 0) if (size == 0)
...@@ -154,7 +163,6 @@ mingw32_gt_pch_use_address (void *addr, size_t size, int fd, ...@@ -154,7 +163,6 @@ mingw32_gt_pch_use_address (void *addr, size_t size, int fd,
OBJECT_NAME_FMT "%lx", GetCurrentProcessId()); OBJECT_NAME_FMT "%lx", GetCurrentProcessId());
object_name = local_object_name; object_name = local_object_name;
} }
mmap_handle = CreateFileMappingA ((HANDLE) _get_osfhandle (fd), NULL, mmap_handle = CreateFileMappingA ((HANDLE) _get_osfhandle (fd), NULL,
PAGE_WRITECOPY | SEC_COMMIT, 0, 0, PAGE_WRITECOPY | SEC_COMMIT, 0, 0,
object_name); object_name);
...@@ -164,8 +172,19 @@ mingw32_gt_pch_use_address (void *addr, size_t size, int fd, ...@@ -164,8 +172,19 @@ mingw32_gt_pch_use_address (void *addr, size_t size, int fd,
w32_error (__FUNCTION__, __FILE__, __LINE__, "CreateFileMapping"); w32_error (__FUNCTION__, __FILE__, __LINE__, "CreateFileMapping");
return -1; 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) if (mmap_addr != addr)
{ {
w32_error (__FUNCTION__, __FILE__, __LINE__, "MapViewOfFileEx"); w32_error (__FUNCTION__, __FILE__, __LINE__, "MapViewOfFileEx");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment