public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Szabolcs Nagy <nsz@sourceware.org>
To: glibc-cvs@sourceware.org
Subject: [glibc/arm/morello/main] TODO(uapi): mmap perm emulation
Date: Wed, 26 Oct 2022 14:48:58 +0000 (GMT)	[thread overview]
Message-ID: <20221026144859.E53663854811@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=dac0b184e7affbcdb11c3bfaef7d03bf3b0bfe28

commit dac0b184e7affbcdb11c3bfaef7d03bf3b0bfe28
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Mon Oct 24 15:29:58 2022 +0100

    TODO(uapi): mmap perm emulation

Diff:
---
 sysdeps/unix/sysv/linux/mmap64.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/sysdeps/unix/sysv/linux/mmap64.c b/sysdeps/unix/sysv/linux/mmap64.c
index 60da02939d..a7bd396880 100644
--- a/sysdeps/unix/sysv/linux/mmap64.c
+++ b/sysdeps/unix/sysv/linux/mmap64.c
@@ -22,6 +22,9 @@
 #include <sysdep.h>
 #include <ldsodefs.h>
 #include <mmap_internal.h>
+#ifdef __CHERI_PURE_CAPABILITY__
+# include <cheri_perms.h>
+#endif
 
 #ifdef __NR_mmap2
 /* To avoid silent truncation of offset when using mmap2, do not accept
@@ -64,6 +67,20 @@ __mmap64 (void *addr, size_t len, int prot, int flags, int fd, off64_t offset)
     {
       size_t ps = GLRO(dl_pagesize);
       ret = __builtin_cheri_bounds_set (ret, (len + ps - 1) & -ps);
+      unsigned long mask = CAP_PERM_MASK_BASE;
+      if (prot & PROT_READ)
+	mask |= CAP_PERM_MASK_R;
+      if (prot & PROT_WRITE)
+	mask |= CAP_PERM_MASK_RW;
+      if (prot & PROT_EXEC)
+	mask |= CAP_PERM_MASK_RX;
+      if (prot & PROT_MAX (PROT_READ))
+	mask |= CAP_PERM_MASK_R;
+      if (prot & PROT_MAX (PROT_WRITE))
+	mask |= CAP_PERM_MASK_RW;
+      if (prot & PROT_MAX (PROT_EXEC))
+	mask |= CAP_PERM_MASK_RX;
+      ret = __builtin_cheri_perms_and (ret, mask);
     }
 #endif
   return ret;

                 reply	other threads:[~2022-10-26 14:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221026144859.E53663854811@sourceware.org \
    --to=nsz@sourceware.org \
    --cc=glibc-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).