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