xref: /openbmc/linux/include/trace/events/signal.h (revision 0bf49ffb)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #undef TRACE_SYSTEM
3 #define TRACE_SYSTEM signal
4 
5 #if !defined(_TRACE_SIGNAL_H) || defined(TRACE_HEADER_MULTI_READ)
6 #define _TRACE_SIGNAL_H
7 
8 #include <linux/signal.h>
9 #include <linux/sched.h>
10 #include <linux/tracepoint.h>
11 
12 #define TP_STORE_SIGINFO(__entry, info)				\
13 	do {							\
14 		if (info == SEND_SIG_NOINFO) {			\
15 			__entry->errno	= 0;			\
16 			__entry->code	= SI_USER;		\
17 		} else if (info == SEND_SIG_PRIV) {		\
18 			__entry->errno	= 0;			\
19 			__entry->code	= SI_KERNEL;		\
20 		} else {					\
21 			__entry->errno	= info->si_errno;	\
22 			__entry->code	= info->si_code;	\
23 		}						\
24 	} while (0)
25 
26 #ifndef TRACE_HEADER_MULTI_READ
27 enum {
28 	TRACE_SIGNAL_DELIVERED,
29 	TRACE_SIGNAL_IGNORED,
30 	TRACE_SIGNAL_ALREADY_PENDING,
31 	TRACE_SIGNAL_OVERFLOW_FAIL,
32 	TRACE_SIGNAL_LOSE_INFO,
33 };
34 #endif
35 
36 /**
37  * signal_generate - called when a signal is generated
38  * @sig: signal number
39  * @info: pointer to struct siginfo
40  * @task: pointer to struct task_struct
41  * @group: shared or private
42  * @result: TRACE_SIGNAL_*
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 TRACE_EVENT(signal_generate,
51 
52 	TP_PROTO(int sig, struct kernel_siginfo *info, struct task_struct *task,
53 			int group, int result),
54 
55 	TP_ARGS(sig, info, task, group, result),
56 
57 	TP_STRUCT__entry(
58 		__field(	int,	sig			)
59 		__field(	int,	errno			)
60 		__field(	int,	code			)
61 		__array(	char,	comm,	TASK_COMM_LEN	)
62 		__field(	pid_t,	pid			)
63 		__field(	int,	group			)
64 		__field(	int,	result			)
65 	),
66 
67 	TP_fast_assign(
68 		__entry->sig	= sig;
69 		TP_STORE_SIGINFO(__entry, info);
70 		memcpy(__entry->comm, task->comm, TASK_COMM_LEN);
71 		__entry->pid	= task->pid;
72 		__entry->group	= group;
73 		__entry->result	= result;
74 	),
75 
76 	TP_printk("sig=%d errno=%d code=%d comm=%s pid=%d grp=%d res=%d",
77 		  __entry->sig, __entry->errno, __entry->code,
78 		  __entry->comm, __entry->pid, __entry->group,
79 		  __entry->result)
80 );
81 
82 /**
83  * signal_deliver - called when a signal is delivered
84  * @sig: signal number
85  * @info: pointer to struct siginfo
86  * @ka: pointer to struct k_sigaction
87  *
88  * A 'sig' signal is delivered to current process with 'info' siginfo,
89  * and it will be handled by 'ka'. ka->sa.sa_handler can be SIG_IGN or
90  * SIG_DFL.
91  * Note that some signals reported by signal_generate tracepoint can be
92  * lost, ignored or modified (by debugger) before hitting this tracepoint.
93  * This means, this can show which signals are actually delivered, but
94  * matching generated signals and delivered signals may not be correct.
95  */
96 TRACE_EVENT(signal_deliver,
97 
98 	TP_PROTO(int sig, struct kernel_siginfo *info, struct k_sigaction *ka),
99 
100 	TP_ARGS(sig, info, ka),
101 
102 	TP_STRUCT__entry(
103 		__field(	int,		sig		)
104 		__field(	int,		errno		)
105 		__field(	int,		code		)
106 		__field(	unsigned long,	sa_handler	)
107 		__field(	unsigned long,	sa_flags	)
108 	),
109 
110 	TP_fast_assign(
111 		__entry->sig	= sig;
112 		TP_STORE_SIGINFO(__entry, info);
113 		__entry->sa_handler	= (unsigned long)ka->sa.sa_handler;
114 		__entry->sa_flags	= ka->sa.sa_flags;
115 	),
116 
117 	TP_printk("sig=%d errno=%d code=%d sa_handler=%lx sa_flags=%lx",
118 		  __entry->sig, __entry->errno, __entry->code,
119 		  __entry->sa_handler, __entry->sa_flags)
120 );
121 
122 #endif /* _TRACE_SIGNAL_H */
123 
124 /* This part must be outside protection */
125 #include <trace/define_trace.h>
126