1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _PERF_TRACE_BEAUTY_H
3 #define _PERF_TRACE_BEAUTY_H
4 
5 #include <linux/kernel.h>
6 #include <linux/types.h>
7 #include <sys/types.h>
8 #include <stdbool.h>
9 
10 struct strarray {
11 	u64	    offset;
12 	int	    nr_entries;
13 	const char *prefix;
14 	const char * const *entries;
15 };
16 
17 #define DEFINE_STRARRAY(array, _prefix) struct strarray strarray__##array = { \
18 	.nr_entries = ARRAY_SIZE(array), \
19 	.entries = array, \
20 	.prefix = _prefix, \
21 }
22 
23 #define DEFINE_STRARRAY_OFFSET(array, _prefix, off) struct strarray strarray__##array = { \
24 	.offset	    = off, \
25 	.nr_entries = ARRAY_SIZE(array), \
26 	.entries = array, \
27 	.prefix = _prefix, \
28 }
29 
30 size_t strarray__scnprintf(struct strarray *sa, char *bf, size_t size, const char *intfmt, bool show_prefix, int val);
31 size_t strarray__scnprintf_suffix(struct strarray *sa, char *bf, size_t size, const char *intfmt, bool show_suffix, int val);
32 size_t strarray__scnprintf_flags(struct strarray *sa, char *bf, size_t size, bool show_prefix, unsigned long flags);
33 
34 bool strarray__strtoul(struct strarray *sa, char *bf, size_t size, u64 *ret);
35 bool strarray__strtoul_flags(struct strarray *sa, char *bf, size_t size, u64 *ret);
36 
37 struct trace;
38 struct thread;
39 
40 struct file {
41 	char *pathname;
42 	int  dev_maj;
43 };
44 
45 struct file *thread__files_entry(struct thread *thread, int fd);
46 
47 struct strarrays {
48 	int		nr_entries;
49 	struct strarray **entries;
50 };
51 
52 #define DEFINE_STRARRAYS(array) struct strarrays strarrays__##array = { \
53 	.nr_entries = ARRAY_SIZE(array), \
54 	.entries = array, \
55 }
56 
57 size_t strarrays__scnprintf(struct strarrays *sas, char *bf, size_t size, const char *intfmt, bool show_prefix, int val);
58 
59 bool strarrays__strtoul(struct strarrays *sas, char *bf, size_t size, u64 *ret);
60 
61 size_t pid__scnprintf_fd(struct trace *trace, pid_t pid, int fd, char *bf, size_t size);
62 
63 extern struct strarray strarray__socket_families;
64 
65 extern struct strarray strarray__socket_level;
66 
67 /**
68  * augmented_arg: extra payload for syscall pointer arguments
69 
70  * If perf_sample->raw_size is more than what a syscall sys_enter_FOO puts, then
71  * its the arguments contents, so that we can show more than just a
72  * pointer. This will be done initially with eBPF, the start of that is at the
73  * tools/perf/util/bpf_skel/augmented_syscalls.bpf.c that will eventually be
74  * done automagically caching the running kernel tracefs events data into an
75  * eBPF C script, that then gets compiled and its .o file cached for subsequent
76  * use. For char pointers like the ones for 'open' like syscalls its easy, for
77  * the rest we should use DWARF or better, BTF, much more compact.
78  *
79  * @size: 8 if all we need is an integer, otherwise all of the augmented arg.
80  * @int_arg: will be used for integer like pointer contents, like 'accept's 'upeer_addrlen'
81  * @value: u64 aligned, for structs, pathnames
82  */
83 struct augmented_arg {
84 	int  size;
85 	int  int_arg;
86 	u64  value[];
87 };
88 
89 struct syscall_arg_fmt;
90 
91 /**
92  * @val: value of syscall argument being formatted
93  * @len: for tracepoint dynamic arrays, if fmt->nr_entries == 0, then its not a fixed array, look at arg->len
94  * @args: All the args, use syscall_args__val(arg, nth) to access one
95  * @augmented_args: Extra data that can be collected, for instance, with eBPF for expanding the pathname for open, etc
96  * @augmented_args_size: augmented_args total payload size
97  * @thread: tid state (maps, pid, tid, etc)
98  * @trace: 'perf trace' internals: all threads, etc
99  * @parm: private area, may be an strarray, for instance
100  * @idx: syscall arg idx (is this the first?)
101  * @mask: a syscall arg may mask another arg, see syscall_arg__scnprintf_futex_op
102  * @show_string_prefix: When there is a common prefix in a string table, show it or not
103  */
104 
105 struct syscall_arg {
106 	unsigned long val;
107 	unsigned char *args;
108 	struct syscall_arg_fmt *fmt;
109 	struct {
110 		struct augmented_arg *args;
111 		int		     size;
112 	} augmented;
113 	struct thread *thread;
114 	struct trace  *trace;
115 	void	      *parm;
116 	u16	      len;
117 	u8	      idx;
118 	u8	      mask;
119 	bool	      show_string_prefix;
120 };
121 
122 unsigned long syscall_arg__val(struct syscall_arg *arg, u8 idx);
123 
124 size_t syscall_arg__scnprintf_strarray_flags(char *bf, size_t size, struct syscall_arg *arg);
125 #define SCA_STRARRAY_FLAGS syscall_arg__scnprintf_strarray_flags
126 
127 bool syscall_arg__strtoul_strarray(char *bf, size_t size, struct syscall_arg *arg, u64 *ret);
128 #define STUL_STRARRAY syscall_arg__strtoul_strarray
129 
130 bool syscall_arg__strtoul_strarray_flags(char *bf, size_t size, struct syscall_arg *arg, u64 *ret);
131 #define STUL_STRARRAY_FLAGS syscall_arg__strtoul_strarray_flags
132 
133 bool syscall_arg__strtoul_strarrays(char *bf, size_t size, struct syscall_arg *arg, u64 *ret);
134 #define STUL_STRARRAYS syscall_arg__strtoul_strarrays
135 
136 size_t syscall_arg__scnprintf_x86_irq_vectors(char *bf, size_t size, struct syscall_arg *arg);
137 #define SCA_X86_IRQ_VECTORS syscall_arg__scnprintf_x86_irq_vectors
138 
139 bool syscall_arg__strtoul_x86_irq_vectors(char *bf, size_t size, struct syscall_arg *arg, u64 *ret);
140 #define STUL_X86_IRQ_VECTORS syscall_arg__strtoul_x86_irq_vectors
141 
142 size_t syscall_arg__scnprintf_x86_MSR(char *bf, size_t size, struct syscall_arg *arg);
143 #define SCA_X86_MSR syscall_arg__scnprintf_x86_MSR
144 
145 bool syscall_arg__strtoul_x86_MSR(char *bf, size_t size, struct syscall_arg *arg, u64 *ret);
146 #define STUL_X86_MSR syscall_arg__strtoul_x86_MSR
147 
148 size_t syscall_arg__scnprintf_strarrays(char *bf, size_t size, struct syscall_arg *arg);
149 #define SCA_STRARRAYS syscall_arg__scnprintf_strarrays
150 
151 size_t syscall_arg__scnprintf_fd(char *bf, size_t size, struct syscall_arg *arg);
152 #define SCA_FD syscall_arg__scnprintf_fd
153 
154 size_t syscall_arg__scnprintf_hex(char *bf, size_t size, struct syscall_arg *arg);
155 #define SCA_HEX syscall_arg__scnprintf_hex
156 
157 size_t syscall_arg__scnprintf_ptr(char *bf, size_t size, struct syscall_arg *arg);
158 #define SCA_PTR syscall_arg__scnprintf_ptr
159 
160 size_t syscall_arg__scnprintf_int(char *bf, size_t size, struct syscall_arg *arg);
161 #define SCA_INT syscall_arg__scnprintf_int
162 
163 size_t syscall_arg__scnprintf_long(char *bf, size_t size, struct syscall_arg *arg);
164 #define SCA_LONG syscall_arg__scnprintf_long
165 
166 size_t syscall_arg__scnprintf_pid(char *bf, size_t size, struct syscall_arg *arg);
167 #define SCA_PID syscall_arg__scnprintf_pid
168 
169 size_t syscall_arg__scnprintf_clone_flags(char *bf, size_t size, struct syscall_arg *arg);
170 #define SCA_CLONE_FLAGS syscall_arg__scnprintf_clone_flags
171 
172 size_t syscall_arg__scnprintf_fcntl_cmd(char *bf, size_t size, struct syscall_arg *arg);
173 #define SCA_FCNTL_CMD syscall_arg__scnprintf_fcntl_cmd
174 
175 size_t syscall_arg__scnprintf_fcntl_arg(char *bf, size_t size, struct syscall_arg *arg);
176 #define SCA_FCNTL_ARG syscall_arg__scnprintf_fcntl_arg
177 
178 size_t syscall_arg__scnprintf_flock(char *bf, size_t size, struct syscall_arg *arg);
179 #define SCA_FLOCK syscall_arg__scnprintf_flock
180 
181 size_t syscall_arg__scnprintf_fsmount_attr_flags(char *bf, size_t size, struct syscall_arg *arg);
182 #define SCA_FSMOUNT_ATTR_FLAGS syscall_arg__scnprintf_fsmount_attr_flags
183 
184 size_t syscall_arg__scnprintf_fspick_flags(char *bf, size_t size, struct syscall_arg *arg);
185 #define SCA_FSPICK_FLAGS syscall_arg__scnprintf_fspick_flags
186 
187 size_t syscall_arg__scnprintf_ioctl_cmd(char *bf, size_t size, struct syscall_arg *arg);
188 #define SCA_IOCTL_CMD syscall_arg__scnprintf_ioctl_cmd
189 
190 size_t syscall_arg__scnprintf_kcmp_type(char *bf, size_t size, struct syscall_arg *arg);
191 #define SCA_KCMP_TYPE syscall_arg__scnprintf_kcmp_type
192 
193 size_t syscall_arg__scnprintf_kcmp_idx(char *bf, size_t size, struct syscall_arg *arg);
194 #define SCA_KCMP_IDX syscall_arg__scnprintf_kcmp_idx
195 
196 unsigned long syscall_arg__mask_val_mount_flags(struct syscall_arg *arg, unsigned long flags);
197 #define SCAMV_MOUNT_FLAGS syscall_arg__mask_val_mount_flags
198 
199 size_t syscall_arg__scnprintf_mount_flags(char *bf, size_t size, struct syscall_arg *arg);
200 #define SCA_MOUNT_FLAGS syscall_arg__scnprintf_mount_flags
201 
202 size_t syscall_arg__scnprintf_move_mount_flags(char *bf, size_t size, struct syscall_arg *arg);
203 #define SCA_MOVE_MOUNT_FLAGS syscall_arg__scnprintf_move_mount_flags
204 
205 size_t syscall_arg__scnprintf_pkey_alloc_access_rights(char *bf, size_t size, struct syscall_arg *arg);
206 #define SCA_PKEY_ALLOC_ACCESS_RIGHTS syscall_arg__scnprintf_pkey_alloc_access_rights
207 
208 size_t syscall_arg__scnprintf_open_flags(char *bf, size_t size, struct syscall_arg *arg);
209 #define SCA_OPEN_FLAGS syscall_arg__scnprintf_open_flags
210 
211 size_t syscall_arg__scnprintf_x86_arch_prctl_code(char *bf, size_t size, struct syscall_arg *arg);
212 #define SCA_X86_ARCH_PRCTL_CODE syscall_arg__scnprintf_x86_arch_prctl_code
213 
214 size_t syscall_arg__scnprintf_prctl_option(char *bf, size_t size, struct syscall_arg *arg);
215 #define SCA_PRCTL_OPTION syscall_arg__scnprintf_prctl_option
216 
217 extern struct strarray strarray__prctl_options;
218 
219 size_t syscall_arg__scnprintf_prctl_arg2(char *bf, size_t size, struct syscall_arg *arg);
220 #define SCA_PRCTL_ARG2 syscall_arg__scnprintf_prctl_arg2
221 
222 size_t syscall_arg__scnprintf_prctl_arg3(char *bf, size_t size, struct syscall_arg *arg);
223 #define SCA_PRCTL_ARG3 syscall_arg__scnprintf_prctl_arg3
224 
225 size_t syscall_arg__scnprintf_renameat2_flags(char *bf, size_t size, struct syscall_arg *arg);
226 #define SCA_RENAMEAT2_FLAGS syscall_arg__scnprintf_renameat2_flags
227 
228 size_t syscall_arg__scnprintf_sockaddr(char *bf, size_t size, struct syscall_arg *arg);
229 #define SCA_SOCKADDR syscall_arg__scnprintf_sockaddr
230 
231 size_t syscall_arg__scnprintf_socket_protocol(char *bf, size_t size, struct syscall_arg *arg);
232 #define SCA_SK_PROTO syscall_arg__scnprintf_socket_protocol
233 
234 size_t syscall_arg__scnprintf_socket_level(char *bf, size_t size, struct syscall_arg *arg);
235 #define SCA_SK_LEVEL syscall_arg__scnprintf_socket_level
236 
237 size_t syscall_arg__scnprintf_statx_flags(char *bf, size_t size, struct syscall_arg *arg);
238 #define SCA_STATX_FLAGS syscall_arg__scnprintf_statx_flags
239 
240 size_t syscall_arg__scnprintf_statx_mask(char *bf, size_t size, struct syscall_arg *arg);
241 #define SCA_STATX_MASK syscall_arg__scnprintf_statx_mask
242 
243 size_t syscall_arg__scnprintf_sync_file_range_flags(char *bf, size_t size, struct syscall_arg *arg);
244 #define SCA_SYNC_FILE_RANGE_FLAGS syscall_arg__scnprintf_sync_file_range_flags
245 
246 size_t syscall_arg__scnprintf_timespec(char *bf, size_t size, struct syscall_arg *arg);
247 #define SCA_TIMESPEC syscall_arg__scnprintf_timespec
248 
249 size_t open__scnprintf_flags(unsigned long flags, char *bf, size_t size, bool show_prefix);
250 
251 void syscall_arg__set_ret_scnprintf(struct syscall_arg *arg,
252 				    size_t (*ret_scnprintf)(char *bf, size_t size, struct syscall_arg *arg));
253 
254 const char *arch_syscalls__strerrno(const char *arch, int err);
255 
256 #endif /* _PERF_TRACE_BEAUTY_H */
257