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_helpers.h" 6 7 struct { 8 __u32 type; 9 __u32 max_entries; 10 __u32 *key; 11 __u64 *value; 12 } info_map SEC(".maps") = { 13 .type = BPF_MAP_TYPE_ARRAY, 14 .max_entries = 1, 15 }; 16 17 struct { 18 __u32 type; 19 __u32 max_entries; 20 __u32 *key; 21 __u64 *value; 22 } status_map SEC(".maps") = { 23 .type = BPF_MAP_TYPE_ARRAY, 24 .max_entries = 1, 25 }; 26 27 SEC("send_signal_demo") 28 int bpf_send_signal_test(void *ctx) 29 { 30 __u64 *info_val, *status_val; 31 __u32 key = 0, pid, sig; 32 int ret; 33 34 status_val = bpf_map_lookup_elem(&status_map, &key); 35 if (!status_val || *status_val != 0) 36 return 0; 37 38 info_val = bpf_map_lookup_elem(&info_map, &key); 39 if (!info_val || *info_val == 0) 40 return 0; 41 42 sig = *info_val >> 32; 43 pid = *info_val & 0xffffFFFF; 44 45 if ((bpf_get_current_pid_tgid() >> 32) == pid) { 46 ret = bpf_send_signal(sig); 47 if (ret == 0) 48 *status_val = 1; 49 } 50 51 return 0; 52 } 53 char __license[] SEC("license") = "GPL"; 54