From b732f86998e39ca8714330f487804428b54c481c Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
Date: Wed, 8 Jan 2025 16:52:03 +0100
Subject: [PATCH 14/14] linux: support EVIOCGRAB ioctl

EVIOCGRAB just takes an int argument.

https://bugs.kde.org/show_bug.cgi?id=498143

(cherry picked from commit 59eb5a4af60d4beb2c6910a1fa6cdf8d1f3a56f2)
---
 NEWS                                | 1 +
 coregrind/m_syswrap/syswrap-linux.c | 4 ++++
 include/vki/vki-linux.h             | 3 +++
 3 files changed, 8 insertions(+)

diff --git a/NEWS b/NEWS
index 2fb8ce5c724b..7f9e005c59f4 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,7 @@ The following bugs have been fixed or resolved on this branch.
 497130  Recognize new DWARF5 DW_LANG constants
 498317  FdBadUse is not a valid CoreError type in a suppression
         even though it's generated by --gen-suppressions=yes
+498143  False positive on EVIOCGRAB ioctl
 
 To see details of a given bug, visit
   https://bugs.kde.org/show_bug.cgi?id=XXXXXX
diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c
index 57672f167126..87ab82e6e342 100644
--- a/coregrind/m_syswrap/syswrap-linux.c
+++ b/coregrind/m_syswrap/syswrap-linux.c
@@ -10397,6 +10397,10 @@ PRE(sys_ioctl)
       break;
    }
 
+   case VKI_EVIOCGRAB:
+	/* This just takes an int argument. */
+	break;
+
    default:
       /* EVIOC* are variable length and return size written on success */
       switch (ARG2 & ~(_VKI_IOC_SIZEMASK << _VKI_IOC_SIZESHIFT)) {
diff --git a/include/vki/vki-linux.h b/include/vki/vki-linux.h
index 006f16d92201..d4e1908e1e9c 100644
--- a/include/vki/vki-linux.h
+++ b/include/vki/vki-linux.h
@@ -3226,6 +3226,9 @@ struct vki_getcpu_cache {
 
 #define VKI_EVIOCGBIT(ev,len)	_VKI_IOC(_VKI_IOC_READ, 'E', 0x20 + ev, len)	/* get event bits */
 
+#define VKI_EVIOCGRAB		_VKI_IOW('E', 0x90, int)
+/* grab device */
+
 /*
  * Event types
  */
-- 
2.47.1