1 // SPDX-License-Identifier: GPL-2.0
2 
3 #include "vmlinux.h"
4 #include <bpf/bpf_helpers.h>
5 #include <bpf/usdt.bpf.h>
6 
7 struct {
8     __uint(type, BPF_MAP_TYPE_RINGBUF);
9     __uint(max_entries, 4096 /* one page */);
10 } ringbuf SEC(".maps");
11 
12 SEC("uprobe")
handle__uprobe(void * ctx)13 int handle__uprobe(void *ctx)
14 {
15     int *value;
16 
17     value = bpf_ringbuf_reserve(&ringbuf, sizeof(int), 0);
18     if (!value) {
19         bpf_printk("handle__uprobe: failed to reserve ring buffer space");
20         return 1;
21     }
22 
23     *value = 1;
24     bpf_ringbuf_submit(value, 0);
25     bpf_printk("handle__uprobe: submitted ringbuf value");
26     return 0;
27 }
28 
29 SEC("uprobe")
handle__uprobe_with_cookie(void * ctx)30 int handle__uprobe_with_cookie(void *ctx)
31 {
32     int *value;
33 
34     value = bpf_ringbuf_reserve(&ringbuf, sizeof(int), 0);
35     if (!value) {
36         bpf_printk("handle__uprobe_with_cookie: failed to reserve ring buffer space");
37         return 1;
38     }
39 
40     *value = bpf_get_attach_cookie(ctx);
41     bpf_printk("handle__uprobe_with_cookie: cookie=%d", *value);
42     bpf_ringbuf_submit(value, 0);
43     return 0;
44 }
45 
46 char LICENSE[] SEC("license") = "GPL";
47