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