]> granicus.if.org Git - strace/blobdiff - evdev.c
Remove linux/ptp_clock.h
[strace] / evdev.c
diff --git a/evdev.c b/evdev.c
index 2775a71816e2e9ad67e392b7f57d48c18b149ba1..5642e0d7ba466d5d729b50b7f88ecb3c062f7118 100644 (file)
--- a/evdev.c
+++ b/evdev.c
@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2015 Etienne Gemsa <etienne.gemsa@lse.epita.fr>
- * Copyright (c) 2015 Dmitry V. Levin <ldv@altlinux.org>
+ * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
+ * Copyright (c) 2015-2017 The strace developers.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 
 #ifdef HAVE_LINUX_INPUT_H
 
+#include DEF_MPERS_TYPE(struct_ff_effect)
+
 # include <linux/ioctl.h>
 # include <linux/input.h>
-# include "xlat/evdev_abs.h"
+
+typedef struct ff_effect struct_ff_effect;
+
+#endif /* HAVE_LINUX_INPUT_H */
+
+#include MPERS_DEFS
+
+#ifdef HAVE_LINUX_INPUT_H
+
 # include "xlat/evdev_autorepeat.h"
 # include "xlat/evdev_ff_status.h"
 # include "xlat/evdev_ff_types.h"
 # endif
 
 static void
