From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 108701 invoked by alias); 25 Sep 2019 07:03:31 -0000 Mailing-List: contact newlib-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-cvs-owner@sourceware.org Received: (qmail 108682 invoked by uid 10080); 25 Sep 2019 07:03:30 -0000 Date: Wed, 25 Sep 2019 07:03:00 -0000 Message-ID: <20190925070330.108681.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Sebastian Huber To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] Extend mmap/mprotect API to specify the max page X-Act-Checkin: newlib-cygwin X-Git-Author: brooks X-Git-Refname: refs/heads/master X-Git-Oldrev: 17baf5e3909ecc0a25fec7a06637d5347f509cde X-Git-Newrev: e94d2a0f8bff63c2a544f31cdc81891b8d6e1a95 X-SW-Source: 2019-q3/txt/msg00038.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=e94d2a0f8bff63c2a544f31cdc81891b8d6e1a95 commit e94d2a0f8bff63c2a544f31cdc81891b8d6e1a95 Author: brooks Date: Thu Jun 20 18:24:16 2019 +0000 Extend mmap/mprotect API to specify the max page protections. A new macro PROT_MAX() alters a protection value so it can be OR'd with a regular protection value to specify the maximum permissions. If present, these flags specify the maximum permissions. While these flags are non-portable, they can be used in portable code with simple ifdefs to expand PROT_MAX() to 0. This change allows (e.g.) a region that must be writable during run-time linking or JIT code generation to be made permanently read+execute after writes are complete. This complements W^X protections allowing more precise control by the programmer. This change alters mprotect argument checking and returns an error when unhandled protection flags are set. This differs from POSIX (in that POSIX only specifies an error), but is the documented behavior on Linux and more closely matches historical mmap behavior. In addition to explicit setting of the maximum permissions, an experimental sysctl vm.imply_prot_max causes mmap to assume that the initial permissions requested should be the maximum when the sysctl is set to 1. PROT_NONE mappings are excluded from this for compatibility with rtld and other consumers that use such mappings to reserve address space before mapping contents into part of the reservation. A final version this is expected to provide per-binary and per-process opt-in/out options and this sysctl will go away in its current form. As such it is undocumented. Reviewed by: emaste, kib (prior version), markj Additional suggestions from: alc Obtained from: CheriBSD Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D18880 Diff: --- newlib/libc/sys/rtems/include/sys/mman.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/newlib/libc/sys/rtems/include/sys/mman.h b/newlib/libc/sys/rtems/include/sys/mman.h index f74f473..4ac4f34 100644 --- a/newlib/libc/sys/rtems/include/sys/mman.h +++ b/newlib/libc/sys/rtems/include/sys/mman.h @@ -29,7 +29,7 @@ * SUCH DAMAGE. * * @(#)mman.h 8.2 (Berkeley) 1/9/95 - * $FreeBSD: head/sys/sys/mman.h 326023 2017-11-20 19:43:44Z pfg $ + * $FreeBSD: head/sys/sys/mman.h 349240 2019-06-20 18:24:16Z brooks $ */ #ifndef _SYS_MMAN_H_ @@ -55,6 +55,14 @@ #define PROT_READ 0x01 /* pages can be read */ #define PROT_WRITE 0x02 /* pages can be written */ #define PROT_EXEC 0x04 /* pages can be executed */ +#if __BSD_VISIBLE +#define _PROT_ALL (PROT_READ | PROT_WRITE | PROT_EXEC) +#define PROT_EXTRACT(prot) ((prot) & _PROT_ALL) + +#define _PROT_MAX_SHIFT 16 +#define PROT_MAX(prot) ((prot) << _PROT_MAX_SHIFT) +#define PROT_MAX_EXTRACT(prot) (((prot) >> _PROT_MAX_SHIFT) & _PROT_ALL) +#endif /* * Flags contain sharing type and options.