Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Message-ID: <07f601c19a8b$56af1150$0200a8c0@lifelesswks>
From: "Robert Collins" <robert.collins@itdomain.com.au>
To: "Corinna Vinschen" <cygwin@cygwin.com>
References: <200201101259.g0ACxFN12728@dymwsm10.mailwatch.com> <20020110144551.J12057@cygbert.vinschen.de> <033d01c199de$4578ab10$0200a8c0@lifelesswks> <20020110150729.L12057@cygbert.vinschen.de>
Subject: Re: ksh on cygwin
Date: Fri, 11 Jan 2002 21:32:57 +1100
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
X-OriginalArrivalTime: 11 Jan 2002 10:32:56.0212 (UTC) FILETIME=[551C1540:01C19A8B]

----- Original Message -----
From: "Corinna Vinschen" <cygwin@cygwin.com>

> mmap (MapViewOfFile resp.) alwaus map whole pages.  A page is 4096
> bytes long.
>
> If a file is, say, 8190 bytes, then we have a two page map, size 8192.
> So we have two trailing 0 bytes.  If getpagesize() returns 4096, gcc
can
> count that correctly, if getpagesize returns 65536, gcc assumes 57346
> trailing bytes.  No problem, gcc only accesses exactly one trailing 0
byte.
>
> If the file is 8192 bytes long, mmap maps exactly 8192 bytes, no
> trailing bytes left.  If getpagesize() returns 4096, gcc knows that,
> if getpagesize returns 65536, gcc assumes 57344 trailing bytes.
> Now it is a problem, since the one trailing 0 byte doesn't exist.
> Segmentation fault.

Ok. Lets see if I understand:

Let m be the size reported by getpagesize.
Let f be the size of a file gcc is mmaping.

1) Gcc can't handle a remainder of m divided by f that is greater than
<some number between  2 and 57346>.

2) If the remainfer of m divided by f is 0, gcc behaves correctly.

3) If f > m, then gcc assumes that f is m bytes long?

Sounds to me like gcc is badly broken.
i.e. in your prior example:
where m = 4096
if the file is 2048 bytes long, mmap maps exactly 2048 bytes. if m is
4096, gcc assumes there is  2048 trailing bytes. Now it is a problem,
since the one trailing 0 byte doesn't exist. Segmentation fault.

IOW, I don't see how the 4K vs 64K thing affects this scenario, it seems
to be driven purely by the fact the m != 1.

Rob


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

