This is the mail archive of the
mailing list for the Cygwin project.
Fix for REAL_PAGE_SIZE in PHP
- From: Richard H Lee <ricardohenrylee at gmail dot com>
- To: cygwin at cygwin dot com
- Date: Tue, 2 May 2017 11:28:49 +0100
- Subject: Fix for REAL_PAGE_SIZE in PHP
- Authentication-results: sourceware.org; auth=none
There is a bug with PHP on Cygwin where it segfaults if the php file
size is a multiple of 4K.
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
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
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple