xref: /linux/include/trace/events/signal.h (revision 3eb66e91a25497065c5322b1268cbc3953642227)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2d1eb650fSMasami Hiramatsu #undef TRACE_SYSTEM
3d1eb650fSMasami Hiramatsu #define TRACE_SYSTEM signal
4d1eb650fSMasami Hiramatsu 
5d1eb650fSMasami Hiramatsu #if !defined(_TRACE_SIGNAL_H) || defined(TRACE_HEADER_MULTI_READ)
6d1eb650fSMasami Hiramatsu #define _TRACE_SIGNAL_H
7d1eb650fSMasami Hiramatsu 
8d1eb650fSMasami Hiramatsu #include <linux/signal.h>
9d1eb650fSMasami Hiramatsu #include <linux/sched.h>
10d1eb650fSMasami Hiramatsu #include <linux/tracepoint.h>
11d1eb650fSMasami Hiramatsu 
12d1eb650fSMasami Hiramatsu #define TP_STORE_SIGINFO(__entry, info)				\
13d1eb650fSMasami Hiramatsu 	do {							\
144ff4c31aSEric W. Biederman 		if (info == SEND_SIG_NOINFO) {			\
15d1eb650fSMasami Hiramatsu 			__entry->errno	= 0;			\
16d1eb650fSMasami Hiramatsu 			__entry->code	= SI_USER;		\
17d1eb650fSMasami Hiramatsu 		} else if (info == SEND_SIG_PRIV) {		\
18d1eb650fSMasami Hiramatsu 			__entry->errno	= 0;			\
19d1eb650fSMasami Hiramatsu 			__entry->code	= SI_KERNEL;		\
20d1eb650fSMasami Hiramatsu 		} else {					\
21d1eb650fSMasami Hiramatsu 			__entry->errno	= info->si_errno;	\
22d1eb650fSMasami Hiramatsu 			__entry->code	= info->si_code;	\
23d1eb650fSMasami Hiramatsu 		}						\
24d1eb650fSMasami Hiramatsu 	} while (0)
25d1eb650fSMasami Hiramatsu 
266c303d3aSOleg Nesterov #ifndef TRACE_HEADER_MULTI_READ
276c303d3aSOleg Nesterov enum {
286c303d3aSOleg Nesterov 	TRACE_SIGNAL_DELIVERED,
296c303d3aSOleg Nesterov 	TRACE_SIGNAL_IGNORED,
306c303d3aSOleg Nesterov 	TRACE_SIGNAL_ALREADY_PENDING,
316c303d3aSOleg Nesterov 	TRACE_SIGNAL_OVERFLOW_FAIL,
326c303d3aSOleg Nesterov 	TRACE_SIGNAL_LOSE_INFO,
336c303d3aSOleg Nesterov };
346c303d3aSOleg Nesterov #endif
356c303d3aSOleg Nesterov 
36d1eb650fSMasami Hiramatsu /**
37d1eb650fSMasami Hiramatsu  * signal_generate - called when a signal is generated
38d1eb650fSMasami Hiramatsu  * @sig: signal number
39d1eb650fSMasami Hiramatsu  * @info: pointer to struct siginfo
40d1eb650fSMasami Hiramatsu  * @task: pointer to struct task_struct
416c303d3aSOleg Nesterov  * @group: shared or private
426c303d3aSOleg Nesterov  * @result: TRACE_SIGNAL_*
43d1eb650fSMasami Hiramatsu  *
44d1eb650fSMasami Hiramatsu  * Current process sends a 'sig' signal to 'task' process with
45d1eb650fSMasami Hiramatsu  * 'info' siginfo. If 'info' is SEND_SIG_NOINFO or SEND_SIG_PRIV,
46d1eb650fSMasami Hiramatsu  * 'info' is not a pointer and you can't access its field. Instead,
47d1eb650fSMasami Hiramatsu  * SEND_SIG_NOINFO means that si_code is SI_USER, and SEND_SIG_PRIV
48d1eb650fSMasami Hiramatsu  * means that si_code is SI_KERNEL.
49d1eb650fSMasami Hiramatsu  */
50d1eb650fSMasami Hiramatsu TRACE_EVENT(signal_generate,
51d1eb650fSMasami Hiramatsu 
52*ae7795bcSEric W. Biederman 	TP_PROTO(int sig, struct kernel_siginfo *info, struct task_struct *task,
536c303d3aSOleg Nesterov 			int group, int result),
54d1eb650fSMasami Hiramatsu 
556c303d3aSOleg Nesterov 	TP_ARGS(sig, info, task, group, result),
56d1eb650fSMasami Hiramatsu 
57d1eb650fSMasami Hiramatsu 	TP_STRUCT__entry(
58d1eb650fSMasami Hiramatsu 		__field(	int,	sig			)
59d1eb650fSMasami Hiramatsu 		__field(	int,	errno			)
60d1eb650fSMasami Hiramatsu 		__field(	int,	code			)
61d1eb650fSMasami Hiramatsu 		__array(	char,	comm,	TASK_COMM_LEN	)
62d1eb650fSMasami Hiramatsu 		__field(	pid_t,	pid			)
636c303d3aSOleg Nesterov 		__field(	int,	group			)
646c303d3aSOleg Nesterov 		__field(	int,	result			)
65d1eb650fSMasami Hiramatsu 	),
66d1eb650fSMasami Hiramatsu 
67d1eb650fSMasami Hiramatsu 	TP_fast_assign(
68d1eb650fSMasami Hiramatsu 		__entry->sig	= sig;
69d1eb650fSMasami Hiramatsu 		TP_STORE_SIGINFO(__entry, info);
70d1eb650fSMasami Hiramatsu 		memcpy(__entry->comm, task->comm, TASK_COMM_LEN);
71d1eb650fSMasami Hiramatsu 		__entry->pid	= task->pid;
726c303d3aSOleg Nesterov 		__entry->group	= group;
736c303d3aSOleg Nesterov 		__entry->result	= result;
74d1eb650fSMasami Hiramatsu 	),
75d1eb650fSMasami Hiramatsu 
766c303d3aSOleg Nesterov 	TP_printk("sig=%d errno=%d code=%d comm=%s pid=%d grp=%d res=%d",
77d1eb650fSMasami Hiramatsu 		  __entry->sig, __entry->errno, __entry->code,
786c303d3aSOleg Nesterov 		  __entry->comm, __entry->pid, __entry->group,
796c303d3aSOleg Nesterov 		  __entry->result)
80d1eb650fSMasami Hiramatsu );
81d1eb650fSMasami Hiramatsu 
82f9d4257eSMasami Hiramatsu /**
83f9d4257eSMasami Hiramatsu  * signal_deliver - called when a signal is delivered
84f9d4257eSMasami Hiramatsu  * @sig: signal number
85f9d4257eSMasami Hiramatsu  * @info: pointer to struct siginfo
86f9d4257eSMasami Hiramatsu  * @ka: pointer to struct k_sigaction
87f9d4257eSMasami Hiramatsu  *
88f9d4257eSMasami Hiramatsu  * A 'sig' signal is delivered to current process with 'info' siginfo,
89f9d4257eSMasami Hiramatsu  * and it will be handled by 'ka'. ka->sa.sa_handler can be SIG_IGN or
90f9d4257eSMasami Hiramatsu  * SIG_DFL.
91f9d4257eSMasami Hiramatsu  * Note that some signals reported by signal_generate tracepoint can be
92f9d4257eSMasami Hiramatsu  * lost, ignored or modified (by debugger) before hitting this tracepoint.
93f9d4257eSMasami Hiramatsu  * This means, this can show which signals are actually delivered, but
94f9d4257eSMasami Hiramatsu  * matching generated signals and delivered signals may not be correct.
95f9d4257eSMasami Hiramatsu  */
96f9d4257eSMasami Hiramatsu TRACE_EVENT(signal_deliver,
97f9d4257eSMasami Hiramatsu 
98*ae7795bcSEric W. Biederman 	TP_PROTO(int sig, struct kernel_siginfo *info, struct k_sigaction *ka),
99f9d4257eSMasami Hiramatsu 
100f9d4257eSMasami Hiramatsu 	TP_ARGS(sig, info, ka),
101f9d4257eSMasami Hiramatsu 
102f9d4257eSMasami Hiramatsu 	TP_STRUCT__entry(
103f9d4257eSMasami Hiramatsu 		__field(	int,		sig		)
104f9d4257eSMasami Hiramatsu 		__field(	int,		errno		)
105f9d4257eSMasami Hiramatsu 		__field(	int,		code		)
106f9d4257eSMasami Hiramatsu 		__field(	unsigned long,	sa_handler	)
107f9d4257eSMasami Hiramatsu 		__field(	unsigned long,	sa_flags	)
108f9d4257eSMasami Hiramatsu 	),
109f9d4257eSMasami Hiramatsu 
110f9d4257eSMasami Hiramatsu 	TP_fast_assign(
111f9d4257eSMasami Hiramatsu 		__entry->sig	= sig;
112f9d4257eSMasami Hiramatsu 		TP_STORE_SIGINFO(__entry, info);
113f9d4257eSMasami Hiramatsu 		__entry->sa_handler	= (unsigned long)ka->sa.sa_handler;
114f9d4257eSMasami Hiramatsu 		__entry->sa_flags	= ka->sa.sa_flags;
115f9d4257eSMasami Hiramatsu 	),
116f9d4257eSMasami Hiramatsu 
117f9d4257eSMasami Hiramatsu 	TP_printk("sig=%d errno=%d code=%d sa_handler=%lx sa_flags=%lx",
118f9d4257eSMasami Hiramatsu 		  __entry->sig, __entry->errno, __entry->code,
119f9d4257eSMasami Hiramatsu 		  __entry->sa_handler, __entry->sa_flags)
120f9d4257eSMasami Hiramatsu );
121ba005e1fSMasami Hiramatsu 
122d1eb650fSMasami Hiramatsu #endif /* _TRACE_SIGNAL_H */
123d1eb650fSMasami Hiramatsu 
124d1eb650fSMasami Hiramatsu /* This part must be outside protection */
125d1eb650fSMasami Hiramatsu #include <trace/define_trace.h>
126