public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Fix for REAL_PAGE_SIZE in PHP
@ 2017-05-02 10:28 Richard H Lee
  2017-05-04 14:39 ` [ATTN: PHP maintainer] " Richard H Lee
  0 siblings, 1 reply; 2+ messages in thread
From: Richard H Lee @ 2017-05-02 10:28 UTC (permalink / raw)
  To: cygwin

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-05-04 14:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-02 10:28 Fix for REAL_PAGE_SIZE in PHP Richard H Lee
2017-05-04 14:39 ` [ATTN: PHP maintainer] " Richard H Lee

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