aboutsummaryrefslogtreecommitdiff
path: root/shm.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2023-10-12 14:35:37 +0000
committerDaniel Eklöf <daniel@ekloef.se>2023-10-12 14:35:37 +0000
commitee7e6e7234d559f3e4713f5eeabd6d50dbe91fa6 (patch)
treeba21afc3b880e2a1c22c789f74616c5a2d77edbe /shm.c
parentmeson: bump version to 1.16.0 (diff)
parentrender: fix surface damage when rendering sixels. (diff)
Merge branch 'master' into releases/1.16
Diffstat (limited to 'shm.c')
-rw-r--r--shm.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/shm.c b/shm.c
index 8ca0ead0..171459f6 100644
--- a/shm.c
+++ b/shm.c
@@ -27,10 +27,8 @@
#define MAP_UNINITIALIZED 0
#endif
-#if defined(MFD_NOEXEC_SEAL)
- #define FOOT_MFD_FLAGS (MFD_CLOEXEC | MFD_ALLOW_SEALING | MFD_NOEXEC_SEAL)
-#else
- #define FOOT_MFD_FLAGS (MFD_CLOEXEC | MFD_ALLOW_SEALING)
+#if !defined(MFD_NOEXEC_SEAL)
+ #define MFD_NOEXEC_SEAL 0
#endif
#define TIME_SCROLL 0
@@ -339,7 +337,20 @@ get_new_buffers(struct buffer_chain *chain, size_t count,
/* Backing memory for SHM */
#if defined(MEMFD_CREATE)
- pool_fd = memfd_create("foot-wayland-shm-buffer-pool", FOOT_MFD_FLAGS);
+ /*
+ * Older kernels reject MFD_NOEXEC_SEAL with EINVAL. Try first
+ * *with* it, and if that fails, try again *without* it.
+ */
+ errno = 0;
+ pool_fd = memfd_create(
+ "foot-wayland-shm-buffer-pool",
+ MFD_CLOEXEC | MFD_ALLOW_SEALING | MFD_NOEXEC_SEAL);
+
+ if (pool_fd < 0 && errno == EINVAL) {
+ pool_fd = memfd_create(
+ "foot-wayland-shm-buffer-pool", MFD_CLOEXEC | MFD_ALLOW_SEALING);
+ }
+
#elif defined(__FreeBSD__)
// memfd_create on FreeBSD 13 is SHM_ANON without sealing support
pool_fd = shm_open(SHM_ANON, O_RDWR | O_CLOEXEC, 0600);