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 **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 /** 66 * augmented_arg: extra payload for syscall pointer arguments 67 68 * If perf_sample->raw_size is more than what a syscall sys_enter_FOO puts, 69 * then its the arguments contents, so that we can show more than just a 70 * pointer. This will be done initially with eBPF, the start of that is at the 71 * tools/perf/examples/bpf/augmented_syscalls.c example for the openat, but 72 * will eventually be done automagically caching the running kernel tracefs 73 * events data into an eBPF C script, that then gets compiled and its .o file 74 * cached for subsequent use. For char pointers like the ones for 'open' like 75 * syscalls its easy, for the rest we should use DWARF or better, BTF, much 76 * more compact. 77 * 78 * @size: 8 if all we need is an integer, otherwise all of the augmented arg. 79 * @int_arg: will be used for integer like pointer contents, like 'accept's 'upeer_addrlen' 80 * @value: u64 aligned, for structs, pathnames 81 */ 82 struct augmented_arg { 83 int size; 84 int int_arg; 85 u64 value[]; 86 }; 87 88 struct syscall_arg_fmt; 89 90 /** 91 * @val: value of syscall argument being formatted 92 * @len: for tracepoint dynamic arrays, if fmt->nr_entries == 0, then its not a fixed array, look at arg->len 93 * @args: All the args, use syscall_args__val(arg, nth) to access one 94 * @augmented_args: Extra data that can be collected, for instance, with eBPF for expanding the pathname for open, etc 95 * @augmented_args_size: augmented_args total payload size 96 * @thread: tid state (maps, pid, tid, etc) 97 * @trace: 'perf trace' internals: all threads, etc 98 * @parm: private area, may be an strarray, for instance 99 * @idx: syscall arg idx (is this the first?) 100 * @mask: a syscall arg may mask another arg, see syscall_arg__scnprintf_futex_op 101 * @show_string_prefix: When there is a common prefix in a string table, show it or not 102 */ 103 104 struct syscall_arg { 105 unsigned long val; 106 unsigned char *args; 107 struct syscall_arg_fmt *fmt; 108 struct { 109 struct augmented_arg *args; 110 int size; 111 } augmented; 112 struct thread *thread; 113 struct trace *trace; 114 void *parm; 115 u16 len; 116 u8 idx; 117 u8 mask; 118 bool show_string_prefix; 119 }; 120 121 unsigned long syscall_arg__val(struct syscall_arg *arg, u8 idx); 122 123 size_t syscall_arg__scnprintf_strarray_flags(char *bf, size_t size, struct syscall_arg *arg); 124 #define SCA_STRARRAY_FLAGS syscall_arg__scnprintf_strarray_flags 125 126 bool syscall_arg__strtoul_strarray(char *bf, size_t size, struct syscall_arg *arg, u64 *ret); 127 #define STUL_STRARRAY syscall_arg__strtoul_strarray 128 129 bool syscall_arg__strtoul_strarray_flags(char *bf, size_t size, struct syscall_arg *arg, u64 *ret); 130 #define STUL_STRARRAY_FLAGS syscall_arg__strtoul_strarray_flags 131 132 bool syscall_arg__strtoul_strarrays(char *bf, size_t size, struct syscall_arg *arg, u64 *ret); 133 #define STUL_STRARRAYS syscall_arg__strtoul_strarrays 134 135 size_t syscall_arg__scnprintf_x86_irq_vectors(char *bf, size_t size, struct syscall_arg *arg); 136 #define SCA_X86_IRQ_VECTORS syscall_arg__scnprintf_x86_irq_vectors 137 138 bool syscall_arg__strtoul_x86_irq_vectors(char *bf, size_t size, struct syscall_arg *arg, u64 *ret); 139 #define STUL_X86_IRQ_VECTORS syscall_arg__strtoul_x86_irq_vectors 140 141 size_t syscall_arg__scnprintf_x86_MSR(char *bf, size_t size, struct syscall_arg *arg); 142 #define SCA_X86_MSR syscall_arg__scnprintf_x86_MSR 143 144 bool syscall_arg__strtoul_x86_MSR(char *bf, size_t size, struct syscall_arg *arg, u64 *ret); 145 #define STUL_X86_MSR syscall_arg__strtoul_x86_MSR 146 147 size_t syscall_arg__scnprintf_strarrays(char *bf, size_t size, struct syscall_arg *arg); 148 #define SCA_STRARRAYS syscall_arg__scnprintf_strarrays 149 150 size_t syscall_arg__scnprintf_fd(char *bf, size_t size, struct syscall_arg *arg); 151 #define SCA_FD syscall_arg__scnprintf_fd 152 153 size_t syscall_arg__scnprintf_hex(char *bf, size_t size, struct syscall_arg *arg); 154 #define SCA_HEX syscall_arg__scnprintf_hex 155 156 size_t syscall_arg__scnprintf_ptr(char *bf, size_t size, struct syscall_arg *arg); 157 #define SCA_PTR syscall_arg__scnprintf_ptr 158 159 size_t syscall_arg__scnprintf_int(char *bf, size_t size, struct syscall_arg *arg); 160 #define SCA_INT syscall_arg__scnprintf_int 161 162 size_t syscall_arg__scnprintf_long(char *bf, size_t size, struct syscall_arg *arg); 163 #define SCA_LONG syscall_arg__scnprintf_long 164 165 size_t syscall_arg__scnprintf_pid(char *bf, size_t size, struct syscall_arg *arg); 166 #define SCA_PID syscall_arg__scnprintf_pid 167 168 size_t syscall_arg__scnprintf_clone_flags(char *bf, size_t size, struct syscall_arg *arg); 169 #define SCA_CLONE_FLAGS syscall_arg__scnprintf_clone_flags 170 171 size_t syscall_arg__scnprintf_fcntl_cmd(char *bf, size_t size, struct syscall_arg *arg); 172 #define SCA_FCNTL_CMD syscall_arg__scnprintf_fcntl_cmd 173 174 size_t syscall_arg__scnprintf_fcntl_arg(char *bf, size_t size, struct syscall_arg *arg); 175 #define SCA_FCNTL_ARG syscall_arg__scnprintf_fcntl_arg 176 177 size_t syscall_arg__scnprintf_flock(char *bf, size_t size, struct syscall_arg *arg); 178 #define SCA_FLOCK syscall_arg__scnprintf_flock 179 180 size_t syscall_arg__scnprintf_fsmount_attr_flags(char *bf, size_t size, struct syscall_arg *arg); 181 #define SCA_FSMOUNT_ATTR_FLAGS syscall_arg__scnprintf_fsmount_attr_flags 182 183 size_t syscall_arg__scnprintf_fspick_flags(char *bf, size_t size, struct syscall_arg *arg); 184 #define SCA_FSPICK_FLAGS syscall_arg__scnprintf_fspick_flags 185 186 size_t syscall_arg__scnprintf_ioctl_cmd(char *bf, size_t size, struct syscall_arg *arg); 187 #define SCA_IOCTL_CMD syscall_arg__scnprintf_ioctl_cmd 188 189 size_t syscall_arg__scnprintf_kcmp_type(char *bf, size_t size, struct syscall_arg *arg); 190 #define SCA_KCMP_TYPE syscall_arg__scnprintf_kcmp_type 191 192 size_t syscall_arg__scnprintf_kcmp_idx(char *bf, size_t size, struct syscall_arg *arg); 193 #define SCA_KCMP_IDX syscall_arg__scnprintf_kcmp_idx 194 195 unsigned long syscall_arg__mask_val_mount_flags(struct syscall_arg *arg, unsigned long flags); 196 #define SCAMV_MOUNT_FLAGS syscall_arg__mask_val_mount_flags 197 198 size_t syscall_arg__scnprintf_mount_flags(char *bf, size_t size, struct syscall_arg *arg); 199 #define SCA_MOUNT_FLAGS syscall_arg__scnprintf_mount_flags 200 201 size_t syscall_arg__scnprintf_move_mount_flags(char *bf, size_t size, struct syscall_arg *arg); 202 #define SCA_MOVE_MOUNT_FLAGS syscall_arg__scnprintf_move_mount_flags 203 204 size_t syscall_arg__scnprintf_pkey_alloc_access_rights(char *bf, size_t size, struct syscall_arg *arg); 205 #define SCA_PKEY_ALLOC_ACCESS_RIGHTS syscall_arg__scnprintf_pkey_alloc_access_rights 206 207 size_t syscall_arg__scnprintf_open_flags(char *bf, size_t size, struct syscall_arg *arg); 208 #define SCA_OPEN_FLAGS syscall_arg__scnprintf_open_flags 209 210 size_t syscall_arg__scnprintf_x86_arch_prctl_code(char *bf, size_t size, struct syscall_arg *arg); 211 #define SCA_X86_ARCH_PRCTL_CODE syscall_arg__scnprintf_x86_arch_prctl_code 212 213 size_t syscall_arg__scnprintf_prctl_option(char *bf, size_t size, struct syscall_arg *arg); 214 #define SCA_PRCTL_OPTION syscall_arg__scnprintf_prctl_option 215 216 size_t syscall_arg__scnprintf_prctl_arg2(char *bf, size_t size, struct syscall_arg *arg); 217 #define SCA_PRCTL_ARG2 syscall_arg__scnprintf_prctl_arg2 218 219 size_t syscall_arg__scnprintf_prctl_arg3(char *bf, size_t size, struct syscall_arg *arg); 220 #define SCA_PRCTL_ARG3 syscall_arg__scnprintf_prctl_arg3 221 222 size_t syscall_arg__scnprintf_renameat2_flags(char *bf, size_t size, struct syscall_arg *arg); 223 #define SCA_RENAMEAT2_FLAGS syscall_arg__scnprintf_renameat2_flags 224 225 size_t syscall_arg__scnprintf_sockaddr(char *bf, size_t size, struct syscall_arg *arg); 226 #define SCA_SOCKADDR syscall_arg__scnprintf_sockaddr 227 228 size_t syscall_arg__scnprintf_socket_protocol(char *bf, size_t size, struct syscall_arg *arg); 229 #define SCA_SK_PROTO syscall_arg__scnprintf_socket_protocol 230 231 size_t syscall_arg__scnprintf_statx_flags(char *bf, size_t size, struct syscall_arg *arg); 232 #define SCA_STATX_FLAGS syscall_arg__scnprintf_statx_flags 233 234 size_t syscall_arg__scnprintf_statx_mask(char *bf, size_t size, struct syscall_arg *arg); 235 #define SCA_STATX_MASK syscall_arg__scnprintf_statx_mask 236 237 size_t syscall_arg__scnprintf_sync_file_range_flags(char *bf, size_t size, struct syscall_arg *arg); 238 #define SCA_SYNC_FILE_RANGE_FLAGS syscall_arg__scnprintf_sync_file_range_flags 239 240 size_t open__scnprintf_flags(unsigned long flags, char *bf, size_t size, bool show_prefix); 241 242 void syscall_arg__set_ret_scnprintf(struct syscall_arg *arg, 243 size_t (*ret_scnprintf)(char *bf, size_t size, struct syscall_arg *arg)); 244 245 const char *arch_syscalls__strerrno(const char *arch, int err); 246 247 #endif /* _PERF_TRACE_BEAUTY_H */ 248