[PATCH libdrm 2/2] xf86drm: introduce drmIoctl2()

Eric Engestrom eric at engestrom.ch
Wed Jun 21 23:16:13 UTC 2017


Basically ripped off of [1] by Chris Wilson, which I thought should live
in libdrm too (even though it's needed in Mesa anyway).

[1] https://lists.freedesktop.org/archives/mesa-dev/2017-June/159894.html

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
Signed-off-by: Eric Engestrom <eric at engestrom.ch>
---
 xf86drm.h | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/xf86drm.h b/xf86drm.h
index aeed543f..eb75b944 100644
--- a/xf86drm.h
+++ b/xf86drm.h
@@ -38,6 +38,9 @@
 #include <sys/types.h>
 #include <stdint.h>
 #include <drm.h>
+#if defined(__linux__) && defined(__GNUC__) && defined (__x86_64__)
+#include <sys/syscall.h>
+#endif
 #include <sys/ioctl.h>
 #include <errno.h>
 
@@ -135,6 +138,30 @@ drmIoctl(int fd, unsigned long request, void *arg)
     return ret;
 }
 
+/**
+ * Call ioctl, restarting if it is interupted, and return the error.
+ */
+static inline int
+drmIoctl2(int fd, unsigned long request, void *arg)
+{
+    int result;
+
+    do {
+#if defined(__linux__) && defined(__GNUC__) && defined (__x86_64__)
+        __asm__("syscall"
+                : "=a" (result)
+                : "0" (__NR_ioctl), "D" (fd), "S" (request), "d" (arg)
+                : "cc", "rcx", "r11", "memory");
+#else
+        result = ioctl(fd, request, arg);
+        if (result == -1)
+            result = -errno;
+#endif
+    } while (result == -EINTR || result == -EAGAIN);
+
+    return result;
+}
+
 extern void *drmGetHashTable(void);
 extern drmHashEntry *drmGetEntry(int fd);
 
-- 
Cheers,
  Eric



More information about the dri-devel mailing list