This is the mail archive of the mailing list for the glibc 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]

Re: Consistently use page_shift in sysdeps/unix/sysv/linux/mmap64.c

On Fri, 28 Jun 2013, Roland McGrath wrote:

> That's fine but if you're going to worry about the unused #if case then you
> might make it name space clean (use __getpagesize or GLRO(dl_pagesize)) and
> make it use __ffs instead of a loop for its log2.  (The latter is also a
> correctness fix in case of a race to be the first call, in which case the
> first thread could be partway through its loop when the second thread comes
> along and uses a bogus nonzero value for page_shift.)

This patch (untested, given the unused nature of this #if block) uses 
__getpagesize and fixes the race with use of __ffs.

(I have not investigated whether the race was real or whether the 
assignments to the static page_shift would get hoisted to after the loop.)

2013-07-01  Joseph Myers  <>

	* sysdeps/unix/sysv/linux/mmap64.c (__mmap64) [MMAP2_PAGE_SHIFT ==
	-1]: Use __getpagesize to determine page size.  Use __ffs to
	determine corresponding shift.

diff --git a/sysdeps/unix/sysv/linux/mmap64.c b/sysdeps/unix/sysv/linux/mmap64.c
index e2dcdc4..4ba686c 100644
--- a/sysdeps/unix/sysv/linux/mmap64.c
+++ b/sysdeps/unix/sysv/linux/mmap64.c
@@ -42,9 +42,8 @@ __mmap64 (void *addr, size_t len, int prot, int flags, int fd, off64_t offset)
 #if MMAP2_PAGE_SHIFT == -1
   if (page_shift == 0)
-      int page_size = getpagesize ();
-      while ((1 << ++page_shift) != page_size)
-	;
+      int page_size = __getpagesize ();
+      page_shift = __ffs (page_size) - 1;
   if (offset & ((1 << page_shift) - 1))

Joseph S. Myers

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