diff options
author | Kai Tietz <ktietz@redhat.com> | 2012-11-30 09:10:34 +0100 |
---|---|---|
committer | Kai Tietz <ktietz@gcc.gnu.org> | 2012-11-30 09:10:34 +0100 |
commit | e7b0b62dc0cdf46195cc3a1353a66812199cce30 (patch) | |
tree | 3214f1dabec5c74e199f989c9dedfb827f3642f7 /gcc/config/i386/host-mingw32.c | |
parent | d71576d634a27eed6e34aee7abfd1b89d32d8949 (diff) | |
download | gcc-e7b0b62dc0cdf46195cc3a1353a66812199cce30.zip gcc-e7b0b62dc0cdf46195cc3a1353a66812199cce30.tar.gz gcc-e7b0b62dc0cdf46195cc3a1353a66812199cce30.tar.bz2 |
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
Diffstat (limited to 'gcc/config/i386/host-mingw32.c')
-rw-r--r-- | gcc/config/i386/host-mingw32.c | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/gcc/config/i386/host-mingw32.c b/gcc/config/i386/host-mingw32.c index c224b28..015696c 100644 --- a/gcc/config/i386/host-mingw32.c +++ b/gcc/config/i386/host-mingw32.c @@ -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 inline void w32_error(const char*, const char*, int, const char*); 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 @@ w32_error (const char* function, const char* file, int line, } /* 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; } @@ -114,7 +121,7 @@ mingw32_gt_pch_use_address (void *addr, size_t size, int fd, { void * mmap_addr; 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 @@ -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 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 @@ mingw32_gt_pch_use_address (void *addr, size_t size, int fd, 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 @@ mingw32_gt_pch_use_address (void *addr, size_t size, int fd, 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"); |