[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r8387: Do not graciously increase the size to be mmaped if the curr (in tor/trunk: . src/common)



Author: weasel
Date: 2006-09-14 00:53:42 -0400 (Thu, 14 Sep 2006)
New Revision: 8387

Modified:
   tor/trunk/
   tor/trunk/src/common/compat.c
Log:
 r9749@danube:  weasel | 2006-09-14 06:53:12 +0200
 Do not graciously increase the size to be mmaped if the current size already is
 at a page_size boundary.  This is important since if a file has a size of zero
 and we mmap() it with length > 0, then accessing the mmaped memory area causes
 a bus error.  However, if we pass a length of 0 to mmap() it will return with -1
 and things work from there.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /local/or/tor/trunk [r9749] on 17f730b7-d419-0410-b50f-85ee4b70197a

Modified: tor/trunk/src/common/compat.c
===================================================================
--- tor/trunk/src/common/compat.c	2006-09-14 04:53:23 UTC (rev 8386)
+++ tor/trunk/src/common/compat.c	2006-09-14 04:53:42 UTC (rev 8387)
@@ -130,7 +130,7 @@
   lseek(fd, 0, SEEK_SET);
   /* ensure page alignment */
   page_size = getpagesize();
-  size += (page_size + (page_size-(size%page_size)));
+  size += (size%page_size) ? page_size-(size%page_size) : 0;
 
   string = mmap(0, size, PROT_READ, MAP_PRIVATE, fd, 0);
   if (string == MAP_FAILED) {