mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
Add struct malloc, add struct instantiation to example
This commit is contained in:
@ -19,6 +19,7 @@ def events() -> PerfEventArray:
|
|||||||
@bpf
|
@bpf
|
||||||
@section("tracepoint/syscalls/sys_enter_clone")
|
@section("tracepoint/syscalls/sys_enter_clone")
|
||||||
def hello(ctx: c_void_p) -> c_int32:
|
def hello(ctx: c_void_p) -> c_int32:
|
||||||
|
dataobj = data_t()
|
||||||
ts = ktime()
|
ts = ktime()
|
||||||
process_id = pid()
|
process_id = pid()
|
||||||
print(f"clone called at {ts} by pid {process_id}")
|
print(f"clone called at {ts} by pid {process_id}")
|
||||||
|
|||||||
@ -7,6 +7,8 @@ from .type_deducer import ctypes_to_ir
|
|||||||
from .binary_ops import handle_binary_op
|
from .binary_ops import handle_binary_op
|
||||||
from .expr_pass import eval_expr, handle_expr
|
from .expr_pass import eval_expr, handle_expr
|
||||||
|
|
||||||
|
local_var_metadata = {}
|
||||||
|
|
||||||
|
|
||||||
def get_probe_string(func_node):
|
def get_probe_string(func_node):
|
||||||
"""Extract the probe string from the decorator of the function node."""
|
"""Extract the probe string from the decorator of the function node."""
|
||||||
@ -298,6 +300,16 @@ def allocate_mem(module, builder, body, func, ret_type, map_sym_tab, local_sym_t
|
|||||||
var.align = ir_type.width // 8
|
var.align = ir_type.width // 8
|
||||||
print(
|
print(
|
||||||
f"Pre-allocated variable {var_name} for deref")
|
f"Pre-allocated variable {var_name} for deref")
|
||||||
|
elif call_type in structs_sym_tab:
|
||||||
|
struct_info = structs_sym_tab[call_type]
|
||||||
|
ir_type = struct_info["type"]
|
||||||
|
var = builder.alloca(ir_type, name=var_name)
|
||||||
|
|
||||||
|
# Null init
|
||||||
|
builder.store(ir.Constant(ir_type, None), var)
|
||||||
|
local_var_metadata[var_name] = call_type
|
||||||
|
print(
|
||||||
|
f"Pre-allocated variable {var_name} for struct {call_type}")
|
||||||
elif isinstance(rval.func, ast.Attribute):
|
elif isinstance(rval.func, ast.Attribute):
|
||||||
ir_type = ir.PointerType(ir.IntType(64))
|
ir_type = ir.PointerType(ir.IntType(64))
|
||||||
var = builder.alloca(ir_type, name=var_name)
|
var = builder.alloca(ir_type, name=var_name)
|
||||||
|
|||||||
Reference in New Issue
Block a user