[PATCH 2/5] Add decoding for parametered ioctls

Gabriel Laskar gabriel at lse.epita.fr
Thu Jan 15 19:32:27 UTC 2015


Some ioctls from evdev, hiddev, mixer, uinput, spi and joystick are
parametered by a size or a number that is variable. These changes add
the display of these ones, and their parameters.

* defs.h: Declare new function ioctl_decode_number.
* io.c (sys_ioctl): Add call to ioctl_decode_number.
* ioctl.c (ioctl_decode_number): Implement this new function.

Signed-off-by: Gabriel Laskar <gabriel at lse.epita.fr>
---
 defs.h  |   1 +
 io.c    |  19 +++++++----
 ioctl.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 128 insertions(+), 7 deletions(-)

diff --git a/defs.h b/defs.h
index d0acb19..501464e 100644
--- a/defs.h
+++ b/defs.h
@@ -733,6 +733,7 @@ extern void print_loff_t(struct tcb *, long);
 extern const struct_ioctlent *ioctl_lookup(unsigned long);
 extern const struct_ioctlent *ioctl_next_match(const struct_ioctlent *);
 extern int ioctl_decode(struct tcb *, long, long);
+extern int ioctl_decode_number(unsigned long);
 extern int term_ioctl(struct tcb *, long, long);
 extern int sock_ioctl(struct tcb *, long, long);
 extern int proc_ioctl(struct tcb *, int, int);
diff --git a/io.c b/io.c
index 87bdbba..b7526bb 100644
--- a/io.c
+++ b/io.c
@@ -398,13 +398,18 @@ sys_ioctl(struct tcb *tcp)
 	if (entering(tcp)) {
 		printfd(tcp, tcp->u_arg[0]);
 		tprints(", ");
-		iop = ioctl_lookup(tcp->u_arg[1]);
-		if (iop) {
-			tprints(iop->symbol);
-			while ((iop = ioctl_next_match(iop)))
-				tprintf(" or %s", iop->symbol);
-		} else
-			tprintf("%#lx", tcp->u_arg[1]);
+
+		int ret = ioctl_decode_number(tcp->u_arg[1]);
+		if (!ret) {
+			iop = ioctl_lookup(tcp->u_arg[1]);
+			if (iop) {
+				tprints(iop->symbol);
+				while ((iop = ioctl_next_match(iop)))
+					tprintf(" or %s", iop->symbol);
+			} else {
+				tprintf("%#lx", tcp->u_arg[1]);
+			}
+		}
 		ioctl_decode(tcp, tcp->u_arg[1], tcp->u_arg[2]);
 	}
 	else {
diff --git a/ioctl.c b/ioctl.c
index cfd5a24..050ec28 100644
--- a/ioctl.c
+++ b/ioctl.c
@@ -70,6 +70,121 @@ ioctl_next_match(const struct_ioctlent *iop)
 }
 
 int
+evdev_decode_number(unsigned long arg)
+{
+	unsigned long nr = _IOC_NR(arg);
+
+	if (nr >= 0x20 && nr <= 0x20 + 0x1f) {
+		tprintf("EVIOCGBIT(ev=%lu, len=%lu)", nr - 0x20, _IOC_SIZE(arg));
+		return 1;
+	} else if (nr >= 0x40 && nr <= 0x40 + 0x3f) {
+		tprintf("EVIOCGABS(abs=%lu)", nr - 0x40);
+		return 1;
+	} else if (nr >= 0xc0 && nr <= 0xc0 + 0x3f) {
+		tprintf("EVIOCSABS(abs=%lu)", nr - 0xc0);
+		return 1;
+	}
+
+	switch (_IOC_NR(nr)) {
+		case 0x06:
+			tprintf("EVIOCGNAME(len=%lu)", _IOC_SIZE(arg));
+			return 1;
+		case 0x07:
+			tprintf("EVIOCGPHYS(len=%lu)", _IOC_SIZE(arg));
+			return 1;
+		case 0x08:
+			tprintf("EVIOCGUNIQ(len=%lu)", _IOC_SIZE(arg));
+			return 1;
+		case 0x09:
+			tprintf("EVIOCGPROP(len=%lu)", _IOC_SIZE(arg));
+			return 1;
+		case 0x0a:
+			tprintf("EVIOCGMTSLOTS(len=%lu)", _IOC_SIZE(arg));
+			return 1;
+		case 0x18:
+			tprintf("EVIOCGKEY(len=%lu)", _IOC_SIZE(arg));
+			return 1;
+		case 0x19:
+			tprintf("EVIOCGLED(len=%lu)", _IOC_SIZE(arg));
+			return 1;
+		case 0x1a:
+			tprintf("EVIOCGSND(len=%lu)", _IOC_SIZE(arg));
+			return 1;
+		case 0x1b:
+			tprintf("EVIOCGSW(len=%lu)", _IOC_SIZE(arg));
+			return 1;
+		default:
+			return 0;
+	}
+}
+
+int
+hiddev_decode_number(unsigned long arg)
+{
+	switch (_IOC_NR(arg)) {
+		case 0x04:
+			tprintf("HIDIOCGRAWNAME(len=%lu)", _IOC_SIZE(arg));
+			return 1;
+		case 0x05:
+			tprintf("HIDIOCGRAWPHYS(len=%lu)", _IOC_SIZE(arg));
+			return 1;
+		case 0x06:
+			if (_IOC_DIR(arg) == IOC_IN) {
+				tprintf("HIDIOCSFEATURE(len=%lu)", _IOC_SIZE(arg));
+			} else {
+				tprintf("HIDIOCGNAME(len=%lu)", _IOC_SIZE(arg));
+			}
+			return 1;
+		case 0x07:
+			tprintf("HIDIOCGFEATURE(len=%lu)", _IOC_SIZE(arg));
+			return 1;
+		case 0x12:
+			tprintf("HIDIOCGPHYS(len=%lu)", _IOC_SIZE(arg));
+			return 1;
+		default:
+			return 0;
+	}
+}
+
+int
+ioctl_decode_number(unsigned long arg)
+{
+	switch (_IOC_TYPE(arg)) {
+		case 'E':
+			return evdev_decode_number(arg);
+		case 'H':
+			return hiddev_decode_number(arg);
+		case 'M':
+			if (_IOC_DIR(arg) == IOC_IN) {
+				tprintf("MIXER_WRITE(dev=%lu)", _IOC_NR(arg));
+			} else {
+				tprintf("MIXER_READ(dev=%lu)", _IOC_NR(arg));
+			}
+			return 1;
+		case 'U':
+			if (_IOC_NR(arg) == 0x2c) {
+				tprintf("UI_GET_SYSNAME(len=%lu)", _IOC_SIZE(arg));
+				return 1;
+			}
+			return 0;
+		case 'j':
+			if (_IOC_NR(arg) == 0x13) {
+				tprintf("JSIOCGNAME(len=%lu)", _IOC_SIZE(arg));
+				return 1;
+			}
+			return 0;
+		case 'k':
+			if (_IOC_NR(arg) == 0) {
+				tprintf("SPI_IOC_MESSAGE(N=%lu)", _IOC_SIZE(arg));
+				return 1;
+			}
+			return 0;
+		default:
+			return 0;
+	}
+}
+
+int
 ioctl_decode(struct tcb *tcp, long code, long arg)
 {
 	switch ((code >> 8) & 0xff) {
-- 
2.2.2





More information about the Strace-devel mailing list