Skip to content

Commit 0d9dcd1

Browse files
Merge pull request #27 from pythonbpf/vmlinux
Add vmlinux transpiler from experiments
2 parents 8554688 + 8a69e05 commit 0d9dcd1

File tree

3 files changed

+415
-0
lines changed

3 files changed

+415
-0
lines changed

examples/kprobes.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from pythonbpf import bpf, section, bpfglobal, BPF
2+
from ctypes import c_void_p, c_int64
3+
4+
5+
@bpf
6+
@section("kretprobe/do_unlinkat")
7+
def hello_world(ctx: c_void_p) -> c_int64:
8+
print("Hello, World!")
9+
return c_int64(0)
10+
11+
@bpf
12+
@section("kprobe/do_unlinkat")
13+
def hello_world2(ctx: c_void_p) -> c_int64:
14+
print("Hello, World!")
15+
return c_int64(0)
16+
17+
@bpf
18+
@bpfglobal
19+
def LICENSE() -> str:
20+
return "GPL"
21+
22+
23+
b = BPF()
24+
b.load_and_attach()
25+
while True:
26+
print("running")
27+
# Now cat /sys/kernel/debug/tracing/trace_pipe to see results of unlink kprobe.

tests/c-form/kprobe.bpf.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "vmlinux.h"
2+
#include <bpf/bpf_helpers.h>
3+
#include <bpf/bpf_tracing.h>
4+
5+
char LICENSE[] SEC("license") = "Dual BSD/GPL";
6+
7+
SEC("kprobe/do_unlinkat")
8+
int kprobe_execve(struct pt_regs *ctx)
9+
{
10+
bpf_printk("unlinkat created");
11+
return 0;
12+
}
13+
14+
SEC("kretprobe/do_unlinkat")
15+
int kretprobe_execve(struct pt_regs *ctx)
16+
{
17+
bpf_printk("unlinkat returned\n");
18+
return 0;
19+
}

0 commit comments

Comments
 (0)