-decode_envelope(const struct ff_envelope *envelope)
+decode_envelope(void *const data)
 {
+       const struct ff_envelope *const envelope = data;
+
        tprintf(", envelope={attack_length=%" PRIu16
                ", attack_level=%" PRIu16
                ", fade_length=%" PRIu16
@@ -64,14 +77,14 @@ decode_envelope(const struct ff_envelope *envelope)
 }
 
 static int
-ff_effect_ioctl(struct tcb *tcp, long arg)
+ff_effect_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
 {
        tprints(", ");
 
-       struct ff_effect ffe;
+       struct_ff_effect ffe;
 
        if (umove_or_printaddr(tcp, arg, &ffe))
-               return 1;
+               return RVAL_IOCTL_DECODED;
 
        tprints("{type=");
        printxval(evdev_ff_types, ffe.type, "FF_???");
@@ -82,7 +95,7 @@ ff_effect_ioctl(struct tcb *tcp, long arg)
 
        if (abbrev(tcp)) {
                tprints("...}");
-               return 1;
+               return RVAL_IOCTL_DECODED;
        }
 
        tprintf("trigger={button=%" PRIu16
@@ -121,10 +134,10 @@ ff_effect_ioctl(struct tcb *tcp, long arg)
                                ffe.u.periodic.offset,
                                ffe.u.periodic.phase);
                        decode_envelope(&ffe.u.periodic.envelope);
-                       tprintf(", custom_len=%u"
-                               ", custom_data=%#lx}",
-                               ffe.u.periodic.custom_len,
-                               (unsigned long) ffe.u.periodic.custom_data);
+                       tprintf(", custom_len=%u, custom_data=",
+                               ffe.u.periodic.custom_len);
+                       printaddr(ptr_to_kulong(ffe.u.periodic.custom_data));
+                       tprints("}");
                        break;
                case FF_RUMBLE:
                        tprintf(", rumble={strong_magnitude=%" PRIu16
@@ -138,71 +151,79 @@ ff_effect_ioctl(struct tcb *tcp, long arg)
 
        tprints("}");
 
-       return 1;
+       return RVAL_IOCTL_DECODED;
 }
 
 static int
-abs_ioctl(struct tcb *tcp, long arg)
+abs_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
 {
-       struct input_absinfo absinfo;
+       tprints(", ");
 
-       if (!verbose(tcp) || umove(tcp, arg, &absinfo) < 0)
-               return 0;
+       struct input_absinfo absinfo;
 
-       tprintf(", {value=%" PRIu32 ", minimum=%" PRIu32,
-               absinfo.value, absinfo.minimum);
-       if (!abbrev(tcp)) {
-               tprintf(", maximum=%" PRIu32 ", fuzz=%" PRIu32,
-                       absinfo.maximum, absinfo.fuzz);
-               tprintf(", flat=%" PRIu32, absinfo.flat);
+       if (!umove_or_printaddr(tcp, arg, &absinfo)) {
+               tprintf("{value=%u"
+                       ", minimum=%u, ",
+                       absinfo.value,
+                       absinfo.minimum);
+
+               if (!abbrev(tcp)) {
+                       tprintf("maximum=%u"
+                               ", fuzz=%u"
+                               ", flat=%u",
+                               absinfo.maximum,
+                               absinfo.fuzz,
+                               absinfo.flat);
 # ifdef HAVE_STRUCT_INPUT_ABSINFO_RESOLUTION
-               tprintf(", resolution=%" PRIu32, absinfo.resolution);
+                       tprintf(", resolution=%u",
+                               absinfo.resolution);
 # endif
+               } else {
+                       tprints("...");
+               }
+
                tprints("}");
-       } else {
-               tprints(", ...}");
        }
-       return 1;
+
+       return RVAL_IOCTL_DECODED;
 }
 
 static int
-keycode_ioctl(struct tcb *tcp, long arg)
+keycode_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
 {
+       tprints(", ");
+
        unsigned int keycode[2];
 
-       if (!arg) {
-               tprints(", NULL");
-               return 1;
+       if (!umove_or_printaddr(tcp, arg, &keycode)) {
+               tprintf("[%u, ", keycode[0]);
+               printxval(evdev_keycode, keycode[1], "KEY_???");
+               tprints("]");
        }
 
-       if (!verbose(tcp) || umove(tcp, arg, &keycode) < 0)
-               return 0;
-
-       tprintf(", [%u, ", keycode[0]);
-       printxval(evdev_keycode, keycode[1], "KEY_???");
-       tprints("]");
-       return 1;
+       return RVAL_IOCTL_DECODED;
 }
 
 # ifdef EVIOCGKEYCODE_V2
 static int
-keycode_V2_ioctl(struct tcb *tcp, long arg)
+keycode_V2_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
 {
+       tprints(", ");
+
        struct input_keymap_entry ike;
 
-       if (!arg) {
-               tprints(", NULL");
-               return 1;
-       }
+       if (umove_or_printaddr(tcp, arg, &ike))
+               return RVAL_IOCTL_DECODED;
 
-       if (!verbose(tcp) || umove(tcp, arg, &ike) < 0)
-               return 0;
+       tprintf("{flags=%" PRIu8
+               ", len=%" PRIu8 ", ",
+               ike.flags,
+               ike.len);
 
-       tprintf(", {flags=%" PRIu8 ", len=%" PRIu8, ike.flags, ike.len);
        if (!abbrev(tcp)) {
                unsigned int i;
 
-               tprintf("index=%" PRIu16 ", keycode=", ike.index);
+               tprintf("index=%" PRIu16 ", keycode=", ike.index);
                printxval(evdev_keycode, ike.keycode, "KEY_???");
                tprints(", scancode=[");
                for (i = 0; i < ARRAY_SIZE(ike.scancode); i++) {
@@ -210,51 +231,55 @@ keycode_V2_ioctl(struct tcb *tcp, long arg)
                                tprints(", ");
                        tprintf("%" PRIx8, ike.scancode[i]);
                }
-               tprints("]}");
+               tprints("]");
        } else {
-               tprints(", ...}");
+               tprints("...");
        }
-       return 1;
+
+       tprints("}");
+
+       return RVAL_IOCTL_DECODED;
 }
 # endif /* EVIOCGKEYCODE_V2 */
 
 static int
-getid_ioctl(struct tcb *tcp, long arg)
+getid_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
 {
-       struct input_id id;
+       tprints(", ");
 
-       if (!verbose(tcp) || umove(tcp, arg, &id) < 0)
-               return 0;
+       struct input_id id;
 
-       tprintf(", {ID_BUS=%" PRIu16 ", ID_VENDOR=%" PRIu16,
-               id.bustype, id.vendor);
-       if (!abbrev(tcp)) {
-               tprintf(", ID_PRODUCT=%" PRIu16 ", ID_VERSION=%" PRIu16 "}",
-                       id.product, id.version);
-       } else {
-               tprints(", ...}");
-       }
-       return 1;
+       if (!umove_or_printaddr(tcp, arg, &id))
+               tprintf("{ID_BUS=%" PRIu16
+                       ", ID_VENDOR=%" PRIu16
+                       ", ID_PRODUCT=%" PRIu16
+                       ", ID_VERSION=%" PRIu16 "}",
+                       id.bustype,
+                       id.vendor,
+                       id.product,
+                       id.version);
+
+       return RVAL_IOCTL_DECODED;
 }
 
 static int
-decode_bitset(struct tcb *tcp, long arg, const struct xlat decode_nr[],
-             const unsigned int max_nr, const char *dflt)
+decode_bitset(struct tcb *const tcp, const kernel_ulong_t arg,
+             const struct xlat decode_nr[], const unsigned int max_nr,
+             const char *const dflt)
 {
-       if (!verbose(tcp))
-               return 0;
+       tprints(", ");
 
        unsigned int size;
-       if ((unsigned long) tcp->u_rval > max_nr)
+       if ((kernel_ulong_t) tcp->u_rval > max_nr)
                size = max_nr;
        else
                size = tcp->u_rval;
        char decoded_arg[size];
 
-       if (umoven(tcp, arg, size, decoded_arg) < 0)
-               return 0;
+       if (umove_or_printaddr(tcp, arg, &decoded_arg))
+               return RVAL_IOCTL_DECODED;
 
-       tprints("[");
+       tprints("[");
 
        int bit_displayed = 0;
        int i = next_set_bit(decoded_arg, 0, size);
@@ -276,114 +301,122 @@ decode_bitset(struct tcb *tcp, long arg, const struct xlat decode_nr[],
 
        tprints("]");
 
-       return 1;
+       return RVAL_IOCTL_DECODED;
 }
 
 # ifdef EVIOCGMTSLOTS
 static int
-mtslots_ioctl(struct tcb *tcp, const unsigned int code, long arg)
+mtslots_ioctl(struct tcb *const tcp, const unsigned int code,
+             const kernel_ulong_t arg)
 {
-       const size_t size = _IOC_SIZE(code) / sizeof(int32_t);
-       if (!size)
-               return 0;
+       tprints(", ");
 
-       int32_t buffer[size];
+       const size_t size = _IOC_SIZE(code) / sizeof(int);
+       if (!size) {
+               printaddr(arg);
+               return RVAL_IOCTL_DECODED;
+       }
+
+       int buffer[size];
 
-       if (!verbose(tcp) || umove(tcp, arg, &buffer) < 0)
-               return 0;
+       if (umove_or_printaddr(tcp, arg, &buffer))
+               return RVAL_IOCTL_DECODED;
 
-       tprints("{code=");
+       tprints("{code=");
        printxval(evdev_mtslots, buffer[0], "ABS_MT_???");
 
-       unsigned int i;
        tprints(", values=[");
 
+       unsigned int i;
        for (i = 1; i < ARRAY_SIZE(buffer); i++)
                tprintf("%s%d", i > 1 ? ", " : "", buffer[i]);
 
        tprints("]}");
-       return 1;
+
+       return RVAL_IOCTL_DECODED;
 }
 # endif /* EVIOCGMTSLOTS */
 
 # if defined EVIOCGREP || defined EVIOCSREP
 static int
-repeat_ioctl(struct tcb *tcp, long arg)
+repeat_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
 {
        tprints(", ");
        printpair_int(tcp, arg, "%u");
-       return 1;
+       return RVAL_IOCTL_DECODED;
 }
 # endif /* EVIOCGREP || EVIOCSREP */
 
 static int
-bit_ioctl(struct tcb *tcp, const unsigned int ev_nr, const long arg)
+bit_ioctl(struct tcb *const tcp, const unsigned int ev_nr,
+         const kernel_ulong_t arg)
 {
        switch (ev_nr) {
                case EV_SYN:
                        return decode_bitset(tcp, arg, evdev_sync,
-                                       SYN_MAX, "SYN_???");
+                                            SYN_MAX, "SYN_???");
                case EV_KEY:
                        return decode_bitset(tcp, arg, evdev_keycode,
-                                       KEY_MAX, "KEY_???");
+                                            KEY_MAX, "KEY_???");
                case EV_REL:
                        return decode_bitset(tcp, arg, evdev_relative_axes,
-                                       REL_MAX, "REL_???");
+                                            REL_MAX, "REL_???");
                case EV_ABS:
-                       return decode_bitset(tcp, arg,
-                                       evdev_abs, ABS_MAX, "ABS_???");
+                       return decode_bitset(tcp, arg, evdev_abs,
+                                            ABS_MAX, "ABS_???");
                case EV_MSC:
-                       return decode_bitset(tcp, arg,
-                                       evdev_misc, MSC_MAX, "MSC_???");
+                       return decode_bitset(tcp, arg, evdev_misc,
+                                            MSC_MAX, "MSC_???");
 # ifdef EV_SW
                case EV_SW:
-                       return decode_bitset(tcp, arg,
-                                       evdev_switch, SW_MAX, "SW_???");
+                       return decode_bitset(tcp, arg, evdev_switch,
+                                            SW_MAX, "SW_???");
 # endif
                case EV_LED:
-                       return decode_bitset(tcp, arg,
-                                       evdev_leds, LED_MAX, "LED_???");
+                       return decode_bitset(tcp, arg, evdev_leds,
+                                            LED_MAX, "LED_???");
                case EV_SND:
-                       return decode_bitset(tcp, arg,
-                                       evdev_snd, SND_MAX, "SND_???");
+                       return decode_bitset(tcp, arg, evdev_snd,
+                                            SND_MAX, "SND_???");
                case EV_REP:
                        return decode_bitset(tcp, arg, evdev_autorepeat,
-                                       REP_MAX, "REP_???");
+                                            REP_MAX, "REP_???");
                case EV_FF:
                        return decode_bitset(tcp, arg, evdev_ff_types,
-                                       FF_MAX, "FF_???");
+                                            FF_MAX, "FF_???");
                case EV_PWR:
+                       tprints(", ");
                        printnum_int(tcp, arg, "%d");
-                       return 1;
+                       return RVAL_IOCTL_DECODED;
                case EV_FF_STATUS:
                        return decode_bitset(tcp, arg, evdev_ff_status,
-                                       FF_STATUS_MAX, "FF_STATUS_???");
+                                            FF_STATUS_MAX, "FF_STATUS_???");
                default:
-                       return 0;
+                       tprints(", ");
+                       printaddr(arg);
+                       return RVAL_IOCTL_DECODED;
        }
 }
 
 static int
