This is the mail archive of the cygwin 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]

Fix for REAL_PAGE_SIZE in PHP


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


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