mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
Update bpf examples and remove function pass code
This commit is contained in:
@ -10,7 +10,7 @@ OBJECT := example.bpf.o
|
|||||||
all: $(OUT)
|
all: $(OUT)
|
||||||
|
|
||||||
object: $(SRC)
|
object: $(SRC)
|
||||||
$(BPF_CLANG) $(CFLAGS) $< -o $(OBJECT)
|
$(BPF_CLANG) -O2 -target bpf -c $< -o $(OBJECT)
|
||||||
|
|
||||||
$(OUT): $(SRC) object
|
$(OUT): $(SRC) object
|
||||||
$(BPF_CLANG) $(CFLAGS) -S $< -o $@
|
$(BPF_CLANG) $(CFLAGS) -S $< -o $@
|
||||||
|
|||||||
@ -2,31 +2,16 @@
|
|||||||
#include <bpf/bpf_helpers.h>
|
#include <bpf/bpf_helpers.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
int trace_testing(void *ctx)
|
void test_function() {
|
||||||
{
|
bpf_printk("test_function called");
|
||||||
bpf_printk("THISISACONSTANT");
|
|
||||||
bpf_printk("THISISCONSTANT2");
|
|
||||||
uint64_t a = 69;
|
|
||||||
bpf_printk("%d", a);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("tracepoint/syscalls/sys_enter_execve")
|
SEC("tracepoint/syscalls/sys_enter_execve")
|
||||||
int trace_execve(void *ctx)
|
int trace_execve(void *ctx)
|
||||||
{
|
{
|
||||||
if(ctx){
|
bpf_printk("execve called");
|
||||||
trace_testing(ctx);
|
bpf_printk("execve2 called");
|
||||||
} else {
|
test_function();
|
||||||
bpf_printk("THISISANOTHERCONSTANT");
|
|
||||||
}
|
|
||||||
bpf_trace_printk("execve called\n", 15);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SEC("tracepoint/syscalls/sys_exit_execve")
|
|
||||||
int trace_randomname_exit(void *ctx)
|
|
||||||
{
|
|
||||||
bpf_trace_printk("execve called to exit\n", 15);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,10 @@
|
|||||||
from pythonbpf.decorators import section
|
from pythonbpf.decorators import section
|
||||||
# from pythonbpf.decorators import tracepoint, syscalls
|
|
||||||
from ctypes import c_void_p, c_int32
|
from ctypes import c_void_p, c_int32
|
||||||
|
|
||||||
#This is a test function
|
#This is a test function
|
||||||
def test_function():
|
def test_function():
|
||||||
print("test_function called")
|
print("test_function called")
|
||||||
|
|
||||||
# @tracepoint(syscalls.sys_enter_execve)
|
|
||||||
@section("tracepoint/syscalls/sys_enter_execve")
|
@section("tracepoint/syscalls/sys_enter_execve")
|
||||||
def trace_execve(ctx: c_void_p) -> c_int32:
|
def trace_execve(ctx: c_void_p) -> c_int32:
|
||||||
print("execve called")
|
print("execve called")
|
||||||
@ -14,5 +12,4 @@ def trace_execve(ctx: c_void_p) -> c_int32:
|
|||||||
test_function()
|
test_function()
|
||||||
return c_int32(0)
|
return c_int32(0)
|
||||||
|
|
||||||
|
|
||||||
LICENSE = "GPL"
|
LICENSE = "GPL"
|
||||||
|
|||||||
@ -1,32 +1,5 @@
|
|||||||
from llvmlite import ir
|
from llvmlite import ir
|
||||||
import ast
|
import ast
|
||||||
|
|
||||||
def emit_function(module: ir.Module, license_str: str):
|
|
||||||
license_bytes = license_str.encode("utf8") + b"\x00"
|
|
||||||
elems = [ir.Constant(ir.IntType(8), b) for b in license_bytes]
|
|
||||||
ty = ir.ArrayType(ir.IntType(8), len(elems))
|
|
||||||
|
|
||||||
gvar = ir.GlobalVariable(module, ty, name="LICENSE")
|
|
||||||
|
|
||||||
gvar.initializer = ir.Constant(ty, elems) # type: ignore
|
|
||||||
|
|
||||||
gvar.align = 1 # type: ignore
|
|
||||||
gvar.linkage = "dso_local" # type: ignore
|
|
||||||
gvar.global_constant = False
|
|
||||||
gvar.section = "license" # type: ignore
|
|
||||||
|
|
||||||
return gvar
|
|
||||||
|
|
||||||
def functions_processing(tree, module):
|
def functions_processing(tree, module):
|
||||||
bpf_functions = []
|
pass
|
||||||
helper_functions = []
|
|
||||||
for node in tree.body:
|
|
||||||
section_name = ""
|
|
||||||
if isinstance(node, ast.FunctionDef):
|
|
||||||
if len(node.decorator_list) == 1:
|
|
||||||
bpf_functions.append(node)
|
|
||||||
else:
|
|
||||||
if 'helper_functions' not in locals():
|
|
||||||
helper_functions.append(node)
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user