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