Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorChristian Rauch <Rauch.Christian@gmx.de>2021-07-13 01:28:41 +0300
committerChristian Rauch <Rauch.Christian@gmx.de>2021-07-15 01:15:00 +0300
commit4e65b1ef6cdaa0fbe6bac1d1f4a54da4d3247584 (patch)
treec6f56ad0fa4f4a16a9898130690728eb9e121382 /intern
parentebf7673f83aea30dc126f0997c9c6f42f2cf5d9e (diff)
GHOST/wayland: create mmap-ed file manually if memfd_create is unavailable
Diffstat (limited to 'intern')
-rw-r--r--intern/ghost/CMakeLists.txt7
-rw-r--r--intern/ghost/intern/GHOST_SystemWayland.cpp34
2 files changed, 39 insertions, 2 deletions
diff --git a/intern/ghost/CMakeLists.txt b/intern/ghost/CMakeLists.txt
index a35c9fffcab..76cac1049fb 100644
--- a/intern/ghost/CMakeLists.txt
+++ b/intern/ghost/CMakeLists.txt
@@ -288,6 +288,13 @@ elseif(WITH_GHOST_X11 OR WITH_GHOST_WAYLAND)
${dbus_INCLUDE_DIRS}
)
+ include(CheckSymbolExists)
+ set(CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
+ check_symbol_exists(memfd_create "sys/mman.h" HAVE_MEMFD_CREATE)
+ if (HAVE_MEMFD_CREATE)
+ add_definitions(-DHAVE_MEMFD_CREATE)
+ endif()
+
list(APPEND SRC
intern/GHOST_SystemWayland.cpp
intern/GHOST_WindowWayland.cpp
diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp
index 75a80de983d..38700845405 100644
--- a/intern/ghost/intern/GHOST_SystemWayland.cpp
+++ b/intern/ghost/intern/GHOST_SystemWayland.cpp
@@ -1804,13 +1804,43 @@ GHOST_TSuccess GHOST_SystemWayland::setCustomCursorShape(uint8_t *bitmap,
static const int32_t stride = sizex * 4; /* ARGB */
cursor->file_buffer->size = size_t(stride * sizey);
+#ifdef HAVE_MEMFD_CREATE
const int fd = memfd_create("blender-cursor-custom", MFD_CLOEXEC | MFD_ALLOW_SEALING);
- fcntl(fd, F_ADD_SEALS, F_SEAL_SHRINK);
- posix_fallocate(fd, 0, int32_t(cursor->file_buffer->size));
+ if (fd >= 0) {
+ fcntl(fd, F_ADD_SEALS, F_SEAL_SHRINK | F_SEAL_SEAL);
+ }
+#else
+ char *path = getenv("XDG_RUNTIME_DIR");
+ if (!path) {
+ errno = ENOENT;
+ return GHOST_kFailure;
+ }
+
+ char *tmpname;
+ asprintf(&tmpname, "%s/%s", path, "blender-XXXXXX");
+ const int fd = mkostemp(tmpname, O_CLOEXEC);
+ if (fd >= 0) {
+ unlink(tmpname);
+ }
+ free(tmpname);
+#endif
+
+ if (fd < 0) {
+ return GHOST_kFailure;
+ }
+
+ if (posix_fallocate(fd, 0, int32_t(cursor->file_buffer->size)) != 0) {
+ return GHOST_kFailure;
+ }
cursor->file_buffer->data = mmap(
nullptr, cursor->file_buffer->size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ if (cursor->file_buffer->data == MAP_FAILED) {
+ close(fd);
+ return GHOST_kFailure;
+ }
+
struct wl_shm_pool *pool = wl_shm_create_pool(d->shm, fd, int32_t(cursor->file_buffer->size));
wl_buffer *buffer = wl_shm_pool_create_buffer(