From patchwork Fri Dec 11 19:26:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 9988 Received: (qmail 74889 invoked by alias); 11 Dec 2015 19:26:32 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 74875 invoked by uid 89); 11 Dec 2015 19:26:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-ob0-f176.google.com MIME-Version: 1.0 X-Received: by 10.182.79.200 with SMTP id l8mr16135691obx.18.1449861987581; Fri, 11 Dec 2015 11:26:27 -0800 (PST) In-Reply-To: <566B01BE.1070703@linaro.org> References: <20151211143706.GA7868@intel.com> <566AF894.4060300@linaro.org> <566B01BE.1070703@linaro.org> Date: Fri, 11 Dec 2015 11:26:27 -0800 Message-ID: Subject: Re: [PATCH] Add Prefer_MAP_32BIT_EXEC for Silvermont From: "H.J. Lu" To: Adhemerval Zanella Cc: GNU C Library On Fri, Dec 11, 2015 at 9:02 AM, Adhemerval Zanella wrote: > > > On 11-12-2015 14:40, H.J. Lu wrote: >> On Fri, Dec 11, 2015 at 8:23 AM, Adhemerval Zanella >> wrote: >>> >>> >>> On 11-12-2015 13:59, H.J. Lu wrote: >>>> On Fri, Dec 11, 2015 at 7:39 AM, Joseph Myers wrote: >>>>>> On Fri, 11 Dec 2015, H.J. Lu wrote: >>>>>> >>>>>>>> +++ b/sysdeps/unix/sysv/linux/x86_64/64/mmap.c >>>>>>>> @@ -0,0 +1,49 @@ >>>>>>>> +/* Copyright (C) 2015 Free Software Foundation, Inc. >>>>>> >>>>>> All new files should have a descriptive first line before the copyright >>>>>> notice. >>>>>> >>>> Here is the updated patch. >>> >>>> >>>> diff --git a/sysdeps/unix/sysv/linux/x86_64/64/mmap.c b/sysdeps/unix/sysv/linux/x86_64/64/mmap.c >>>> new file mode 100644 >>>> index 0000000..c34f633 >>>> --- /dev/null >>>> +++ b/sysdeps/unix/sysv/linux/x86_64/64/mmap.c >>> >>>> + >>>> +__ptr_t >>>> +__mmap (__ptr_t addr, size_t len, int prot, int flags, int fd, off_t offset) >>>> +{ >>>> + /* If the Prefer_MAP_32BIT_EXEC bit is set, try to map executable pages >>>> + with MAP_32BIT first. */ >>>> + if (addr == NULL >>>> + && (prot & PROT_EXEC) != 0 >>>> + && HAS_ARCH_FEATURE (Prefer_MAP_32BIT_EXEC)) >>>> + { >>>> + addr = (__ptr_t) INLINE_SYSCALL (mmap, 6, addr, len, prot, >>>> + flags | MAP_32BIT, >>>> + fd, offset); >>>> + if (addr != MAP_FAILED) >>>> + return addr; >>>> + } >>>> + return (__ptr_t) INLINE_SYSCALL (mmap, 6, addr, len, prot, flags, >>>> + fd, offset); >>>> +} >>>> + >>> >>> I would advise not add another syscall variant implementation, but rather >>> work on make a generic implementation with adjustments made by each platform. >>> Something like >>> >>> __ptr_t >>> __mmap (__ptr_t addr, size_t len, int prot, int flags, int fd, off_t offset) >>> { >>> flags = MMAP_ARCH_FLAGS (flags); >>> return (__ptr_t) INLINE_SYSCALL( mmap, 6, addr, len, prot, flags, fd, offset); >>> } >>> >>> And then define MMAP_ARCH_FLAG for x86 to add the MAP_32BIT when required. >>> >> >> This won't work here since we fallback to the default mmap when >> MAP_32BIT fails. > > So just change the MMAP_ARCH_FLAGS hook to something like: > > __ptr_t ret = __mmap_arch (addr, len, prot, flags, fd, offset)); > if (ret != MAP_FAILED) > ret = INLINE_SYSCALL (mmap, 6, addr, len, prot, flags, fd, offset); > return ret > > The default value for __mmap_arch could be a constant value so compiler > could remove the the comparison if it is the case. How about this? diff --git a/sysdeps/unix/sysv/linux/wordsize-64/mmap.c b/sysdeps/unix/sysv/linux/wordsize-64/mmap.c new file mode 100644 index 0000000..e098976 --- /dev/null +++ b/sysdeps/unix/sysv/linux/wordsize-64/mmap.c @@ -0,0 +1,40 @@ +/* Linux mmap system call. 64-bit version. + Copyright (C) 2015 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 + modify it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + +/* An architecture may override this. */ +#ifndef MMAP_PREPARE +# define MMAP_PREPARE(addr, len, prot, flags, fd, offset) +#endif + +__ptr_t +__mmap (__ptr_t addr, size_t len, int prot, int flags, int fd, off_t offset) +{ + MMAP_PREPARE (addr, len, prot, flags, fd, offset); + return (__ptr_t) INLINE_SYSCALL (mmap, 6, addr, len, prot, flags, + fd, offset); +} + +weak_alias (__mmap, mmap) +weak_alias (__mmap, mmap64) +weak_alias (__mmap, __mmap64) diff --git a/sysdeps/unix/sysv/linux/x86_64/64/mmap.c b/sysdeps/unix/sysv/linux/x86_64/64/mmap.c new file mode 100644 index 0000000..031316c --- /dev/null +++ b/sysdeps/unix/sysv/linux/x86_64/64/mmap.c @@ -0,0 +1,37 @@ +/* Linux mmap system call. x86-64 version. + Copyright (C) 2015 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 + modify it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +/* If the Prefer_MAP_32BIT_EXEC bit is set, try to map executable pages + with MAP_32BIT first. */ +#define MMAP_PREPARE(addr, len, prot, flags, fd, offset) \ + if ((addr) == NULL \ + && ((prot) & PROT_EXEC) != 0 \ + && HAS_ARCH_FEATURE (Prefer_MAP_32BIT_EXEC)) \ + { \ + __ptr_t ret = (__ptr_t) INLINE_SYSCALL (mmap, 6, (addr), (len), \ + (prot), \ + (flags) | MAP_32BIT, \ + (fd), (offset)); \ + if (ret != MAP_FAILED) \ + return ret; \ + } + +#include