This is the mail archive of the libc-ports@sources.redhat.com mailing list for the libc-ports 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: [PATCH] Fix mmap2 syscall for ColdFire


Andreas Schwab wrote:
Daniel Jacobowitz <drow@false.org> writes:

On Fri, Oct 02, 2009 at 02:16:25PM +0200, Andreas Schwab wrote:
Maxim Kuvyrkov <maxim@codesourcery.com> writes:

Andreas Schwab wrote:
Maxim Kuvyrkov <maxim@codesourcery.com> writes:

M68K linux port expects the argument of mmap2 syscall to be counted in
the memory pages.
The offset is supposed to be always counted in units of 4k.
Unfortunately, that is not the case for ColdFire.
Which is a kernel bug.
It's a long-standing kernel ABI wart.  I disagree that it's a bug, and
it would be a royal pain to have kernels with two different shift
amounts!

Ok. But hardcoding it is wrong, that's what getpagesize is for.

Do you have in mind something like the attached patch? Using this one can then define MMAP2_PAGE_SHIFT to -1 in a particular port to use getpagesize.


Let me know if you think this approach is better then simply hardcoding the value; I'll then submit this patch to libc-alpha@ for review.

Thanks,

--
Maxim Kuvyrkov
CodeSourcery
maxim@codesourcery.com
(650) 331-3385 x724
>From 3ea09fbd56754c272fdc59be766dfb5d5881733c Mon Sep 17 00:00:00 2001
From: Maxim Kuvyrkov <maxim@codesourcery.com>
Date: Fri, 30 Oct 2009 15:25:02 +0300
Subject: [PATCH] Use getpagesize where appropriate


Signed-off-by: Maxim Kuvyrkov <maxim@codesourcery.com>
---
 sysdeps/unix/sysv/linux/mmap64.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/mmap64.c b/sysdeps/unix/sysv/linux/mmap64.c
index d3c68cd..eb5f187 100644
--- a/sysdeps/unix/sysv/linux/mmap64.c
+++ b/sysdeps/unix/sysv/linux/mmap64.c
@@ -34,6 +34,8 @@
 #  define MMAP2_PAGE_SHIFT 12
 # endif
 
+static int page_shift = MMAP2_PAGE_SHIFT;
+
 # ifndef __ASSUME_MMAP2_SYSCALL
 static int have_no_mmap2;
 # endif
@@ -44,7 +46,17 @@ void *
 __mmap64 (void *addr, size_t len, int prot, int flags, int fd, off64_t offset)
 {
 #ifdef __NR_mmap2
-  if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1))
+# if MMAP2_PAGE_SHIFT == -1
+  if (page_shift == -1)
+    {
+      int page_size;
+
+      page_size = getpagesize ();
+      while ((1 << ++page_shift) != page_size);
+    }
+# endif
+
+  if (offset & ((1 << page_shift) - 1))
     {
       __set_errno (EINVAL);
       return MAP_FAILED;
@@ -60,7 +72,7 @@ __mmap64 (void *addr, size_t len, int prot, int flags, int fd, off64_t offset)
       __ptrvalue (result) = (void *__unbounded)
 	INLINE_SYSCALL (mmap2, 6, __ptrvalue (addr),
 			len, prot, flags, fd,
-			(off_t) (offset >> MMAP2_PAGE_SHIFT));
+			(off_t) (offset >> page_shift));
 # if __BOUNDED_POINTERS__
       __ptrlow (result) = __ptrvalue (result);
       __ptrhigh (result) = __ptrvalue (result) + len;
-- 
1.6.4


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