| 1 | #undef TRACE_SYSTEM |
| 2 | #define TRACE_SYSTEM signal |
| 3 | |
| 4 | #if !defined(LTTNG_TRACE_SIGNAL_H) || defined(TRACE_HEADER_MULTI_READ) |
| 5 | #define LTTNG_TRACE_SIGNAL_H |
| 6 | |
| 7 | #include <probes/lttng-tracepoint-event.h> |
| 8 | #include <linux/version.h> |
| 9 | |
| 10 | #ifndef _TRACE_SIGNAL_DEF |
| 11 | #define _TRACE_SIGNAL_DEF |
| 12 | #include <linux/signal.h> |
| 13 | #include <linux/sched.h> |
| 14 | #undef LTTNG_FIELDS_SIGINFO |
| 15 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,20,0)) |
| 16 | #define LTTNG_FIELDS_SIGINFO(info) \ |
| 17 | ctf_integer(int, errno, \ |
| 18 | (info == SEND_SIG_NOINFO || info == SEND_SIG_PRIV) ? \ |
| 19 | 0 : \ |
| 20 | info->si_errno) \ |
| 21 | ctf_integer(int, code, \ |
| 22 | (info == SEND_SIG_NOINFO) ? \ |
| 23 | SI_USER : \ |
| 24 | ((info == SEND_SIG_PRIV) ? SI_KERNEL : info->si_code)) |
| 25 | #else /* LINUX_VERSION_CODE >= KERNEL_VERSION(4,20,0) */ |
| 26 | #define LTTNG_FIELDS_SIGINFO(info) \ |
| 27 | ctf_integer(int, errno, \ |
| 28 | (info == SEND_SIG_NOINFO || info == SEND_SIG_FORCED || info == SEND_SIG_PRIV) ? \ |
| 29 | 0 : \ |
| 30 | info->si_errno) \ |
| 31 | ctf_integer(int, code, \ |
| 32 | (info == SEND_SIG_NOINFO || info == SEND_SIG_FORCED) ? \ |
| 33 | SI_USER : \ |
| 34 | ((info == SEND_SIG_PRIV) ? SI_KERNEL : info->si_code)) |
| 35 | #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4,20,0) */ |
| 36 | #endif /* _TRACE_SIGNAL_DEF */ |
| 37 | |
| 38 | /** |
| 39 | * signal_generate - called when a signal is generated |
| 40 | * @sig: signal number |
| 41 | * @info: pointer to struct siginfo |
| 42 | * @task: pointer to struct task_struct |
| 43 | * |
| 44 | * Current process sends a 'sig' signal to 'task' process with |
| 45 | * 'info' siginfo. If 'info' is SEND_SIG_NOINFO or SEND_SIG_PRIV, |
| 46 | * 'info' is not a pointer and you can't access its field. Instead, |
| 47 | * SEND_SIG_NOINFO means that si_code is SI_USER, and SEND_SIG_PRIV |
| 48 | * means that si_code is SI_KERNEL. |
| 49 | */ |
| 50 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,20,0)) |
| 51 | LTTNG_TRACEPOINT_EVENT(signal_generate, |
| 52 | |
| 53 | TP_PROTO(int sig, struct kernel_siginfo *info, struct task_struct *task, |
| 54 | int group, int result), |
| 55 | |
| 56 | TP_ARGS(sig, info, task, group, result), |
| 57 | |
| 58 | TP_FIELDS( |
| 59 | ctf_integer(int, sig, sig) |
| 60 | LTTNG_FIELDS_SIGINFO(info) |
| 61 | ctf_array_text(char, comm, task->comm, TASK_COMM_LEN) |
| 62 | ctf_integer(pid_t, pid, task->pid) |
| 63 | ctf_integer(int, group, group) |
| 64 | ctf_integer(int, result, result) |
| 65 | ) |
| 66 | ) |
| 67 | #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)) |
| 68 | LTTNG_TRACEPOINT_EVENT(signal_generate, |
| 69 | |
| 70 | TP_PROTO(int sig, struct siginfo *info, struct task_struct *task, |
| 71 | int group, int result), |
| 72 | |
| 73 | TP_ARGS(sig, info, task, group, result), |
| 74 | |
| 75 | TP_FIELDS( |
| 76 | ctf_integer(int, sig, sig) |
| 77 | LTTNG_FIELDS_SIGINFO(info) |
| 78 | ctf_array_text(char, comm, task->comm, TASK_COMM_LEN) |
| 79 | ctf_integer(pid_t, pid, task->pid) |
| 80 | ctf_integer(int, group, group) |
| 81 | ctf_integer(int, result, result) |
| 82 | ) |
| 83 | ) |
| 84 | #else |
| 85 | LTTNG_TRACEPOINT_EVENT(signal_generate, |
| 86 | |
| 87 | TP_PROTO(int sig, struct siginfo *info, struct task_struct *task), |
| 88 | |
| 89 | TP_ARGS(sig, info, task), |
| 90 | |
| 91 | TP_FIELDS( |
| 92 | ctf_integer(int, sig, sig) |
| 93 | LTTNG_FIELDS_SIGINFO(info) |
| 94 | ctf_array_text(char, comm, task->comm, TASK_COMM_LEN) |
| 95 | ctf_integer(pid_t, pid, task->pid) |
| 96 | ) |
| 97 | ) |
| 98 | #endif |
| 99 | |
| 100 | /** |
| 101 | * signal_deliver - called when a signal is delivered |
| 102 | * @sig: signal number |
| 103 | * @info: pointer to struct siginfo |
| 104 | * @ka: pointer to struct k_sigaction |
| 105 | * |
| 106 | * A 'sig' signal is delivered to current process with 'info' siginfo, |
| 107 | * and it will be handled by 'ka'. ka->sa.sa_handler can be SIG_IGN or |
| 108 | * SIG_DFL. |
| 109 | * Note that some signals reported by signal_generate tracepoint can be |
| 110 | * lost, ignored or modified (by debugger) before hitting this tracepoint. |
| 111 | * This means, this can show which signals are actually delivered, but |
| 112 | * matching generated signals and delivered signals may not be correct. |
| 113 | */ |
| 114 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,20,0)) |
| 115 | LTTNG_TRACEPOINT_EVENT(signal_deliver, |
| 116 | |
| 117 | TP_PROTO(int sig, struct kernel_siginfo *info, struct k_sigaction *ka), |
| 118 | |
| 119 | TP_ARGS(sig, info, ka), |
| 120 | |
| 121 | TP_FIELDS( |
| 122 | ctf_integer(int, sig, sig) |
| 123 | LTTNG_FIELDS_SIGINFO(info) |
| 124 | ctf_integer(unsigned long, sa_handler, (unsigned long) ka->sa.sa_handler) |
| 125 | ctf_integer(unsigned long, sa_flags, ka->sa.sa_flags) |
| 126 | ) |
| 127 | ) |
| 128 | #else |
| 129 | LTTNG_TRACEPOINT_EVENT(signal_deliver, |
| 130 | |
| 131 | TP_PROTO(int sig, struct siginfo *info, struct k_sigaction *ka), |
| 132 | |
| 133 | TP_ARGS(sig, info, ka), |
| 134 | |
| 135 | TP_FIELDS( |
| 136 | ctf_integer(int, sig, sig) |
| 137 | LTTNG_FIELDS_SIGINFO(info) |
| 138 | ctf_integer(unsigned long, sa_handler, (unsigned long) ka->sa.sa_handler) |
| 139 | ctf_integer(unsigned long, sa_flags, ka->sa.sa_flags) |
| 140 | ) |
| 141 | ) |
| 142 | #endif |
| 143 | |
| 144 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0)) |
| 145 | LTTNG_TRACEPOINT_EVENT_CLASS(signal_queue_overflow, |
| 146 | |
| 147 | TP_PROTO(int sig, int group, struct siginfo *info), |
| 148 | |
| 149 | TP_ARGS(sig, group, info), |
| 150 | |
| 151 | TP_FIELDS( |
| 152 | ctf_integer(int, sig, sig) |
| 153 | ctf_integer(int, group, group) |
| 154 | LTTNG_FIELDS_SIGINFO(info) |
| 155 | ) |
| 156 | ) |
| 157 | |
| 158 | /** |
| 159 | * signal_overflow_fail - called when signal queue is overflow |
| 160 | * @sig: signal number |
| 161 | * @group: signal to process group or not (bool) |
| 162 | * @info: pointer to struct siginfo |
| 163 | * |
| 164 | * Kernel fails to generate 'sig' signal with 'info' siginfo, because |
| 165 | * siginfo queue is overflow, and the signal is dropped. |
| 166 | * 'group' is not 0 if the signal will be sent to a process group. |
| 167 | * 'sig' is always one of RT signals. |
| 168 | */ |
| 169 | LTTNG_TRACEPOINT_EVENT_INSTANCE(signal_queue_overflow, signal_overflow_fail, |
| 170 | |
| 171 | TP_PROTO(int sig, int group, struct siginfo *info), |
| 172 | |
| 173 | TP_ARGS(sig, group, info) |
| 174 | ) |
| 175 | |
| 176 | /** |
| 177 | * signal_lose_info - called when siginfo is lost |
| 178 | * @sig: signal number |
| 179 | * @group: signal to process group or not (bool) |
| 180 | * @info: pointer to struct siginfo |
| 181 | * |
| 182 | * Kernel generates 'sig' signal but loses 'info' siginfo, because siginfo |
| 183 | * queue is overflow. |
| 184 | * 'group' is not 0 if the signal will be sent to a process group. |
| 185 | * 'sig' is always one of non-RT signals. |
| 186 | */ |
| 187 | LTTNG_TRACEPOINT_EVENT_INSTANCE(signal_queue_overflow, signal_lose_info, |
| 188 | |
| 189 | TP_PROTO(int sig, int group, struct siginfo *info), |
| 190 | |
| 191 | TP_ARGS(sig, group, info) |
| 192 | ) |
| 193 | #endif |
| 194 | |
| 195 | #endif /* LTTNG_TRACE_SIGNAL_H */ |
| 196 | |
| 197 | /* This part must be outside protection */ |
| 198 | #include <probes/define_trace.h> |