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