Skip to content

Commit f18a439

Browse files
format chore
1 parent 4e01df7 commit f18a439

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

pythonbpf/allocation_pass.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import ast
2-
import ctypes
32
import logging
43

54
from llvmlite import ir
@@ -246,12 +245,16 @@ def _allocate_for_attribute(builder, var_name, rval, local_sym_tab, structs_sym_
246245
# Handle vmlinux struct field access
247246
vmlinux_struct_name = struct_type.__name__
248247
if not VmlinuxHandlerRegistry.has_field(vmlinux_struct_name, field_name):
249-
logger.error(f"Field '{field_name}' not found in vmlinux struct '{vmlinux_struct_name}'")
248+
logger.error(
249+
f"Field '{field_name}' not found in vmlinux struct '{vmlinux_struct_name}'"
250+
)
250251
return
251252

252-
field_type: tuple[ir.GlobalVariable, Field] = VmlinuxHandlerRegistry.get_field_type(vmlinux_struct_name, field_name)
253+
field_type: tuple[ir.GlobalVariable, Field] = (
254+
VmlinuxHandlerRegistry.get_field_type(vmlinux_struct_name, field_name)
255+
)
253256
field_ir, field = field_type
254-
#TODO: For now, we only support integer type allocations.
257+
# TODO: For now, we only support integer type allocations.
255258

256259
# loaded_value = builder.load(field_ir, align=8)
257260
# #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_
270273
var = _allocate_with_type(builder, var_name, actual_ir_type)
271274
local_sym_tab[var_name] = LocalSymbol(var, actual_ir_type, field)
272275

273-
logger.info(f"Pre-allocated {var_name} from vmlinux struct {vmlinux_struct_name}.{field_name}")
276+
logger.info(
277+
f"Pre-allocated {var_name} from vmlinux struct {vmlinux_struct_name}.{field_name}"
278+
)
274279
return
275280
else:
276281
logger.error(f"Struct type '{struct_type}' not found")

pythonbpf/expr/expr_pass.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,13 @@ def _handle_attribute_expr(
7272
if var_name in local_sym_tab:
7373
var_ptr, var_type, var_metadata = local_sym_tab[var_name]
7474
logger.info(f"Loading attribute {attr_name} from variable {var_name}")
75-
logger.info(f"Variable type: {var_type}, Variable ptr: {var_ptr}, Variable Metadata: {var_metadata}")
76-
if hasattr(var_metadata, "__module__") and var_metadata.__module__ == "vmlinux":
75+
logger.info(
76+
f"Variable type: {var_type}, Variable ptr: {var_ptr}, Variable Metadata: {var_metadata}"
77+
)
78+
if (
79+
hasattr(var_metadata, "__module__")
80+
and var_metadata.__module__ == "vmlinux"
81+
):
7782
# Try vmlinux handler when var_metadata is not a string, but has a module attribute.
7883
# This has been done to keep everything separate in vmlinux struct handling.
7984
vmlinux_result = VmlinuxHandlerRegistry.handle_attribute(

pythonbpf/functions/functions_pass.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
from pythonbpf.allocation_pass import (
2121
handle_assign_allocation,
2222
allocate_temp_pool,
23-
create_targets_and_rvals, LocalSymbol,
23+
create_targets_and_rvals,
24+
LocalSymbol,
2425
)
2526

2627
from .return_utils import handle_none_return, handle_xdp_return, is_xdp_name
@@ -347,12 +348,16 @@ def process_func_body(
347348
resolved_type = VmlinuxHandlerRegistry.get_struct_type(
348349
context_type_name
349350
)
350-
context_type = LocalSymbol(None, ir.PointerType(resolved_type), resolved_type)
351+
context_type = LocalSymbol(
352+
None, ir.PointerType(resolved_type), resolved_type
353+
)
351354
else:
352355
try:
353356
resolved_type = ctypes_to_ir(context_type_name)
354357
logger.error("THIS SHOULD NOT HAPPEN. I THINK. PROBABLY.")
355-
context_type = LocalSymbol(None, ir.PointerType(resolved_type), resolved_type)
358+
context_type = LocalSymbol(
359+
None, ir.PointerType(resolved_type), resolved_type
360+
)
356361
except Exception:
357362
raise TypeError(f"Type '{context_type_name}' not declared")
358363

tests/c-form/struct_field_tests.bpf.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,8 @@ There is no point of
1919
SEC("tp/syscalls/sys_enter_execve")
2020
int handle_setuid_entry(struct trace_event_raw_sys_enter *ctx) {
2121
// Access each argument separately with clear variable assignments
22-
unsigned long arg0 = ctx->args[0];
23-
bpf_printk("args[0]: %u", arg0);
24-
25-
unsigned long arg1 = ctx->args[1];
26-
bpf_printk("args[1]: %u", arg1);
27-
28-
// Remove the duplicate access to args[1]
29-
30-
unsigned long arg2 = ctx->args[2];
31-
bpf_printk("args[3]: %u", arg2);
32-
bpf_printk("args[4]: %u", ctx->args[2]);
22+
long int arg0 = ctx->id;
23+
bpf_printk("args[0]: %d", arg0);
3324

3425
return 0;
3526
}

tests/passing_tests/assign/comprehensive.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,6 @@ def hello_world(ctx: c_void_p) -> c_int64:
7070
def LICENSE() -> str:
7171
return "GPL"
7272

73+
7374
compile_to_ir("comprehensive.py", "comprehensive.ll")
74-
# compile()
75+
compile()

0 commit comments

Comments
 (0)