Skip to content

Commit ed37aa0

Browse files
committed
add another c example
1 parent 655b7dc commit ed37aa0

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

examples/c-form/ex3-2.bpf.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <linux/bpf.h>
2+
#include <bpf/bpf_helpers.h>
3+
4+
#define u64 unsigned long long
5+
6+
// Define the map
7+
struct {
8+
__uint(type, BPF_MAP_TYPE_HASH);
9+
__type(key, u64);
10+
__type(value, u64);
11+
__uint(max_entries, 1);
12+
} last SEC(".maps");
13+
14+
// Handler for syscall entry
15+
SEC("tracepoint/syscalls/sys_enter_execve")
16+
int hello(void *ctx) {
17+
bpf_printk("entered");
18+
bpf_printk("multi constant support");
19+
return 0;
20+
}
21+
22+
// Handler for syscall exit
23+
SEC("tracepoint/syscalls/sys_exit_execve")
24+
long hello_again(void *ctx) {
25+
bpf_printk("exited");
26+
27+
// Create a key for map lookup
28+
u64 key = 0;
29+
30+
// Simple lookup without conditionals
31+
u64 *tsp = bpf_map_lookup_elem(&last, &key);
32+
33+
// Get current timestamp
34+
u64 ts = bpf_ktime_get_ns();
35+
36+
return 0;
37+
}
38+
39+
char LICENSE[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)