From patchwork Thu Nov 29 10:08:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai Tietz X-Patchwork-Id: 202693 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 873AE2C008E for ; Thu, 29 Nov 2012 21:08:44 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1354788524; h=Comment: DomainKey-Signature:Received:Received:Received:Received: MIME-Version:Received:Received:Date:Message-ID:Subject:From:To: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=btiVzhl CzfBnB7obvs+1XIkmz+o=; b=Qe1Z7q70RN5EdL8pXvxLX5a5K49HZIbn8NjoOiW teGeSBnF6iZgxTh9T3WSCxEMV8Q7xJMu6JMbcZPhjkWJZZ2VTJaxX8IdSMNOu1n4 7QiPkJO2cLQd3GTRQbIK5qC0bsHuF0Q+dHigtoHVdZVP/saGzEeTBPtvbjm/zjSf ojCk= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:MIME-Version:Received:Received:Date:Message-ID:Subject:From:To:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=H1DT6zhzJRVyY95s7IdIJT2glsA/kxjryeLmeN8sKlup9iklsQVXHTFNvgqJFS U8MMXRwAYefLMVAOZUBnVEaWKFaWJfreZDtlXpNPD/nYxHlPaO3/lkiEJZo6HZs+ bfcqKceUGdkRvbfyGocvUwVUrzP/1bU7iZYIW4QVXexj4=; Received: (qmail 10142 invoked by alias); 29 Nov 2012 10:08:39 -0000 Received: (qmail 10133 invoked by uid 22791); 29 Nov 2012 10:08:38 -0000 X-SWARE-Spam-Status: No, hits=-3.1 required=5.0 tests=AWL, BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, KHOP_RCVD_TRUST, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, TW_SF X-Spam-Check-By: sourceware.org Received: from mail-wi0-f169.google.com (HELO mail-wi0-f169.google.com) (209.85.212.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 29 Nov 2012 10:08:32 +0000 Received: by mail-wi0-f169.google.com with SMTP id hq12so5631655wib.2 for ; Thu, 29 Nov 2012 02:08:31 -0800 (PST) MIME-Version: 1.0 Received: by 10.216.206.152 with SMTP id l24mr5054338weo.93.1354183711286; Thu, 29 Nov 2012 02:08:31 -0800 (PST) Received: by 10.216.153.132 with HTTP; Thu, 29 Nov 2012 02:08:31 -0800 (PST) Date: Thu, 29 Nov 2012 11:08:31 +0100 Message-ID: Subject: [patch mingw]: Correct page-size granularity and retry for address-mapping on mingw-hosts. From: Kai Tietz To: GCC Patches X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 +#include 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");