]> granicus.if.org Git - strace/blob - perf_ioctl.c
tests: check decoding of vcpu auxstr
[strace] / perf_ioctl.c
1 /*
2  * Copyright (c) 2018 The strace developers.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 #include "defs.h"
29
30 #include <linux/ioctl.h>
31
32 #include "perf_event_struct.h"
33
34 #define XLAT_MACROS_ONLY
35 # include "xlat/perf_ioctl_cmds.h"
36 #undef XLAT_MACROS_ONLY
37
38 #include "xlat/perf_ioctl_flags.h"
39
40 #include MPERS_DEFS
41
42 static int
43 perf_ioctl_query_bpf(struct tcb *const tcp, const kernel_ulong_t arg)
44 {
45         uint32_t info;
46
47         if (entering(tcp)) {
48                 tprints(", ");
49
50                 if (umove_or_printaddr(tcp, arg, &info))
51                         return RVAL_IOCTL_DECODED;
52
53                 tprintf("{ids_len=%u, ", info);
54
55                 return 0;
56         }
57
58         if (syserror(tcp) ||
59             umove(tcp, arg + offsetof(struct perf_event_query_bpf, prog_cnt),
60                   &info)) {
61                 tprints("...}");
62
63                 return RVAL_IOCTL_DECODED;
64         }
65
66         tprintf("prog_cnt=%u, ids=", info);
67
68         print_array(tcp, arg + offsetof(struct perf_event_query_bpf, ids), info,
69                     &info, sizeof(info),
70                     tfetch_mem, print_uint32_array_member, NULL);
71
72         tprints("}");
73
74         return RVAL_IOCTL_DECODED;
75 }
76
77 static int
78 perf_ioctl_modify_attributes(struct tcb *const tcp, const kernel_ulong_t arg)
79 {
80         tprints(", ");
81         if (!fetch_perf_event_attr(tcp, arg))
82                 print_perf_event_attr(tcp, arg);
83
84         return RVAL_IOCTL_DECODED;
85 }
86
87 MPERS_PRINTER_DECL(int, perf_ioctl,
88                    struct tcb *const tcp, const unsigned int code,
89                    const kernel_ulong_t arg)
90 {
91         switch (code) {
92         case PERF_EVENT_IOC_ENABLE:
93         case PERF_EVENT_IOC_DISABLE:
94         case PERF_EVENT_IOC_RESET:
95                 tprints(", ");
96                 printflags(perf_ioctl_flags, arg, "PERF_IOC_FLAG_???");
97
98                 return RVAL_IOCTL_DECODED;
99
100         case PERF_EVENT_IOC_REFRESH:
101                 tprintf(", %d", (int) arg);
102
103                 return RVAL_IOCTL_DECODED;
104
105         case PERF_EVENT_IOC_PERIOD:
106                 tprints(", ");
107                 printnum_int64(tcp, arg, "%" PRIu64);
108
109                 return RVAL_IOCTL_DECODED;
110
111         case PERF_EVENT_IOC_SET_OUTPUT:
112         case PERF_EVENT_IOC_SET_BPF:
113                 tprintf(", ");
114                 printfd(tcp, (int) arg);
115
116                 return RVAL_IOCTL_DECODED;
117
118         case PERF_EVENT_IOC_PAUSE_OUTPUT:
119                 tprintf(", %" PRI_klu, arg);
120
121                 return RVAL_IOCTL_DECODED;
122
123         /*
124          * The following ioctl requests are personality-specific
125          * due to the pointer size.
126          */
127         case PERF_EVENT_IOC_SET_FILTER:
128                 tprints(", ");
129                 printstr_ex(tcp, arg, get_pagesize(), QUOTE_0_TERMINATED);
130
131                 return RVAL_IOCTL_DECODED;
132
133         case PERF_EVENT_IOC_ID:
134                 if (entering(tcp)) {
135                         tprints(", ");
136
137                         return 0;
138                 }
139
140                 printnum_int64(tcp, arg, "%" PRIu64);
141
142                 return RVAL_IOCTL_DECODED;
143
144         case PERF_EVENT_IOC_QUERY_BPF:
145                 return perf_ioctl_query_bpf(tcp, arg);
146
147         case PERF_EVENT_IOC_MODIFY_ATTRIBUTES:
148                 return perf_ioctl_modify_attributes(tcp, arg);
149
150         default:
151                 return RVAL_DECODED;
152         }
153 }