delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2011/03/23/10:09:05

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-0.6 required=5.0 tests=AWL,BAYES_00,SPF_NEUTRAL,T_RP_MATCHES_RCVD
X-Spam-Check-By: sourceware.org
Message-ID: <4D89FEC7.3000107@cornell.edu>
Date: Wed, 23 Mar 2011 10:08:07 -0400
From: Ken Brown <kbrown AT cornell DOT edu>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: Broken autoconf mmap test
References: <4D8668C6 DOT 8020500 AT cornell DOT edu> <4D890D95 DOT 6090302 AT redhat DOT com> <4D891A55 DOT 6050601 AT cornell DOT edu> <20110323091921 DOT GB10657 AT calimero DOT vinschen DOT de> <4D89D4AA DOT 6070903 AT cornell DOT edu> <20110323132622 DOT GM31220 AT calimero DOT vinschen DOT de>
In-Reply-To: <20110323132622.GM31220@calimero.vinschen.de>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On 3/23/2011 9:26 AM, Corinna Vinschen wrote:
> On Mar 23 07:08, Ken Brown wrote:
>> On 3/23/2011 5:19 AM, Corinna Vinschen wrote:
>>> On Mar 22 17:53, Ken Brown wrote:
>>>> In case it's relevant, my system is 64-bit Windows 7, with the most
>>>> recent cygwin snapshot:
>>>
>>> It is relevant, but it has nothing to do with Windows 7.  Actually, the
>>> autoconf mmap test is testing a scenario which does not work on 64 bit
>>> Windows systems.  Here's what happens in a nutshell.
>>>
>>> The actual pagesize on Windows is 4K.  But there's something called
>>> "allocation granularity" which is 64K.  If you request virtual memory on
>>> Windows, the memory address is always aligned to the allocation
>>> granularity boundary.  Even if you request 4K chunks, they are 64K
>>> aligned.
>>>
>>> If you mmap anonymous memory, this is no big problem.  Cygwin always
>>> requests memory in 64K chunks since Cygwin's pagesize is set to 64K.
>>>
>>> However, if you mmap a file, there's a problem.  The mapping always
>>> starts on a 64K boundary, but it end on the next 4K boundary beyond EOF.
>>> So, for a file of size 1 byte, the memory section will be 4K.  The other
>>> 60K following in the virtual address space are lost.  And they are not
>>> allocated.  And i you try to access them you get a SEGV.
>>>
>>> Fortunately, Cygwin uses the native NT calls in mmap.  The native calls
>>> support a flag called AT_ROUND_TO_PAGE, which allows to allocate memory
>>> on a 4K boundary.  So what Cygwin does is to mmap the file, and then to
>>> request virtual memory rounded to the next 4K page to fill the rest of
>>> the 64K allocation area.  Now we have the full 64K allocated.
>>>
>>> Unfortunately this doesn't work on 64 bit Windows.  The reason is that
>>> the WOW64 layer does not support the AT_ROUND_TO_PAGE flag.  If you try
>>> to use it, the OS call returns STTAUS_INVALID_PARAMETER.  So you can't
>>> allocate the remainder of the 64K allocation slot at all.
>>>
>>> Back to the autoconf mmap test.  What it does is to mmap a file of size
>>> 1 byte.  Then it tests each byte in the mapped page.  And since the
>>> pagesize in Cygwin is 64K it tests all of 64K.
>>>
>>> Given the above description, you can now imagine this works fine on 32
>>> bit Windows, but it crashes on 64 bit Windows.
>>
>> Thanks for the explanation, Corinna.  I've reported this to the
>> autoconf list.
>
> Btw., I just experimented with another flag which has not been exposed
> to the Win32 API, and which is not officially documented.  It's called
> AT_EXTENDABLE_FILE and allows to specify a view which is bigger than
> the filesize.  I tried this on W7-64, and it works.  Just not exactly
> as we need it.  The trailing pages are not commited but only reserved,
> so accessing them still results in a SEGV.  And while commiting them
> allows to run the autoconf testcase, it also changes the filesize of
> the file on disk.  Oh well.

Is the scenario in which the autoconf test fails likely to occur in 
practice?  I wonder if it could be responsible for some of the 
mysterious crashes that people have reported on 64-bit systems.

Ken

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019