From: Nuno Lopes Date: Wed, 28 Jan 2009 23:18:49 +0000 (+0000) Subject: the offset parameter of mmap() must be aligned to a page boundary (although linux... X-Git-Tag: RELEASE_1_3_5~211 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=86df0f095d249d8127cf73bfbeaa3ee2c3e645eb;p=php the offset parameter of mmap() must be aligned to a page boundary (although linux doesnt strictly require it). use 0 as offset as it will be small and increment the ptrs afterwards --- diff --git a/Zend/zend_stream.c b/Zend/zend_stream.c index 10183d664b..1b63daafd6 100644 --- a/Zend/zend_stream.c +++ b/Zend/zend_stream.c @@ -214,11 +214,18 @@ ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t #if HAVE_MMAP if (file_handle->handle.fp) { /* *buf[size] is zeroed automatically by the kernel */ - *buf = mmap(0, size + ZEND_MMAP_AHEAD, PROT_READ, MAP_PRIVATE, fileno(file_handle->handle.fp), ftell(file_handle->handle.fp)); + *buf = mmap(0, size + ZEND_MMAP_AHEAD, PROT_READ, MAP_PRIVATE, fileno(file_handle->handle.fp), 0); if (*buf != MAP_FAILED) { - file_handle->handle.stream.mmap.len = size; + long offset = ftell(file_handle->handle.fp); file_handle->handle.stream.mmap.map = *buf; + + if (offset != -1) { + *buf += offset; + size -= offset; + } file_handle->handle.stream.mmap.buf = *buf; + file_handle->handle.stream.mmap.len = size; + goto return_mapped; } }