xref: /linux/tools/testing/selftests/bpf/progs/test_send_signal_kern.c (revision 24bce201d79807b668bf9d9e0aca801c5c0d5f78)
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2019 Facebook
3 #include <linux/bpf.h>
4 #include <linux/version.h>
5 #include <bpf/bpf_helpers.h>
6 
7 __u32 sig = 0, pid = 0, status = 0, signal_thread = 0;
8 
9 static __always_inline int bpf_send_signal_test(void *ctx)
10 {
11 	int ret;
12 
13 	if (status != 0 || pid == 0)
14 		return 0;
15 
16 	if ((bpf_get_current_pid_tgid() >> 32) == pid) {
17 		if (signal_thread)
18 			ret = bpf_send_signal_thread(sig);
19 		else
20 			ret = bpf_send_signal(sig);
21 		if (ret == 0)
22 			status = 1;
23 	}
24 
25 	return 0;
26 }
27 
28 SEC("tracepoint/syscalls/sys_enter_nanosleep")
29 int send_signal_tp(void *ctx)
30 {
31 	return bpf_send_signal_test(ctx);
32 }
33 
34 SEC("tracepoint/sched/sched_switch")
35 int send_signal_tp_sched(void *ctx)
36 {
37 	return bpf_send_signal_test(ctx);
38 }
39 
40 SEC("perf_event")
41 int send_signal_perf(void *ctx)
42 {
43 	return bpf_send_signal_test(ctx);
44 }
45 
46 char __license[] SEC("license") = "GPL";
47