This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Consistently use page_shift in sysdeps/unix/sysv/linux/mmap64.c
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Roland McGrath <roland at hack dot frob dot com>
- Cc: <libc-alpha at sourceware dot org>, Andreas Schwab <schwab at linux-m68k dot org>
- Date: Mon, 1 Jul 2013 22:41:59 +0000
- Subject: Re: Consistently use page_shift in sysdeps/unix/sysv/linux/mmap64.c
- References: <Pine dot LNX dot 4 dot 64 dot 1306282000050 dot 15167 at digraph dot polyomino dot org dot uk> <20130628213457 dot 38E962C09C at topped-with-meat dot com>
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 <joseph@codesourcery.com>
* 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;
}
#endif
if (offset & ((1 << page_shift) - 1))
--
Joseph S. Myers
joseph@codesourcery.com