This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ksh on cygwin


----- 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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]