public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Extend mmap/mprotect API to specify the max page
@ 2019-09-25  7:03 Sebastian Huber
  0 siblings, 0 replies; only message in thread
From: Sebastian Huber @ 2019-09-25  7:03 UTC (permalink / raw)
  To: newlib-cvs

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=e94d2a0f8bff63c2a544f31cdc81891b8d6e1a95

commit e94d2a0f8bff63c2a544f31cdc81891b8d6e1a95
Author: brooks <brooks@FreeBSD.org>
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.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-09-25  7:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-25  7:03 [newlib-cygwin] Extend mmap/mprotect API to specify the max page Sebastian Huber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).