neuswc

patched neuswc library (tracked)
git clone https://git.daat.foo/neuswc.git
Log | Files | Refs | README | LICENSE

commit 3c4431b0ba7f9f685fa419aa812509bb38d7d048
parent 86a646272b2fde5426e5822c23c43a15d376ff0c
Author: shrub <maybeshrub@gmail.com>
Date:   Sun,  8 Feb 2026 00:45:35 +0000

handle sealed sh pool fd during resize

check the current fd size with fstat before ftruncate-ing. tolerate some
ftrunacate permission issues. this is to remedy issues that openBSD
compat patches were causing on linux.

Diffstat:
Mlibswc/shm.c | 18++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/libswc/shm.c b/libswc/shm.c @@ -34,6 +34,7 @@ #include <stdlib.h> #include <string.h> #include <sys/mman.h> +#include <sys/stat.h> #include <unistd.h> #include <wayland-server.h> #include <wld/pixman.h> @@ -159,12 +160,25 @@ resize(struct wl_client *client, struct wl_resource *resource, int32_t size) { struct pool *pool = wl_resource_get_user_data(resource); void *data; + struct stat st; - if (ftruncate(pool->fd, size) != 0) { - wl_resource_post_error(resource, WL_SHM_ERROR_INVALID_FD, "ftruncate failed: %s", strerror(errno)); + if (fstat(pool->fd, &st) != 0) { + wl_resource_post_error(resource, WL_SHM_ERROR_INVALID_FD, "fstat failed: %s", strerror(errno)); return; } + if (st.st_size < size) { + if (ftruncate(pool->fd, size) != 0) { + int saved = errno; + /* some clients seal memfd if size is already fine, allo */ + if ((saved == EPERM || saved == EACCES) && fstat(pool->fd, &st) == 0 && st.st_size >= size) { + goto remap; + } + wl_resource_post_error(resource, WL_SHM_ERROR_INVALID_FD, "ftruncate failed: %s", strerror(saved)); + return; + } + } +remap: data = swc_mremap(pool, pool->data, pool->size, size); if (data == MAP_FAILED) { wl_resource_post_error(resource, WL_SHM_ERROR_INVALID_FD, "mremap failed: %s", strerror(errno));