This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: Possible bug in sysdeps/unix/sysv/linux/powerpc/mmap64.c
On Sat, May 19, 2001 at 03:30:07PM -0700, H . J . Lu wrote:
> On Sat, May 19, 2001 at 06:23:05PM -0400, Jack Howarth wrote:
> > HJ,
> > I can't say why it is set to 12 but the PAGE_SHIFT is present in
> > sysdeps/unix/sysv/linux/powerpc/mmap64.c because the powerpc asm
> > headers in Linux 2.4.x were tightened to not export PAGE_SHIFT
> > (thus it had to be hardcoded into mmap64.c). I recall that the
> > idea was that it should never change no matter what happened to
> > PAGE_SHIFT in linux.
> >
> > Here is one message where the original idea was discussed.
> >
> > http://sources.redhat.com/ml/libc-alpha/2000-10/msg00255.html
> >
>
> I believe the code and comment are wrong. From mmap (2):
>
> offset should ordinarily be a multiple of the page size
> returned by getpagesize(2).
>
> Unless both the man page and the testcase in glibc are wrong, the real
> page size should be used here.
>
>
Here is a proposed patch.
H.J.
----
Index: sysdeps/unix/sysv/linux/powerpc/mmap64.c
===================================================================
RCS file: /work/cvs/gnu/glibc/sysdeps/unix/sysv/linux/powerpc/mmap64.c,v
retrieving revision 1.1.1.5
diff -u -p -r1.1.1.5 mmap64.c
--- sysdeps/unix/sysv/linux/powerpc/mmap64.c 2001/05/05 04:06:28 1.1.1.5
+++ sysdeps/unix/sysv/linux/powerpc/mmap64.c 2001/05/19 22:54:01
@@ -18,6 +18,7 @@
Boston, MA 02111-1307, USA. */
#include <errno.h>
+#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
@@ -27,9 +28,8 @@
#include "kernel-features.h"
-/* This is always the constant 12 for this routine, even if the actual
- page size is larger. */
-#define PAGE_SHIFT 12
+static int page_shift;
+static int page_size;
#ifdef __NR_mmap2
extern void *__unbounded __syscall_mmap2(void *__unbounded, size_t,
@@ -42,8 +42,14 @@ static int have_no_mmap2;
void *
__mmap64 (void *addr, size_t len, int prot, int flags, int fd, off64_t offset)
{
- if (offset & ((1 << PAGE_SHIFT)-1))
+ if (!page_size)
{
+ page_size = __getpagesize ();
+ page_shift = __ffs (page_size) - 1;
+ }
+
+ if (offset & (page_size - 1))
+ {
__set_errno (EINVAL);
return MAP_FAILED;
}
@@ -58,7 +64,7 @@ __mmap64 (void *addr, size_t len, int pr
void *result;
__ptrvalue (result) = INLINE_SYSCALL (mmap2, 6, __ptrvalue (addr), len,
prot, flags, fd,
- (off_t) (offset >> PAGE_SHIFT));
+ (off_t) (offset >> page_shift));
# if __BOUNDED_POINTERS__
__ptrlow (result) = __ptrvalue (result);
__ptrhigh (result) = __ptrvalue (result) + len;