-evdev_read_ioctl(struct tcb *tcp, const unsigned int code, const long arg)
+evdev_read_ioctl(struct tcb *const tcp, const unsigned int code,
+                const kernel_ulong_t arg)
 {
-       if (syserror(tcp))
-               return 0;
-
        /* fixed-number fixed-length commands */
        switch (code) {
                case EVIOCGVERSION:
                        tprints(", ");
-                       printnum_int(tcp, arg, "%" PRIx32);
-                       return 1;
+                       printnum_int(tcp, arg, "%#x");
+                       return RVAL_IOCTL_DECODED;
                case EVIOCGEFFECTS:
                        tprints(", ");
-                       printnum_int(tcp, arg, "%" PRIu32);
-                       return 1;
+                       printnum_int(tcp, arg, "%u");
+                       return RVAL_IOCTL_DECODED;
                case EVIOCGID:
                        return getid_ioctl(tcp, arg);
 # ifdef EVIOCGREP
                case EVIOCGREP:
-                       return repeat_ioctl(tcp, arg);;
+                       return repeat_ioctl(tcp, arg);
 # endif
                case EVIOCGKEYCODE:
                        return keycode_ioctl(tcp, arg);
@@ -403,27 +436,30 @@ evdev_read_ioctl(struct tcb *tcp, const unsigned int code, const long arg)
                case _IOC_NR(EVIOCGPHYS(0)):
                case _IOC_NR(EVIOCGUNIQ(0)):
                        tprints(", ");
-                       printstr(tcp, arg, tcp->u_rval - 1);
-                       return 1;
+                       if (syserror(tcp))
+                               printaddr(arg);
+                       else
+                               printstrn(tcp, arg, tcp->u_rval);
+                       return RVAL_IOCTL_DECODED;
 # ifdef EVIOCGPROP
                case _IOC_NR(EVIOCGPROP(0)):
-                       return decode_bitset(tcp, arg,
-                                       evdev_prop, INPUT_PROP_MAX, "PROP_???");
+                       return decode_bitset(tcp, arg, evdev_prop,
+                                            INPUT_PROP_MAX, "PROP_???");
 # endif
                case _IOC_NR(EVIOCGSND(0)):
-                       return decode_bitset(tcp, arg,
-                                       evdev_snd, SND_MAX, "SND_???");
+                       return decode_bitset(tcp, arg, evdev_snd,
+                                            SND_MAX, "SND_???");
 # ifdef EVIOCGSW
                case _IOC_NR(EVIOCGSW(0)):
-                       return decode_bitset(tcp, arg,
-                                       evdev_switch, SW_MAX, "SW_???");
+                       return decode_bitset(tcp, arg, evdev_switch,
+                                            SW_MAX, "SW_???");
 # endif
                case _IOC_NR(EVIOCGKEY(0)):
-                       return decode_bitset(tcp, arg,
-                                       evdev_keycode, KEY_MAX, "KEY_???");
+                       return decode_bitset(tcp, arg, evdev_keycode,
+                                            KEY_MAX, "KEY_???");
                case _IOC_NR(EVIOCGLED(0)):
-                       return decode_bitset(tcp, arg,
-                                       evdev_leds, LED_MAX, "LED_???");
+                       return decode_bitset(tcp, arg, evdev_leds,
+                                            LED_MAX, "LED_???");
        }
 
        /* multi-number fixed-length commands */
@@ -438,7 +474,8 @@ evdev_read_ioctl(struct tcb *tcp, const unsigned int code, const long arg)
 }
 
 static int
