mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
add i32 support and make it extensible
This commit is contained in:
15
tests/c-form/i32test.bpf.c
Normal file
15
tests/c-form/i32test.bpf.c
Normal file
@ -0,0 +1,15 @@
|
||||
#include <linux/bpf.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
|
||||
SEC("xdp")
|
||||
int print_xdp_data(struct xdp_md *ctx)
|
||||
{
|
||||
// 'data' is a pointer to the start of packet data
|
||||
void *data = (void *)(long)ctx->data;
|
||||
|
||||
bpf_printk("ctx->data = %p\n", data);
|
||||
|
||||
return XDP_PASS;
|
||||
}
|
||||
|
||||
char LICENSE[] SEC("license") = "GPL";
|
||||
30
tests/failing_tests/vmlinux/args_test.py
Normal file
30
tests/failing_tests/vmlinux/args_test.py
Normal file
@ -0,0 +1,30 @@
|
||||
import logging
|
||||
|
||||
from pythonbpf import bpf, section, bpfglobal, compile_to_ir
|
||||
from pythonbpf import compile # noqa: F401
|
||||
from vmlinux import TASK_COMM_LEN # noqa: F401
|
||||
from vmlinux import struct_trace_event_raw_sys_enter # noqa: F401
|
||||
from ctypes import c_int64, c_int32, c_void_p # noqa: F401
|
||||
|
||||
|
||||
# from vmlinux import struct_uinput_device
|
||||
# from vmlinux import struct_blk_integrity_iter
|
||||
|
||||
|
||||
@bpf
|
||||
@section("tracepoint/syscalls/sys_enter_execve")
|
||||
def hello_world(ctx: struct_trace_event_raw_sys_enter) -> c_int64:
|
||||
b = ctx.args
|
||||
c = b[0]
|
||||
print(f"This is context args field {c}")
|
||||
return c_int64(0)
|
||||
|
||||
|
||||
@bpf
|
||||
@bpfglobal
|
||||
def LICENSE() -> str:
|
||||
return "GPL"
|
||||
|
||||
|
||||
compile_to_ir("args_test.py", "args_test.ll", loglevel=logging.INFO)
|
||||
compile()
|
||||
23
tests/failing_tests/vmlinux/i32_test.py
Normal file
23
tests/failing_tests/vmlinux/i32_test.py
Normal file
@ -0,0 +1,23 @@
|
||||
from ctypes import c_int64, c_int32
|
||||
from pythonbpf import bpf, section, bpfglobal, compile_to_ir, compile
|
||||
from vmlinux import struct_xdp_md
|
||||
from vmlinux import XDP_PASS
|
||||
|
||||
|
||||
@bpf
|
||||
@section("xdp")
|
||||
def print_xdp_data(ctx: struct_xdp_md) -> c_int64:
|
||||
data = ctx.data # 32-bit field: packet start pointer
|
||||
something = c_int32(2 + data)
|
||||
print(f"ctx->data = {something}")
|
||||
return c_int64(XDP_PASS)
|
||||
|
||||
|
||||
@bpf
|
||||
@bpfglobal
|
||||
def LICENSE() -> str:
|
||||
return "GPL"
|
||||
|
||||
|
||||
compile_to_ir("i32_test.py", "i32_test.ll")
|
||||
compile()
|
||||
@ -44,4 +44,4 @@ def LICENSE() -> str:
|
||||
|
||||
|
||||
compile_to_ir("simple_struct_test.py", "simple_struct_test.ll", loglevel=logging.DEBUG)
|
||||
# compile()
|
||||
compile()
|
||||
|
||||
Reference in New Issue
Block a user