Page MenuHome

GHOST/wayland: create temporary file manually for older kernel versions
ClosedPublic

Authored by Christian Rauch (christian.rauch) on Jul 13 2021, 1:04 AM.

Details

Summary

Kernels below version 3.17 do not support the memfd_create syscall for creating temporary anonymous files. For those kernels we have to manually create a temporary file and delete it.

Diff Detail

Repository
rB Blender
Branch
wl_tmpfile
Build Status
Buildable 15809
Build 15809: arc lint + arc unit

Event Timeline

Christian Rauch (christian.rauch) created this revision.
Brecht Van Lommel (brecht) requested changes to this revision.Jul 13 2021, 1:59 PM
Brecht Van Lommel (brecht) added inline comments.
intern/ghost/intern/GHOST_SystemWayland.cpp
1807

Not sure it's worth having Linux-specific code at all, especially if we want to have this running on BSDs as well eventually.

1811

getenv("XDG_RUNTIME_DIR") can return NULL, needs to be checked.

1836–1837

Handle mmap failure, and close fd in that case.

This revision now requires changes to proceed.Jul 13 2021, 1:59 PM
Christian Rauch (christian.rauch) added inline comments.
intern/ghost/intern/GHOST_SystemWayland.cpp
1807

I don't think it is worth bothering about BSD until it is seriously considered to replace X11 for them and there is at least one distribution that makes use of Wayland by default. Further to this, I have no way (and interest) in testing this on BSD. Someone else has to provide the patches and test this on BSD with Wayland.

intern/ghost/intern/GHOST_SystemWayland.cpp
1807

Not expecting anyone to test this on BSD soon. But I just don't see the benefit in keeping the Linux-specific code when we now have a portable alternative.

Christian Rauch (christian.rauch) added inline comments.
intern/ghost/intern/GHOST_SystemWayland.cpp
1807

This mkostemp + unlink is just a workaround, not identical behaviour.

From https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/4:

This (so-far) Linux-only API lets users create file descriptors purely

in memory, without any backing file on the filesystem and the race
condition which could ensue when unlink()ing it.

It is Linux specific API, but it was created for a reason. The HAVE_MEMFD_CREATE solution in this pull request is actually a much better (portable) solution compared to my kernel version comparison. I am going to use this one too.

Christian Rauch (christian.rauch) added inline comments.
intern/ghost/intern/GHOST_SystemWayland.cpp
1807

I cannot change my comment (and I cannot preview the formatting), but this is the fixed citation from the PR that justifies the use of memfd_create:

This (so-far) Linux-only API lets users create file descriptors purely in memory, without any backing file on the filesystem and the race

condition which could ensue when unlink()ing it.

intern/ghost/intern/GHOST_SystemWayland.cpp
1807

Ok, one last try:

This (so-far) Linux-only API lets users create file descriptors purely in memory, without any backing file on the filesystem and the race condition which could ensue when unlink()ing it.

I really don't like this Blender review system :-)

check for memfd_create directly

I am checking for memfd_create directly now and added various other fixes.

This revision is now accepted and ready to land.Jul 14 2021, 6:28 PM

Merged with commit 4e65b1ef6cdaa0fbe6bac1d1f4a54da4d3247584.