1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2017 Facebook
3 
4 #include <linux/ptrace.h>
5 #include <linux/bpf.h>
6 #include "bpf_helpers.h"
7 
8 struct {
9 	__uint(type, BPF_MAP_TYPE_ARRAY);
10 	__uint(max_entries, 4);
11 	__type(key, int);
12 	__type(value, int);
13 } results_map SEC(".maps");
14 
15 SEC("kprobe/sys_nanosleep")
16 int handle_sys_nanosleep_entry(struct pt_regs *ctx)
17 {
18 	const int key = 0, value = 1;
19 
20 	bpf_map_update_elem(&results_map, &key, &value, 0);
21 	return 0;
22 }
23 
24 SEC("kretprobe/sys_nanosleep")
25 int handle_sys_getpid_return(struct pt_regs *ctx)
26 {
27 	const int key = 1, value = 2;
28 
29 	bpf_map_update_elem(&results_map, &key, &value, 0);
30 	return 0;
31 }
32 
33 SEC("uprobe/trigger_func")
34 int handle_uprobe_entry(struct pt_regs *ctx)
35 {
36 	const int key = 2, value = 3;
37 
38 	bpf_map_update_elem(&results_map, &key, &value, 0);
39 	return 0;
40 }
41 
42 SEC("uretprobe/trigger_func")
43 int handle_uprobe_return(struct pt_regs *ctx)
44 {
45 	const int key = 3, value = 4;
46 
47 	bpf_map_update_elem(&results_map, &key, &value, 0);
48 	return 0;
49 }
50 
51 char _license[] SEC("license") = "GPL";
52 __u32 _version SEC("version") = 1;
53