/* Reserve the memory region. If we cannot create the mapping,
there is no reason to set up the backing file. */
- void *target = mmap (NULL, total_size, PROT_NONE,
+ void *target = mmap (NULL, total_size, PROT_NONE | PROT_MAX_RW,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (target == MAP_FAILED)
return (struct support_blob_repeat) { 0 };
so we know they are allocated. */
void *alloc_base = xmmap (0,
alloc_size,
- PROT_NONE,
+ PROT_NONE|PROT_MAX_RW,
MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE|MAP_STACK,
-1);
/* Some architecture still requires executable stack for the signal return
#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/mman.h>
#include <unistd.h>
__BEGIN_DECLS
/* Write the buffer. Retry on short writes. */
void xwrite (int, const void *, size_t);
+/* On CHERI targets ensure the mmap returned capability has RW permissions. */
+#ifdef PROT_MAX
+# define PROT_MAX_RW PROT_MAX (PROT_READ | PROT_WRITE)
+#else
+# define PROT_MAX_RW 0
+#endif
+
/* Invoke mmap with a zero file offset. */
void *xmmap (void *addr, size_t length, int prot, int flags, int fd);
void xmprotect (void *addr, size_t length, int prot);
/* pkey_mprotect with key -1 should work even when there is no
protection key support. */
{
- int *page = xmmap (NULL, pagesize, PROT_NONE,
+ int *page = xmmap (NULL, pagesize, PROT_NONE | PROT_MAX_RW,
MAP_ANONYMOUS | MAP_PRIVATE, -1);
TEST_COMPARE (pkey_mprotect (page, pagesize, PROT_READ | PROT_WRITE, -1),
0);