116f0efc3SYonghong Song // SPDX-License-Identifier: GPL-2.0 216f0efc3SYonghong Song // Copyright (c) 2019 Facebook 316f0efc3SYonghong Song #include <linux/bpf.h> 416f0efc3SYonghong Song #include <linux/version.h> 53e689141SToke Høiland-Jørgensen #include <bpf/bpf_helpers.h> 616f0efc3SYonghong Song 7ab8b7f0cSYonghong Song __u32 sig = 0, pid = 0, status = 0, signal_thread = 0; 816f0efc3SYonghong Song bpf_send_signal_test(void * ctx)9ab8b7f0cSYonghong Songstatic __always_inline int bpf_send_signal_test(void *ctx) 1016f0efc3SYonghong Song { 1116f0efc3SYonghong Song int ret; 1216f0efc3SYonghong Song 13*1fd49864SMykola Lysenko if (status != 0 || pid == 0) 1416f0efc3SYonghong Song return 0; 1516f0efc3SYonghong Song 1616f0efc3SYonghong Song if ((bpf_get_current_pid_tgid() >> 32) == pid) { 17ab8b7f0cSYonghong Song if (signal_thread) 18ab8b7f0cSYonghong Song ret = bpf_send_signal_thread(sig); 19ab8b7f0cSYonghong Song else 2016f0efc3SYonghong Song ret = bpf_send_signal(sig); 2116f0efc3SYonghong Song if (ret == 0) 22ab8b7f0cSYonghong Song status = 1; 2316f0efc3SYonghong Song } 2416f0efc3SYonghong Song 2516f0efc3SYonghong Song return 0; 2616f0efc3SYonghong Song } 27ab8b7f0cSYonghong Song 28ab8b7f0cSYonghong Song SEC("tracepoint/syscalls/sys_enter_nanosleep") send_signal_tp(void * ctx)29ab8b7f0cSYonghong Songint send_signal_tp(void *ctx) 30ab8b7f0cSYonghong Song { 31ab8b7f0cSYonghong Song return bpf_send_signal_test(ctx); 32ab8b7f0cSYonghong Song } 33ab8b7f0cSYonghong Song 34c4ef2f32SYonghong Song SEC("tracepoint/sched/sched_switch") send_signal_tp_sched(void * ctx)35c4ef2f32SYonghong Songint send_signal_tp_sched(void *ctx) 36c4ef2f32SYonghong Song { 37c4ef2f32SYonghong Song return bpf_send_signal_test(ctx); 38c4ef2f32SYonghong Song } 39c4ef2f32SYonghong Song 40ab8b7f0cSYonghong Song SEC("perf_event") send_signal_perf(void * ctx)41ab8b7f0cSYonghong Songint send_signal_perf(void *ctx) 42ab8b7f0cSYonghong Song { 43ab8b7f0cSYonghong Song return bpf_send_signal_test(ctx); 44ab8b7f0cSYonghong Song } 45ab8b7f0cSYonghong Song 4616f0efc3SYonghong Song char __license[] SEC("license") = "GPL"; 47