format chore

This commit is contained in:
2025-10-24 02:40:07 +05:30
parent 4e01df735f
commit f18a4399ea
5 changed files with 29 additions and 22 deletions

View File

@ -1,5 +1,4 @@
import ast
import ctypes
import logging
from llvmlite import ir
@ -246,12 +245,16 @@ def _allocate_for_attribute(builder, var_name, rval, local_sym_tab, structs_sym_
# Handle vmlinux struct field access
vmlinux_struct_name = struct_type.__name__
if not VmlinuxHandlerRegistry.has_field(vmlinux_struct_name, field_name):
logger.error(f"Field '{field_name}' not found in vmlinux struct '{vmlinux_struct_name}'")
logger.error(
f"Field '{field_name}' not found in vmlinux struct '{vmlinux_struct_name}'"
)
return
field_type: tuple[ir.GlobalVariable, Field] = VmlinuxHandlerRegistry.get_field_type(vmlinux_struct_name, field_name)
field_type: tuple[ir.GlobalVariable, Field] = (
VmlinuxHandlerRegistry.get_field_type(vmlinux_struct_name, field_name)
)
field_ir, field = field_type
#TODO: For now, we only support integer type allocations.
# TODO: For now, we only support integer type allocations.
# loaded_value = builder.load(field_ir, align=8)
# #TODO: fatal flaw that this always assumes first argument of function to be the context of what this gets.
@ -270,7 +273,9 @@ def _allocate_for_attribute(builder, var_name, rval, local_sym_tab, structs_sym_
var = _allocate_with_type(builder, var_name, actual_ir_type)
local_sym_tab[var_name] = LocalSymbol(var, actual_ir_type, field)
logger.info(f"Pre-allocated {var_name} from vmlinux struct {vmlinux_struct_name}.{field_name}")
logger.info(
f"Pre-allocated {var_name} from vmlinux struct {vmlinux_struct_name}.{field_name}"
)
return
else:
logger.error(f"Struct type '{struct_type}' not found")

View File

@ -72,8 +72,13 @@ def _handle_attribute_expr(
if var_name in local_sym_tab:
var_ptr, var_type, var_metadata = local_sym_tab[var_name]
logger.info(f"Loading attribute {attr_name} from variable {var_name}")
logger.info(f"Variable type: {var_type}, Variable ptr: {var_ptr}, Variable Metadata: {var_metadata}")
if hasattr(var_metadata, "__module__") and var_metadata.__module__ == "vmlinux":
logger.info(
f"Variable type: {var_type}, Variable ptr: {var_ptr}, Variable Metadata: {var_metadata}"
)
if (
hasattr(var_metadata, "__module__")
and var_metadata.__module__ == "vmlinux"
):
# Try vmlinux handler when var_metadata is not a string, but has a module attribute.
# This has been done to keep everything separate in vmlinux struct handling.
vmlinux_result = VmlinuxHandlerRegistry.handle_attribute(

View File

@ -20,7 +20,8 @@ from pythonbpf.assign_pass import (
from pythonbpf.allocation_pass import (
handle_assign_allocation,
allocate_temp_pool,
create_targets_and_rvals, LocalSymbol,
create_targets_and_rvals,
LocalSymbol,
)
from .return_utils import handle_none_return, handle_xdp_return, is_xdp_name
@ -347,12 +348,16 @@ def process_func_body(
resolved_type = VmlinuxHandlerRegistry.get_struct_type(
context_type_name
)
context_type = LocalSymbol(None, ir.PointerType(resolved_type), resolved_type)
context_type = LocalSymbol(
None, ir.PointerType(resolved_type), resolved_type
)
else:
try:
resolved_type = ctypes_to_ir(context_type_name)
logger.error("THIS SHOULD NOT HAPPEN. I THINK. PROBABLY.")
context_type = LocalSymbol(None, ir.PointerType(resolved_type), resolved_type)
context_type = LocalSymbol(
None, ir.PointerType(resolved_type), resolved_type
)
except Exception:
raise TypeError(f"Type '{context_type_name}' not declared")

View File

@ -19,17 +19,8 @@ There is no point of
SEC("tp/syscalls/sys_enter_execve")
int handle_setuid_entry(struct trace_event_raw_sys_enter *ctx) {
// Access each argument separately with clear variable assignments
unsigned long arg0 = ctx->args[0];
bpf_printk("args[0]: %u", arg0);
unsigned long arg1 = ctx->args[1];
bpf_printk("args[1]: %u", arg1);
// Remove the duplicate access to args[1]
unsigned long arg2 = ctx->args[2];
bpf_printk("args[3]: %u", arg2);
bpf_printk("args[4]: %u", ctx->args[2]);
long int arg0 = ctx->id;
bpf_printk("args[0]: %d", arg0);
return 0;
}

View File

@ -70,5 +70,6 @@ def hello_world(ctx: c_void_p) -> c_int64:
def LICENSE() -> str:
return "GPL"
compile_to_ir("comprehensive.py", "comprehensive.ll")
# compile()
compile()