Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 // Copyright (c) 2019 Facebook
0003 #include <linux/bpf.h>
0004 #include <linux/version.h>
0005 #include <bpf/bpf_helpers.h>
0006 
0007 __u32 sig = 0, pid = 0, status = 0, signal_thread = 0;
0008 
0009 static __always_inline int bpf_send_signal_test(void *ctx)
0010 {
0011     int ret;
0012 
0013     if (status != 0 || pid == 0)
0014         return 0;
0015 
0016     if ((bpf_get_current_pid_tgid() >> 32) == pid) {
0017         if (signal_thread)
0018             ret = bpf_send_signal_thread(sig);
0019         else
0020             ret = bpf_send_signal(sig);
0021         if (ret == 0)
0022             status = 1;
0023     }
0024 
0025     return 0;
0026 }
0027 
0028 SEC("tracepoint/syscalls/sys_enter_nanosleep")
0029 int send_signal_tp(void *ctx)
0030 {
0031     return bpf_send_signal_test(ctx);
0032 }
0033 
0034 SEC("tracepoint/sched/sched_switch")
0035 int send_signal_tp_sched(void *ctx)
0036 {
0037     return bpf_send_signal_test(ctx);
0038 }
0039 
0040 SEC("perf_event")
0041 int send_signal_perf(void *ctx)
0042 {
0043     return bpf_send_signal_test(ctx);
0044 }
0045 
0046 char __license[] SEC("license") = "GPL";