Skip to content

Commit ba39703

Browse files
add failing examples to work on
1 parent 1a0e21e commit ba39703

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
BPF_CLANG := clang
2+
CFLAGS := -O2 -emit-llvm -target bpf -c
3+
4+
SRC := $(wildcard *.bpf.c)
5+
LL := $(SRC:.bpf.c=.bpf.ll)
6+
OBJ := $(SRC:.bpf.c=.bpf.o)
7+
8+
.PHONY: all clean
9+
10+
all: $(LL) $(OBJ)
11+
12+
%.bpf.o: %.bpf.c
13+
$(BPF_CLANG) -O2 -g -target bpf -c $< -o $@
14+
15+
%.bpf.ll: %.bpf.c
16+
$(BPF_CLANG) $(CFLAGS) -g -S $< -o $@
17+
18+
clean:
19+
rm -f $(LL) $(OBJ)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import logging
2+
3+
from pythonbpf import bpf, section, bpfglobal, compile_to_ir
4+
from pythonbpf import compile # noqa: F401
5+
from vmlinux import TASK_COMM_LEN # noqa: F401
6+
from vmlinux import struct_trace_event_raw_sys_enter # noqa: F401
7+
from ctypes import c_uint64, c_int32, c_int64
8+
from pythonbpf.maps import HashMap
9+
10+
# from vmlinux import struct_uinput_device
11+
# from vmlinux import struct_blk_integrity_iter
12+
13+
@bpf
14+
@section("tracepoint/syscalls/sys_enter_execve")
15+
def hello_world(ctx: struct_trace_event_raw_sys_enter) -> c_int64:
16+
a = 2 + TASK_COMM_LEN + TASK_COMM_LEN
17+
print(f"Hello, World{TASK_COMM_LEN} and {a}")
18+
return c_int64(TASK_COMM_LEN + 2)
19+
20+
21+
@bpf
22+
@bpfglobal
23+
def LICENSE() -> str:
24+
return "GPL"
25+
26+
27+
compile_to_ir("struct_field_access.py", "struct_field_access.ll", loglevel=logging.INFO)
28+
# compile()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include "vmlinux.h"
4+
#include <bpf/bpf_helpers.h>
5+
#include <bpf/bpf_tracing.h>
6+
7+
SEC("tp/syscalls/sys_enter_execve")
8+
int handle_setuid_entry(struct trace_event_raw_sys_enter *ctx) {
9+
bpf_printk("args: %u", (unsigned int)ctx->args[0]);
10+
return 0;
11+
}
12+
13+
char LICENSE[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)