about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSzabolcs Nagy <szabolcs.nagy@arm.com>2022-10-24 15:29:58 +0100
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2022-10-26 15:32:01 +0100
commitdac0b184e7affbcdb11c3bfaef7d03bf3b0bfe28 (patch)
tree5d23180de7ac5a9098f0d51e9a0b672b2f5faf34
parent28f19db3b85abd039734b55b29acc22897b88302 (diff)
downloadglibc-dac0b184e7affbcdb11c3bfaef7d03bf3b0bfe28.tar.gz
glibc-dac0b184e7affbcdb11c3bfaef7d03bf3b0bfe28.tar.xz
glibc-dac0b184e7affbcdb11c3bfaef7d03bf3b0bfe28.zip
TODO(uapi): mmap perm emulation
-rw-r--r--sysdeps/unix/sysv/linux/mmap64.c17
1 files changed, 17 insertions, 0 deletions
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;