Skip to content

Commit 9ee821c

Browse files
make pointer allocation feasible but subverting LLC
1 parent 2539405 commit 9ee821c

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

pythonbpf/allocation_pass.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ def _allocate_for_call(
121121
elif VmlinuxHandlerRegistry.is_vmlinux_struct(call_type):
122122
# When calling struct_name(pointer), we're doing a cast, not construction
123123
# So we allocate as a pointer (i64) not as the actual struct
124-
var = builder.alloca(ir.PointerType(), name=var_name)
124+
var = builder.alloca(ir.IntType(64), name=var_name)
125125
var.align = 8
126126
local_sym_tab[var_name] = LocalSymbol(
127-
var, ir.PointerType(), VmlinuxHandlerRegistry.get_struct_type(call_type)
127+
var, ir.IntType(64), VmlinuxHandlerRegistry.get_struct_type(call_type)
128128
)
129129
logger.info(
130130
f"Pre-allocated {var_name} for vmlinux struct pointer cast to {call_type}"

pythonbpf/expr/expr_pass.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -524,20 +524,22 @@ def _handle_boolean_op(
524524
logger.error(f"Unsupported boolean operator: {type(expr.op).__name__}")
525525
return None
526526

527+
527528
# ============================================================================
528529
# VMLinux casting
529530
# ============================================================================
530531

532+
531533
def _handle_vmlinux_cast(
532-
func,
533-
module,
534-
builder,
535-
expr,
536-
local_sym_tab,
537-
map_sym_tab,
538-
structs_sym_tab=None,
534+
func,
535+
module,
536+
builder,
537+
expr,
538+
local_sym_tab,
539+
map_sym_tab,
540+
structs_sym_tab=None,
539541
):
540-
# handle expressions such as struct_request(ctx.di) where struct_request is a vmlinux
542+
# handle expressions such as struct_request(ctx.di) where struct_request is a vmlinux
541543
# struct and ctx.di is a pointer to a struct but is actually represented as a c_uint64
542544
# which needs to be cast to a pointer. This is also a field of another vmlinux struct
543545
"""Handle vmlinux struct cast expressions like struct_request(ctx.di)."""
@@ -572,7 +574,7 @@ def _handle_vmlinux_cast(
572574
# Cast the integer/value to a pointer to the struct
573575
# If arg_val is an integer type, we need to inttoptr it
574576
ptr_type = ir.PointerType()
575-
#TODO: add a integer check here later
577+
# TODO: add a integer check here later
576578
if ctypes_to_ir(arg_type.type.__name__):
577579
# Cast integer to pointer
578580
casted_ptr = builder.inttoptr(arg_val, ptr_type)
@@ -603,8 +605,10 @@ def eval_expr(
603605
elif isinstance(expr, ast.Constant):
604606
return _handle_constant_expr(module, builder, expr)
605607
elif isinstance(expr, ast.Call):
606-
if isinstance(expr.func, ast.Name) and VmlinuxHandlerRegistry.is_vmlinux_struct(expr.func.id):
607-
return _handle_vmlinux_cast(
608+
if isinstance(expr.func, ast.Name) and VmlinuxHandlerRegistry.is_vmlinux_struct(
609+
expr.func.id
610+
):
611+
return _handle_vmlinux_cast(
608612
func,
609613
module,
610614
builder,

0 commit comments

Comments
 (0)