public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Richard H Lee <ricardohenrylee@gmail.com>
To: cygwin@cygwin.com
Subject: Fix for REAL_PAGE_SIZE in PHP
Date: Tue, 02 May 2017 10:28:00 -0000	[thread overview]
Message-ID: <528aeb1a-9a9d-0afd-7372-576e8c94ae81@gmail.com> (raw)

There is a bug with PHP on Cygwin where it segfaults if the php file
size is a multiple of 4K.

https://bugs.php.net/bug.php?id=65312

PHP mmap()s source files as it it faster than using normal I/O.

The problem is with the page size in Cygwin. When a file is mmap()ed
to memory, any remaining bytes after the EOF in the last page are
zero'ed out. So when PHP reads the bytes after the EOF, it expects to
find zeroes.

In most systems the page size is 4K. In Windows the page size is also
4K, but aligned to a boundary of 64K (allocation granularity). Cygwin
reconciles this by making the page size 64K. So in reality, Cygwin
pages are 64K big, backed by 4K pages allocated along 64K boundaries.

When PHP reads a file, it looks at the file size. If there are enough
bytes to read ahead in the last memory page after the EOF, PHP will use
mmap. Else it will open the file normally.

When PHP is given a 4K file on Cygwin, it sees that the file and the
bytes for reading ahead will easily fit into a 64K page (in
Cygwin). So it mmap()s the file. However only one 4K page (in Windows)
is mapped to. The remaining 60K pages are not. When PHP reads ahead
past the EOF, it reads into page which has not been mapped to. This
results in a segfault.

Changing the REAL_PAGE_SIZE to 4096 fixes the issue.

Should this fix go upstream to PHP or be submitted to the PHP package
within Cygwin?


Richard

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

             reply	other threads:[~2017-05-02 10:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-02 10:28 Richard H Lee [this message]
2017-05-04 14:39 ` [ATTN: PHP maintainer] " Richard H Lee

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=528aeb1a-9a9d-0afd-7372-576e8c94ae81@gmail.com \
    --to=ricardohenrylee@gmail.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).