[PATCH] Change logic to select mmap system call in _dl_mmap

Nicolas Bellido ml at acolin.be
Tue Feb 21 21:55:36 UTC 2006


On Tuesday 21 February 2006 15:20, Mike Frysinger wrote:
> On Tuesday 21 February 2006 04:15, Nicolas Bellido wrote:
> > Before submitting a patch, I would like to understand the rationale
> > behind 'use mmap first before trying to use mmap2' ? Is this something
> > required by some other architectures ?
>
> the rationale is 'use a straight mmap syscall before anything else because
> it's the smallest code size'
>
> should be trivial to change the logic to try and do:
>  - mmap 6 arg syscall
>  - mmap2 syscall
>  - mmap 1 arg syscall
> so if you want to submit a patch to do this, i'd prob merge it ...

This patch implements what you suggested. I'm not sure whether
__UCLIBC_MMAP_HAS_6_ARGS__ can be defined even if __NR_mmap is not available,
so I test for both.

Note that this patch depends on the MAP_FAILED fix is sent earlier.

-

On ARM platform, the new EABI makes the mmap system call obsolete. Also, the
way syscall numbers are passed to the kernel is different: they are passed in
r7, and not in the swi.

There is however the possibility to enable a kernel compatibility mode, to
allow non-EABI applications to run. But this implies the non-EABI way to pass
the syscall number.

When uClibc is built with CONFIG_ARM_EABI=y, r7 is used to pass the 
syscall number. But, as mmap is defined in ABI-compatibility mode in the 
kernel, the kernel expects the syscall number in the swi instruction, causing
the mmap to fail with an 'Obsolete system call' error message.

This patch modifies the logic used to select the appropriate mmap, as
suggested by Mike Frysinger:
	. first, check if mmap 6 args syscall is available
	. if not, check mmap2 syscall
	. if not, check mmap 1 arg syscall

Signed-Off-By: Nicolas Bellido <ml at acolin.be>

Index: uClibc-20060218/ldso/include/dl-syscall.h
===================================================================
--- uClibc-20060218.orig/ldso/include/dl-syscall.h
+++ uClibc-20060218/ldso/include/dl-syscall.h
@@ -133,12 +133,25 @@ static inline _syscall3(int, _dl_readlin
 static inline _syscall2(int, _dl_gettimeofday, struct timeval *, tv, struct timezone *, tz);
 #endif
 
-#ifdef __NR_mmap
-#ifdef __UCLIBC_MMAP_HAS_6_ARGS__
+#if defined(__UCLIBC_MMAP_HAS_6_ARGS__) && defined(__NR_mmap)
 #define __NR__dl_mmap __NR_mmap
 static inline _syscall6(void *, _dl_mmap, void *, start, size_t, length,
 		int, prot, int, flags, int, fd, off_t, offset);
-#else
+#elif defined __NR_mmap2
+#define __NR___syscall_mmap2       __NR_mmap2
+static inline _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr,
+		size_t, len, int, prot, int, flags, int, fd, off_t, offset);
+/*always 12, even on architectures where PAGE_SHIFT != 12 */
+#define MMAP2_PAGE_SHIFT 12
+static inline void * _dl_mmap(void * addr, unsigned long size, int prot,
+		int flags, int fd, unsigned long offset)
+{
+    if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1))
+	return (void *)-_dl_MAX_ERRNO;
+    return(__syscall_mmap2(addr, size, prot, flags,
+		fd, (off_t) (offset >> MMAP2_PAGE_SHIFT)));
+}
+#elif defined __NR_mmap
 #define __NR__dl_mmap_real __NR_mmap
 static inline _syscall1(void *, _dl_mmap_real, unsigned long *, buffer);
 
@@ -155,21 +168,6 @@ static inline void * _dl_mmap(void * add
 	buffer[5] = (unsigned long) offset;
 	return (void *) _dl_mmap_real(buffer);
 }
-#endif
-#elif defined __NR_mmap2
-#define __NR___syscall_mmap2       __NR_mmap2
-static inline _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr,
-		size_t, len, int, prot, int, flags, int, fd, off_t, offset);
-/*always 12, even on architectures where PAGE_SHIFT != 12 */
-#define MMAP2_PAGE_SHIFT 12
-static inline void * _dl_mmap(void * addr, unsigned long size, int prot,
-		int flags, int fd, unsigned long offset)
-{
-    if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1))
-	return (void *)-_dl_MAX_ERRNO;
-    return(__syscall_mmap2(addr, size, prot, flags,
-		fd, (off_t) (offset >> MMAP2_PAGE_SHIFT)));
-}
 #else
 #error "Your architecture doesn't seem to provide mmap() !?"
 #endif

--

Nicolas



More information about the uClibc mailing list