From ed37aa01d2609a4cbd22a0dd34fbd41efd71a4a9 Mon Sep 17 00:00:00 2001 From: Pragyansh Chaturvedi Date: Mon, 8 Sep 2025 22:43:24 +0530 Subject: [PATCH] add another c example --- examples/c-form/ex3-2.bpf.c | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 examples/c-form/ex3-2.bpf.c diff --git a/examples/c-form/ex3-2.bpf.c b/examples/c-form/ex3-2.bpf.c new file mode 100644 index 0000000..3091e6a --- /dev/null +++ b/examples/c-form/ex3-2.bpf.c @@ -0,0 +1,39 @@ +#include +#include + +#define u64 unsigned long long + +// Define the map +struct { + __uint(type, BPF_MAP_TYPE_HASH); + __type(key, u64); + __type(value, u64); + __uint(max_entries, 1); +} last SEC(".maps"); + +// Handler for syscall entry +SEC("tracepoint/syscalls/sys_enter_execve") +int hello(void *ctx) { + bpf_printk("entered"); + bpf_printk("multi constant support"); + return 0; +} + +// Handler for syscall exit +SEC("tracepoint/syscalls/sys_exit_execve") +long hello_again(void *ctx) { + bpf_printk("exited"); + + // Create a key for map lookup + u64 key = 0; + + // Simple lookup without conditionals + u64 *tsp = bpf_map_lookup_elem(&last, &key); + + // Get current timestamp + u64 ts = bpf_ktime_get_ns(); + + return 0; +} + +char LICENSE[] SEC("license") = "GPL";