diff mbox

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

Message ID 20170621231613.20619-2-eric@engestrom.ch (mailing list archive)
State New, archived
Headers show

Commit Message

Eric Engestrom June 21, 2017, 11:16 p.m. UTC
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@chris-wilson.co.uk>
Signed-off-by: Eric Engestrom <eric@engestrom.ch>
---
 xf86drm.h | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
diff mbox

Patch

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);