From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3053 invoked by alias); 27 Jul 2012 20:07:10 -0000 Received: (qmail 3034 invoked by uid 22791); 27 Jul 2012 20:07:06 -0000 X-SWARE-Spam-Status: No, hits=-3.9 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,TW_FC,TW_FN,TW_JN,TW_TR X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 27 Jul 2012 20:06:36 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1Suqny-0003cB-Ip from joseph_myers@mentor.com ; Fri, 27 Jul 2012 13:06:34 -0700 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Fri, 27 Jul 2012 13:06:34 -0700 Received: from digraph.polyomino.org.uk (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.1.289.1; Fri, 27 Jul 2012 21:06:31 +0100 Received: from jsm28 (helo=localhost) by digraph.polyomino.org.uk with local-esmtp (Exim 4.76) (envelope-from ) id 1Suqnu-0007Kr-Dv; Fri, 27 Jul 2012 20:06:30 +0000 Date: Fri, 27 Jul 2012 20:07:00 -0000 From: "Joseph S. Myers" To: CC: , Andreas Krebbel Subject: Remove __ASSUME_MMAP2_SYSCALL Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Mailing-List: contact libc-ports-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: libc-ports-owner@sourceware.org X-SW-Source: 2012-07/txt/msg00071.txt.bz2 For the architectures that define __ASSUME_MMAP2_SYSCALL, it is defined for all kernel versions. Those architectures are: arm hppa m68k tile i386 sparc32 sh powerpc32. This macro is tested in the following files: sysdeps/unix/sysv/linux/i386/mmap.S sysdeps/unix/sysv/linux/i386/mmap64.S sysdeps/unix/sysv/linux/mmap64.c sysdeps/unix/sysv/linux/s390/s390-32/mmap.S sysdeps/unix/sysv/linux/s390/s390-32/mmap64.S. None of those files is #included by other files. 64-bit architectures other than MIPS64 override sysdeps/unix/sysv/linux/mmap64.c with sysdeps/unix/sysv/linux/wordsize-64/mmap64.c, while MIPS64 also overrides it with its own mmap64.c. Thus __ASSUME_MMAP2_SYSCALL is only ever tested for 32-bit architectures, and sysdeps/unix/sysv/linux/mmap64.c is only ever used for 32-bit architectures. The 32-bit architectures in libc and ports that do not define __ASSUME_MMAP2_SYSCALL are s390-32, am33 and mips (o32 ABI). The least relevant kernel versions for these architectures are 2.4.21, 2.6.25 (the version when am33 support was added) and 2.6.12 respectively. Each of those kernel versions has the mmap2 syscall for the relevant architecture. Thus, it is in fact safe to assume this syscall is present on all architectures for which code may be built that uses it. This patch does so, removing __ASSUME_MMAP2_SYSCALL and associated __NR_mmap2 conditionals. Tested x86. Could s390 maintainers please test and review it? Note that __ASSUME_MMAP2_SYSCALL was never previously defined for s390-32 at all, despite the conditionals in s390-specific code - thus the changes to the s390-32 mmap/mmap64 code are exposing code that was never used before, and you should carefully review the existing code exposed by my patch, not just that my patch removes the conditionals correctly. If you find pre-existing issues with the s390 code then please commit whatever patch of your own you think appropriate to fix such issues. (A patch version diffed with -w is attached for convenience in reviewing the changes to sysdeps/unix/sysv/linux/mmap64.c, which include reindentation.) 2012-07-27 Joseph Myers * sysdeps/unix/sysv/linux/kernel-features.h (__ASSUME_MMAP2_SYSCALL): Remove all definitions. * sysdeps/unix/sysv/linux/mmap64.c [__NR_mmap2]: Make code unconditional. [!__ASSUME_MMAP2_SYSCALL]: Remove conditional code. * sysdeps/unix/sysv/linux/i386/mmap.S (__mmap) [__ASSUME_MMAP2_SYSCALL]: Make code unconditional. (__mmap) [!__ASSUME_MMAP2_SYSCALL]: Remove conditional code. * sysdeps/unix/sysv/linux/i386/mmap64.S (__mmap64) [__NR_mmap2]: Make code unconditional. (__mmap64) [!__ASSUME_MMAP2_SYSCALL]: Remove conditional code. (__mmap64) [!__NR_mmap2]: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/mmap.S (__mmap) [__ASSUME_MMAP2_SYSCALL]: Make code unconditional. (__mmap) [!__ASSUME_MMAP2_SYSCALL]: Remove conditional code. * sysdeps/unix/sysv/linux/s390/s390-32/mmap64.S (__mmap64) [__NR_mmap2]: Make code unconditional. (__mmap64) [!__ASSUME_MMAP2_SYSCALL]: Remove conditional code. (__mmap64) [!__NR_mmap2]: Likewise. ports/ChangeLog.arm: 2012-07-27 Joseph Myers * sysdeps/unix/sysv/linux/arm/kernel-features.h (__ASSUME_MMAP2_SYSCALL): Remove. ports/ChangeLog.hppa: 2012-07-27 Joseph Myers * sysdeps/unix/sysv/linux/hppa/kernel-features.h (__ASSUME_MMAP2_SYSCALL): Remove. ports/ChangeLog.m68k: 2012-07-27 Joseph Myers * sysdeps/unix/sysv/linux/m68k/kernel-features.h (__ASSUME_MMAP2_SYSCALL): Remove. ports/ChangeLog.tile: 2012-07-27 Joseph Myers * sysdeps/unix/sysv/linux/tile/kernel-features.h (__ASSUME_MMAP2_SYSCALL): Remove. diff --git a/ports/sysdeps/unix/sysv/linux/arm/kernel-features.h b/ports/sysdeps/unix/sysv/linux/arm/kernel-features.h index 9092df7..3f5109c 100644 --- a/ports/sysdeps/unix/sysv/linux/arm/kernel-features.h +++ b/ports/sysdeps/unix/sysv/linux/arm/kernel-features.h @@ -22,9 +22,8 @@ # define __ASSUME_UTIMES 1 #endif -/* On ARM the mmap2/stat64/lstat64/fstat64 syscalls were introduced in +/* On ARM the stat64/lstat64/fstat64 syscalls were introduced in 2.3.35. */ -#define __ASSUME_MMAP2_SYSCALL 1 #define __ASSUME_STAT64_SYSCALL 1 /* Arm got fcntl64 in 2.4.4. */ diff --git a/ports/sysdeps/unix/sysv/linux/hppa/kernel-features.h b/ports/sysdeps/unix/sysv/linux/hppa/kernel-features.h index 8dcdfbf..3b7ee65 100644 --- a/ports/sysdeps/unix/sysv/linux/hppa/kernel-features.h +++ b/ports/sysdeps/unix/sysv/linux/hppa/kernel-features.h @@ -1,6 +1,6 @@ /* Set flags signalling availability of kernel features based on given kernel version number. - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006-2012 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -23,7 +23,6 @@ and expect the final version here. */ #define __ASSUME_32BITUIDS 1 #define __ASSUME_TRUNCATE64_SYSCALL 1 -#define __ASSUME_MMAP2_SYSCALL 1 #define __ASSUME_STAT64_SYSCALL 1 #define __ASSUME_IPC64 1 #define __ASSUME_ST_INO_64_BIT 1 diff --git a/ports/sysdeps/unix/sysv/linux/m68k/kernel-features.h b/ports/sysdeps/unix/sysv/linux/m68k/kernel-features.h index 3b0b441..522f8bd 100644 --- a/ports/sysdeps/unix/sysv/linux/m68k/kernel-features.h +++ b/ports/sysdeps/unix/sysv/linux/m68k/kernel-features.h @@ -18,7 +18,6 @@ . */ /* These features were surely available with 2.4.12. */ -#define __ASSUME_MMAP2_SYSCALL 1 #define __ASSUME_STAT64_SYSCALL 1 #define __ASSUME_FCNTL64 1 #define __ASSUME_VFORK_SYSCALL 1 diff --git a/ports/sysdeps/unix/sysv/linux/tile/kernel-features.h b/ports/sysdeps/unix/sysv/linux/tile/kernel-features.h index 89929d2..746d22d 100644 --- a/ports/sysdeps/unix/sysv/linux/tile/kernel-features.h +++ b/ports/sysdeps/unix/sysv/linux/tile/kernel-features.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 Free Software Foundation, Inc. +/* Copyright (C) 2011-2012 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Chris Metcalf , 2011. @@ -18,7 +18,6 @@ /* TILE glibc support starts with 2.6.36, guaranteeing many kernel features. */ -#define __ASSUME_MMAP2_SYSCALL 1 #define __ASSUME_STAT64_SYSCALL 1 #define __ASSUME_FCNTL64 1 #define __ASSUME_CLONE_THREAD_FLAGS 1 diff --git a/sysdeps/unix/sysv/linux/i386/mmap.S b/sysdeps/unix/sysv/linux/i386/mmap.S index c8bf3e1..1f79bde 100644 --- a/sysdeps/unix/sysv/linux/i386/mmap.S +++ b/sysdeps/unix/sysv/linux/i386/mmap.S @@ -25,10 +25,6 @@ ENTRY (__mmap) -/* I don't think it is worthwhile trying to use mmap2 whenever it - is available. Only use it when we are sure the syscall exists. */ -#ifdef __ASSUME_MMAP2_SYSCALL - /* Save registers. */ pushl %ebp cfi_adjust_cfa_offset (4) @@ -73,25 +69,6 @@ L(skip): cfi_adjust_cfa_offset (-4) cfi_restore (ebp) -#else - - /* Save registers. */ - movl %ebx, %edx - cfi_register (ebx, edx) - - movl $SYS_ify(mmap), %eax /* System call number in %eax. */ - - lea 4(%esp), %ebx /* Address of args is 1st arg. */ - - /* Do the system call trap. */ - int $0x80 - - /* Restore registers. */ - movl %edx, %ebx - cfi_restore (ebx) - -#endif - /* If 0 > %eax > -4096 there was an error. */ cmpl $-4096, %eax ja SYSCALL_ERROR_LABEL diff --git a/sysdeps/unix/sysv/linux/i386/mmap64.S b/sysdeps/unix/sysv/linux/i386/mmap64.S index 7599b85..8855109 100644 --- a/sysdeps/unix/sysv/linux/i386/mmap64.S +++ b/sysdeps/unix/sysv/linux/i386/mmap64.S @@ -37,8 +37,6 @@ .text ENTRY (BP_SYM (__mmap64)) -#ifdef __NR_mmap2 - /* Save registers. */ pushl %ebp cfi_adjust_cfa_offset (4) @@ -88,12 +86,6 @@ L(do_syscall): cfi_adjust_cfa_offset (-4) cfi_restore (ebp) -#ifndef __ASSUME_MMAP2_SYSCALL -2: - cmp $-ENOSYS, %eax - je 3f -#endif - /* If 0 > %eax > -4096 there was an error. */ cmpl $-4096, %eax ja SYSCALL_ERROR_LABEL @@ -122,42 +114,6 @@ L(einval): cfi_restore (ebp) movl $-EINVAL, %eax jmp SYSCALL_ERROR_LABEL -#endif - -#if !defined __ASSUME_MMAP2_SYSCALL || !defined __NR_mmap2 -3: - /* Save registers. */ - movl %ebx, %edx - cfi_register (ebx, edx) - - cmpl $0, OFFHI-SVRSP(%esp) - jne L(einval2) - - movl $SYS_ify(mmap), %eax /* System call number in %eax. */ - - lea ADDR-SVRSP(%esp), %ebx /* Address of args is 1st arg. */ - - /* Do the system call trap. */ - ENTER_KERNEL - - /* Restore registers. */ - movl %edx, %ebx - cfi_restore (ebx) - - /* If 0 > %eax > -4096 there was an error. */ - cmpl $-4096, %eax - ja SYSCALL_ERROR_LABEL - - /* Successful; return the syscall's value. */ - ret - - cfi_register (ebx, edx) -L(einval2): - movl %edx, %ebx - cfi_restore (ebx) - movl $-EINVAL, %eax - jmp SYSCALL_ERROR_LABEL -#endif PSEUDO_END (BP_SYM (__mmap64)) diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h index cfe335d..7e04594 100644 --- a/sysdeps/unix/sysv/linux/kernel-features.h +++ b/sysdeps/unix/sysv/linux/kernel-features.h @@ -40,20 +40,14 @@ /* The sendfile syscall was introduced in 2.2.0. */ #define __ASSUME_SENDFILE 1 -/* On x86 the mmap2 syscall was introduced in 2.3.31. */ -#ifdef __i386__ -# define __ASSUME_MMAP2_SYSCALL 1 -#endif - /* On x86 the stat64/lstat64/fstat64 syscalls were introduced in 2.3.34. */ #ifdef __i386__ # define __ASSUME_STAT64_SYSCALL 1 #endif -/* On sparc the mmap2/stat64/lstat64/fstat64 syscalls were introduced - in 2.3.35. */ +/* On sparc the stat64/lstat64/fstat64 syscalls were introduced in + 2.3.35. */ #if defined __sparc__ && !defined __arch64__ -# define __ASSUME_MMAP2_SYSCALL 1 # define __ASSUME_STAT64_SYSCALL 1 #endif @@ -70,9 +64,8 @@ # define __ASSUME_IPC64 1 #endif -/* SH kernels got stat64 and mmap2 during 2.4.0-test. */ +/* SH kernels got stat64 during 2.4.0-test. */ #ifdef __sh__ -# define __ASSUME_MMAP2_SYSCALL 1 # define __ASSUME_STAT64_SYSCALL 1 #endif @@ -106,12 +99,6 @@ # define __ASSUME_VFORK_SYSCALL 1 #endif -/* Starting with 2.4.5 kernels the mmap2 syscall made it into the official - kernel. But PowerPC64 does not support a separate MMAP2 call. */ -#if defined __powerpc__ && !defined __powerpc64__ -# define __ASSUME_MMAP2_SYSCALL 1 -#endif - /* On x86, the set_thread_area syscall was introduced in 2.5.29, but its semantics was changed in 2.5.30, and again after 2.5.31. */ #if __LINUX_KERNEL_VERSION >= 132384 && defined __i386__ diff --git a/sysdeps/unix/sysv/linux/mmap64.c b/sysdeps/unix/sysv/linux/mmap64.c index 495d777..bca15f9 100644 --- a/sysdeps/unix/sysv/linux/mmap64.c +++ b/sysdeps/unix/sysv/linux/mmap64.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1999,2000,2001,2002,2006,2010 Free Software Foundation, Inc. +/* Copyright (C) 1999-2012 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Jakub Jelinek , 1999. @@ -26,76 +26,42 @@ #include -#ifdef __NR_mmap2 - /* This is always 12, even on architectures where PAGE_SHIFT != 12. */ -# if MMAP2_PAGE_SHIFT == -1 +#if MMAP2_PAGE_SHIFT == -1 static int page_shift; -# else -# ifndef MMAP2_PAGE_SHIFT -# define MMAP2_PAGE_SHIFT 12 -# endif -# define page_shift MMAP2_PAGE_SHIFT -# endif - -# ifndef __ASSUME_MMAP2_SYSCALL -static int have_no_mmap2; +#else +# ifndef MMAP2_PAGE_SHIFT +# define MMAP2_PAGE_SHIFT 12 # endif +#define page_shift MMAP2_PAGE_SHIFT #endif void * __mmap64 (void *addr, size_t len, int prot, int flags, int fd, off64_t offset) { -#ifdef __NR_mmap2 -# if MMAP2_PAGE_SHIFT == -1 +#if MMAP2_PAGE_SHIFT == -1 if (page_shift == 0) { int page_size = getpagesize (); while ((1 << ++page_shift) != page_size) ; } -# endif - if (offset & ((1 << page_shift) - 1)) - { - __set_errno (EINVAL); - return MAP_FAILED; - } -# ifndef __ASSUME_MMAP2_SYSCALL - if (! have_no_mmap2) -# endif - { -# ifndef __ASSUME_MMAP2_SYSCALL - int saved_errno = errno; -# endif - void *result; - __ptrvalue (result) = (void *__unbounded) - INLINE_SYSCALL (mmap2, 6, __ptrvalue (addr), - len, prot, flags, fd, - (off_t) (offset >> MMAP2_PAGE_SHIFT)); -# if __BOUNDED_POINTERS__ - __ptrlow (result) = __ptrvalue (result); - __ptrhigh (result) = __ptrvalue (result) + len; -# endif -# ifndef __ASSUME_MMAP2_SYSCALL - if (result != MAP_FAILED || errno != ENOSYS) -# endif - return result; - -# ifndef __ASSUME_MMAP2_SYSCALL - __set_errno (saved_errno); - have_no_mmap2 = 1; -# endif - } #endif -#ifndef __ASSUME_MMAP2_SYSCALL - if (offset != (off_t) offset || (offset + len) != (off_t) (offset + len)) + if (offset & ((1 << page_shift) - 1)) { __set_errno (EINVAL); return MAP_FAILED; } - - return __mmap (addr, len, prot, flags, fd, (off_t) offset); + void *result; + __ptrvalue (result) = (void *__unbounded) + INLINE_SYSCALL (mmap2, 6, __ptrvalue (addr), + len, prot, flags, fd, + (off_t) (offset >> MMAP2_PAGE_SHIFT)); +#if __BOUNDED_POINTERS__ + __ptrlow (result) = __ptrvalue (result); + __ptrhigh (result) = __ptrvalue (result) + len; #endif + return result; } weak_alias (__mmap64, mmap64) diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/mmap.S b/sysdeps/unix/sysv/linux/s390/s390-32/mmap.S index 6e5ba94..0357ab4 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/mmap.S +++ b/sysdeps/unix/sysv/linux/s390/s390-32/mmap.S @@ -1,4 +1,4 @@ -/* Copyright (C) 2000, 2001, 2007 Free Software Foundation, Inc. +/* Copyright (C) 2000-2012 Free Software Foundation, Inc. Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com). This file is part of the GNU C Library. @@ -40,8 +40,8 @@ ENTRY(__mmap) cfi_adjust_cfa_offset (120) st %r1,0(%r15) /* store back chain */ - /* Store parameters on stack, because old_mmap/mmap2 - * take only one parameter: a pointer to the parameter area + /* Store parameters on stack, because mmap2 + * takes only one parameter: a pointer to the parameter area */ st %r6,0x70(%r15) /* Store 'fd'. */ st %r5,0x6C(%r15) /* Store 'flags'. */ @@ -50,10 +50,6 @@ ENTRY(__mmap) st %r2,0x60(%r15) /* Store 'start'. */ l %r1,216(%r15) /* Load offset. */ -#ifdef __ASSUME_MMAP2_SYSCALL - /* I don't think it is worthwhile trying to use mmap2 whenever - * it is available. Only use it when we are sure the syscall - * exists. */ tml %r1,0x0fff /* Offset page aligned ? */ lhi %r2,-EINVAL jnz 1f /* No -> EINVAL. */ @@ -61,11 +57,6 @@ ENTRY(__mmap) st %r1,0x74(%r15) /* Store page offset. */ la %r2,0x60(%r15) /* Load address of parameter list. */ svc SYS_ify(mmap2) /* Do the system call trap. */ -#else - st %r1,0x74(%r15) /* Store offset unmodified. */ - la %r2,0x60(%r15) /* Load address of parameter list. */ - svc SYS_ify(mmap) /* Do the system call trap. */ -#endif 1: l %r15,0(%r15) /* Load back chain. */ cfi_adjust_cfa_offset (-120) diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/mmap64.S b/sysdeps/unix/sysv/linux/s390/s390-32/mmap64.S index ad6d254..8b4bd45 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/mmap64.S +++ b/sysdeps/unix/sysv/linux/s390/s390-32/mmap64.S @@ -1,4 +1,4 @@ -/* Copyright (C) 2000, 2001, 2007 Free Software Foundation, Inc. +/* Copyright (C) 2000-2012 Free Software Foundation, Inc. Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com). This file is part of the GNU C Library. @@ -41,15 +41,14 @@ ENTRY(__mmap64) cfi_adjust_cfa_offset (120) st %r1,0(%r15) /* Store back chain. */ - /* Store parameters on stack, because mmap2 and old_mmap - * take only one parameter: a pointer to the parameter area. */ + /* Store parameters on stack, because mmap2 + * takes only one parameter: a pointer to the parameter area. */ st %r6,0x70(%r15) /* Store 'fd'. */ st %r5,0x6C(%r15) /* Store 'flags'. */ st %r4,0x68(%r15) /* Store 'prot'. */ st %r3,0x64(%r15) /* Store 'length'. */ st %r2,0x60(%r15) /* Store 'start'. */ -#ifdef __NR_mmap2 lm %r0,%r1,216(%r15) /* Load 64 bit offset. */ tml %r1,0x0fff /* Offset page aligned ? */ jnz 2f /* No -> EINVAL. */ @@ -61,11 +60,6 @@ ENTRY(__mmap64) la %r2,0x60(%r15) /* Load address of parameter list. */ svc SYS_ify(mmap2) /* Do the system call trap. */ -#ifndef __ASSUME_MMAP2_SYSCALL - chi %r2,-ENOSYS - je 1f -#endif - l %r15,0(%r15) /* Load back chain. */ cfi_adjust_cfa_offset (-120) lm %r6,%r15,24(%r15) /* Load registers. */ @@ -78,31 +72,6 @@ ENTRY(__mmap64) /* Successful; return the syscall's value. */ br %r14 -#endif - -#if !defined __ASSUME_MMAP2_SYSCALL || !defined __NR_mmap2 -1: lm %r0,%r1,216(%r15) /* Load 64 bit offset. */ - st %r1,0x74(%r15) /* Store lower word of offset. */ - ltr %r0,%r0 /* Offset > 2^32 ? */ - jnz 2f - alr %r1,%r3 /* Add length to offset. */ - brc 3,2f /* Carry -> EINVAL. */ - - la %r2,0x60(%r15) /* Load address of parameter list. */ - svc SYS_ify(mmap) /* Do the system call trap. */ - - l %r15,0(%r15) /* Load back chain. */ - lm %r6,%r15,24(%r15) /* Load registers. */ - - /* Check gpr 2 for error. */ - lhi %r0,-4096 - clr %r2,%r0 - jnl SYSCALL_ERROR_LABEL - - /* Successful; return the syscall's value. */ - br %r14 -#endif - 2: lhi %r2,-EINVAL l %r15,0(%r15) /* Load back chain. */ lm %r6,%r15,24(%r15) /* Load registers. */ -- Joseph S. Myers joseph@codesourcery.com