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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxxx>
Signed-off-by: Eric Engestrom <eric@xxxxxxxxxxxx>
---
 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

_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux