mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-13 04:10:13 +00:00
wayland: fix error handling for memfd_create
We currently use syscall() directly to invoke memfd_create, since the function isn't available in libc headers yet. The code, though, mishandles how errors are passed from syscall(). It assumes syscall returns the error code directly (but negative), when in fact, syscall() uses errno. Also, the code fails to retry on EINTR. This commit moves the handling of memfd create to a helper function, and changes the code to use errno and handle EINTR. https://bugzilla.gnome.org/show_bug.cgi?id=766341
This commit is contained in:
parent
080fdfa7f9
commit
bb2ca3b94d
@ -1104,6 +1104,23 @@ typedef struct _GdkWaylandCairoSurfaceData {
|
||||
uint32_t scale;
|
||||
} GdkWaylandCairoSurfaceData;
|
||||
|
||||
static int
|
||||
open_shared_memory (void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
do
|
||||
{
|
||||
ret = syscall (__NR_memfd_create, "gdk-wayland", MFD_CLOEXEC);
|
||||
}
|
||||
while (ret < 0 && errno == EINTR);
|
||||
|
||||
if (ret < 0)
|
||||
g_critical (G_STRLOC ": creating shared memory file failed: %m");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct wl_shm_pool *
|
||||
create_shm_pool (struct wl_shm *shm,
|
||||
int size,
|
||||
@ -1111,19 +1128,13 @@ create_shm_pool (struct wl_shm *shm,
|
||||
void **data_out)
|
||||
{
|
||||
struct wl_shm_pool *pool;
|
||||
int ret, fd;
|
||||
int fd;
|
||||
void *data;
|
||||
|
||||
ret = syscall (__NR_memfd_create, "gdk-wayland", MFD_CLOEXEC);
|
||||
fd = open_shared_memory ();
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
g_critical (G_STRLOC ": creating shared memory file failed: %s",
|
||||
g_strerror (-ret));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fd = ret;
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
|
||||
if (ftruncate (fd, size) < 0)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user