1 // SPDX-License-Identifier: GPL-2.0
2 
3 #include "vmlinux.h"
4 #include <bpf/bpf_helpers.h>
5 
6 struct {
7     __uint(type, BPF_MAP_TYPE_RINGBUF);
8     __uint(max_entries, 4096 /* one page */);
9 } ringbuf SEC(".maps");
10 
11 SEC("tracepoint/syscalls/sys_enter_getpid")
handle__tracepoint(void * ctx)12 int handle__tracepoint(void *ctx)
13 {
14     int *value;
15 
16     value = bpf_ringbuf_reserve(&ringbuf, sizeof(int), 0);
17     if (!value) {
18         bpf_printk("handle__tracepoint: failed to reserve ring buffer space");
19         return 1;
20     }
21 
22     *value = 1;
23     bpf_ringbuf_submit(value, 0);
24     bpf_printk("handle__tracepoint: submitted ringbuf value");
25     return 0;
26 }
27 
28 SEC("tracepoint/syscalls/sys_enter_getpid")
handle__tracepoint_with_cookie(void * ctx)29 int handle__tracepoint_with_cookie(void *ctx)
30 {
31     int *value;
32 
33     value = bpf_ringbuf_reserve(&ringbuf, sizeof(int), 0);
34     if (!value) {
35         bpf_printk("handle__tracepoint_with_cookie: failed to reserve ring buffer space");
36         return 1;
37     }
38 
39     *value = bpf_get_attach_cookie(ctx);
40     bpf_printk("handle__tracepoint_with_cookie: cookie=%d", *value);
41     bpf_ringbuf_submit(value, 0);
42     return 0;
43 }
44 
45 struct {
46     __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
47     __uint(key_size, sizeof(int));
48     __uint(value_size, sizeof(int));
49 } pb SEC(".maps");
50 
51 SEC("tracepoint/syscalls/sys_enter_getpid")
handle__tracepoint_with_cookie_pb(void * ctx)52 int handle__tracepoint_with_cookie_pb(void *ctx)
53 {
54     int value = bpf_get_attach_cookie(ctx);
55     bpf_perf_event_output(ctx, &pb, BPF_F_CURRENT_CPU, &value, sizeof(value));
56 
57     return 0;
58 }
59 
60 struct {
61     __uint(type, BPF_MAP_TYPE_QUEUE);
62     __uint(max_entries, 10);
63     __uint(key, 0);
64     __type(value, __u32);
65 } queue SEC(".maps");
66 
67 struct {
68     __uint(type, BPF_MAP_TYPE_STACK);
69     __uint(max_entries, 10);
70     __uint(key, 0);
71     __type(value, __u32);
72 } stack SEC(".maps");
73 
74 struct {
75     __uint(type, BPF_MAP_TYPE_BLOOM_FILTER);
76     __uint(max_entries, 5);
77     __type(value, __u32);
78 } bloom_filter SEC(".maps");
79 
80 char LICENSE[] SEC("license") = "GPL";
81