From 79f0949abcc3721e0ed8a664de17bf6b5dacc334 Mon Sep 17 00:00:00 2001 From: Pragyansh Chaturvedi Date: Sun, 21 Sep 2025 16:19:12 +0530 Subject: [PATCH] Fix calling conventions changed by structs --- pythonbpf/bpf_helper_handler.py | 12 ++++++------ pythonbpf/functions_pass.py | 9 +++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pythonbpf/bpf_helper_handler.py b/pythonbpf/bpf_helper_handler.py index 987f97f..95a8639 100644 --- a/pythonbpf/bpf_helper_handler.py +++ b/pythonbpf/bpf_helper_handler.py @@ -3,7 +3,7 @@ from llvmlite import ir from .expr_pass import eval_expr -def bpf_ktime_get_ns_emitter(call, map_ptr, module, builder, func, local_sym_tab=None): +def bpf_ktime_get_ns_emitter(call, map_ptr, module, builder, func, local_sym_tab=None, local_var_metadata=None): """ Emit LLVM IR for bpf_ktime_get_ns helper function call. """ @@ -16,7 +16,7 @@ def bpf_ktime_get_ns_emitter(call, map_ptr, module, builder, func, local_sym_tab return result -def bpf_map_lookup_elem_emitter(call, map_ptr, module, builder, func, local_sym_tab=None, struct_sym_tab=None): +def bpf_map_lookup_elem_emitter(call, map_ptr, module, builder, func, local_sym_tab=None, struct_sym_tab=None, local_var_metadata=None): """ Emit LLVM IR for bpf_map_lookup_elem helper function call. """ @@ -63,7 +63,7 @@ def bpf_map_lookup_elem_emitter(call, map_ptr, module, builder, func, local_sym_ return result -def bpf_printk_emitter(call, map_ptr, module, builder, func, local_sym_tab=None): +def bpf_printk_emitter(call, map_ptr, module, builder, func, local_sym_tab=None, local_var_metadata=None): if not hasattr(func, "_fmt_counter"): func._fmt_counter = 0 @@ -172,7 +172,7 @@ def bpf_printk_emitter(call, map_ptr, module, builder, func, local_sym_tab=None) ir.IntType(32), len(fmt_str))], tail=True) -def bpf_map_update_elem_emitter(call, map_ptr, module, builder, func, local_sym_tab=None, struct_sym_tab=None): +def bpf_map_update_elem_emitter(call, map_ptr, module, builder, func, local_sym_tab=None, struct_sym_tab=None, local_var_metadata=None): """ Emit LLVM IR for bpf_map_update_elem helper function call. Expected call signature: map.update(key, value, flags=0) @@ -268,7 +268,7 @@ def bpf_map_update_elem_emitter(call, map_ptr, module, builder, func, local_sym_ return result -def bpf_map_delete_elem_emitter(call, map_ptr, module, builder, func, local_sym_tab=None, struct_sym_tab=None): +def bpf_map_delete_elem_emitter(call, map_ptr, module, builder, func, local_sym_tab=None, struct_sym_tab=None, local_var_metadata=None): """ Emit LLVM IR for bpf_map_delete_elem helper function call. Expected call signature: map.delete(key) @@ -323,7 +323,7 @@ def bpf_map_delete_elem_emitter(call, map_ptr, module, builder, func, local_sym_ return result -def bpf_get_current_pid_tgid_emitter(call, map_ptr, module, builder, func, local_sym_tab=None): +def bpf_get_current_pid_tgid_emitter(call, map_ptr, module, builder, func, local_sym_tab=None, local_var_metadata=None): """ Emit LLVM IR for bpf_get_current_pid_tgid helper function call. """ diff --git a/pythonbpf/functions_pass.py b/pythonbpf/functions_pass.py index aaae85e..7a261e4 100644 --- a/pythonbpf/functions_pass.py +++ b/pythonbpf/functions_pass.py @@ -222,7 +222,7 @@ def handle_cond(func, module, builder, cond, local_sym_tab, map_sym_tab): return None -def handle_if(func, module, builder, stmt, map_sym_tab, local_sym_tab): +def handle_if(func, module, builder, stmt, map_sym_tab, local_sym_tab, structs_sym_tab=None): """Handle if statements in the function body.""" print("Handling if statement") start = builder.block.parent @@ -243,7 +243,7 @@ def handle_if(func, module, builder, stmt, map_sym_tab, local_sym_tab): builder.position_at_end(then_block) for s in stmt.body: process_stmt(func, module, builder, s, - local_sym_tab, map_sym_tab, False) + local_sym_tab, map_sym_tab, structs_sym_tab, False) if not builder.block.is_terminated: builder.branch(merge_block) @@ -251,7 +251,7 @@ def handle_if(func, module, builder, stmt, map_sym_tab, local_sym_tab): builder.position_at_end(else_block) for s in stmt.orelse: process_stmt(func, module, builder, s, - local_sym_tab, map_sym_tab, False) + local_sym_tab, map_sym_tab, structs_sym_tab, False) if not builder.block.is_terminated: builder.branch(merge_block) @@ -269,7 +269,8 @@ def process_stmt(func, module, builder, stmt, local_sym_tab, map_sym_tab, struct elif isinstance(stmt, ast.AugAssign): raise SyntaxError("Augmented assignment not supported") elif isinstance(stmt, ast.If): - handle_if(func, module, builder, stmt, map_sym_tab, local_sym_tab) + handle_if(func, module, builder, stmt, map_sym_tab, + local_sym_tab, structs_sym_tab) elif isinstance(stmt, ast.Return): if stmt.value is None: builder.ret(ir.Constant(ir.IntType(32), 0))