2 * Copyright (c) 2018 The strace developers.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
30 #include <linux/ioctl.h>
32 #include "perf_event_struct.h"
34 #define XLAT_MACROS_ONLY
35 # include "xlat/perf_ioctl_cmds.h"
36 #undef XLAT_MACROS_ONLY
38 #include "xlat/perf_ioctl_flags.h"
43 perf_ioctl_query_bpf(struct tcb *const tcp, const kernel_ulong_t arg)
50 if (umove_or_printaddr(tcp, arg, &info))
51 return RVAL_IOCTL_DECODED;
53 tprintf("{ids_len=%u, ", info);
59 umove(tcp, arg + offsetof(struct perf_event_query_bpf, prog_cnt),
63 return RVAL_IOCTL_DECODED;
66 tprintf("prog_cnt=%u, ids=", info);
68 print_array(tcp, arg + offsetof(struct perf_event_query_bpf, ids), info,
70 tfetch_mem, print_uint32_array_member, NULL);
74 return RVAL_IOCTL_DECODED;
78 perf_ioctl_modify_attributes(struct tcb *const tcp, const kernel_ulong_t arg)
81 if (!fetch_perf_event_attr(tcp, arg))
82 print_perf_event_attr(tcp, arg);
84 return RVAL_IOCTL_DECODED;
87 MPERS_PRINTER_DECL(int, perf_ioctl,
88 struct tcb *const tcp, const unsigned int code,
89 const kernel_ulong_t arg)
92 case PERF_EVENT_IOC_ENABLE:
93 case PERF_EVENT_IOC_DISABLE:
94 case PERF_EVENT_IOC_RESET:
96 printflags(perf_ioctl_flags, arg, "PERF_IOC_FLAG_???");
98 return RVAL_IOCTL_DECODED;
100 case PERF_EVENT_IOC_REFRESH:
101 tprintf(", %d", (int) arg);
103 return RVAL_IOCTL_DECODED;
105 case PERF_EVENT_IOC_PERIOD:
107 printnum_int64(tcp, arg, "%" PRIu64);
109 return RVAL_IOCTL_DECODED;
111 case PERF_EVENT_IOC_SET_OUTPUT:
112 case PERF_EVENT_IOC_SET_BPF:
114 printfd(tcp, (int) arg);
116 return RVAL_IOCTL_DECODED;
118 case PERF_EVENT_IOC_PAUSE_OUTPUT:
119 tprintf(", %" PRI_klu, arg);
121 return RVAL_IOCTL_DECODED;
124 * The following ioctl requests are personality-specific
125 * due to the pointer size.
127 case PERF_EVENT_IOC_SET_FILTER:
129 printstr_ex(tcp, arg, get_pagesize(), QUOTE_0_TERMINATED);
131 return RVAL_IOCTL_DECODED;
133 case PERF_EVENT_IOC_ID:
140 printnum_int64(tcp, arg, "%" PRIu64);
142 return RVAL_IOCTL_DECODED;
144 case PERF_EVENT_IOC_QUERY_BPF:
145 return perf_ioctl_query_bpf(tcp, arg);
147 case PERF_EVENT_IOC_MODIFY_ATTRIBUTES:
148 return perf_ioctl_modify_attributes(tcp, arg);