cvs: ZendEngine2(PHP_5_3) / zend_stream.c

[email protected] ("Nuno Lopes") Wed, 28 Jan 2009 23:18:50 -0000
Newsgroups php.zend-engine.cvs
Message-ID <cvsnlopess1233184730@cvsserver>
nlopess		Wed Jan 28 23:18:50 2009 UTC

  Modified files:              (Branch: PHP_5_3)
    /ZendEngine2	zend_stream.c 
  Log:
  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
  
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_stream.c?r1=1.13.2.1.2.1.2.9&r2=1.13.2.1.2.1.2.10&diff_format=u
Index: ZendEngine2/zend_stream.c
diff -u ZendEngine2/zend_stream.c:1.13.2.1.2.1.2.9 ZendEngine2/zend_stream.c:1.13.2.1.2.1.2.10
--- ZendEngine2/zend_stream.c:1.13.2.1.2.1.2.9	Fri Jan  9 17:21:12 2009
+++ ZendEngine2/zend_stream.c	Wed Jan 28 23:18:49 2009
@@ -19,7 +19,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_stream.c,v 1.13.2.1.2.1.2.9 2009/01/09 17:21:12 iliaa Exp $ */
+/* $Id: zend_stream.c,v 1.13.2.1.2.1.2.10 2009/01/28 23:18:49 nlopess Exp $ */
 
 
 #include "zend.h"
@@ -214,11 +214,18 @@
 #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;
 			}
 		}