]> granicus.if.org Git - strace/commitdiff
Use sysconf(_SC_PAGESIZE) instead of hardcoded PAGE_SHIFT
authorDmitry V. Levin <ldv@altlinux.org>
Tue, 5 Mar 2013 14:58:24 +0000 (14:58 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 5 Mar 2013 16:03:53 +0000 (16:03 +0000)
PAGE_SHIFT couldn't be reliably obtained at compile time,
thanks to Chris Metcalf for the hint.

* mem.c: Do not include <sys/user.h>.
[SH64] Do not include <asm/page.h>.
(get_pagesize): New function.
(sys_mmap_pgoff, sys_old_mmap_pgoff): Use it.

mem.c

diff --git a/mem.c b/mem.c
index 6f22922d623e3e871c01933413cabe0be9ad9aed..3bd41b46c5669751823789ceb64174ed7db0fbd7 100644 (file)
--- a/mem.c
+++ b/mem.c
 # endif
 #endif
 
-#include <sys/user.h>  /* for PAGE_SHIFT */
-#if defined(SH64)
-# include <asm/page.h> /* for PAGE_SHIFT */
-#endif
-#if !defined(PAGE_SHIFT)
-# warning Failed to get PAGE_SHIFT, assuming 12
-# define PAGE_SHIFT 12
-#endif
+static unsigned long
+get_pagesize()
+{
+       static unsigned long pagesize;
+
+       if (!pagesize)
+               pagesize = sysconf(_SC_PAGESIZE);
+       return pagesize;
+}
 
 int
 sys_brk(struct tcb *tcp)
@@ -295,7 +296,7 @@ sys_old_mmap_pgoff(struct tcb *tcp)
        for (i = 0; i < 5; i++)
                u_arg[i] = (unsigned long) narrow_arg[i];
        offset = narrow_arg[5];
-       offset <<= PAGE_SHIFT;
+       offset *= get_pagesize();
        return print_mmap(tcp, u_arg, offset);
 }
 #endif
@@ -324,7 +325,7 @@ sys_mmap_pgoff(struct tcb *tcp)
        /* Try test/mmap_offset_decode.c */
        unsigned long long offset;
        offset = (unsigned long) tcp->u_arg[5];
-       offset <<= PAGE_SHIFT;
+       offset *= get_pagesize();
        return print_mmap(tcp, tcp->u_arg, offset);
 }