-evdev_write_ioctl(struct tcb *tcp, const unsigned int code, const long arg)
+evdev_write_ioctl(struct tcb *const tcp, const unsigned int code,
+                 const kernel_ulong_t arg)
 {
        /* fixed-number fixed-length commands */
        switch (code) {
@@ -456,18 +493,18 @@ evdev_write_ioctl(struct tcb *tcp, const unsigned int code, const long arg)
                        return ff_effect_ioctl(tcp, arg);
                case EVIOCRMFF:
                        tprintf(", %d", (int) arg);
-                       return 1;
+                       return RVAL_IOCTL_DECODED;
                case EVIOCGRAB:
 # ifdef EVIOCREVOKE
                case EVIOCREVOKE:
 # endif
-                       tprintf(", %lu", arg);
-                       return 1;
+                       tprintf(", %" PRI_klu, arg);
+                       return RVAL_IOCTL_DECODED;
 # ifdef EVIOCSCLOCKID
                case EVIOCSCLOCKID:
                        tprints(", ");
                        printnum_int(tcp, arg, "%u");
-                       return 1;
+                       return RVAL_IOCTL_DECODED;
 # endif
        }
 
@@ -478,10 +515,10 @@ evdev_write_ioctl(struct tcb *tcp, const unsigned int code, const long arg)
        return 0;
 }
 
-int
-evdev_ioctl(struct tcb *tcp, const unsigned int code, long arg)
+MPERS_PRINTER_DECL(int, evdev_ioctl, struct tcb *const tcp,
+                  const unsigned int code, const kernel_ulong_t arg)
 {
-       switch(_IOC_DIR(code)) {
+       switch (_IOC_DIR(code)) {
                case _IOC_READ:
                        if (entering(tcp))
                                return 0;