mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
revert struct reference pointer sizes to i8 to ensure that compiler does not optimize
This commit is contained in:
@ -39,7 +39,7 @@ def finalize_module(original_str):
|
|||||||
|
|
||||||
def bpf_passthrough_gen(module):
|
def bpf_passthrough_gen(module):
|
||||||
i32_ty = ir.IntType(32)
|
i32_ty = ir.IntType(32)
|
||||||
ptr_ty = ir.PointerType(ir.IntType(64))
|
ptr_ty = ir.PointerType(ir.IntType(8))
|
||||||
fnty = ir.FunctionType(ptr_ty, [i32_ty, ptr_ty])
|
fnty = ir.FunctionType(ptr_ty, [i32_ty, ptr_ty])
|
||||||
|
|
||||||
# Declare the intrinsic
|
# Declare the intrinsic
|
||||||
|
|||||||
@ -97,7 +97,7 @@ class VmlinuxHandler:
|
|||||||
globvar_ir, field_data = self.get_field_type(
|
globvar_ir, field_data = self.get_field_type(
|
||||||
python_type.__name__, field_name
|
python_type.__name__, field_name
|
||||||
)
|
)
|
||||||
builder.function.args[0].type = ir.PointerType(ir.IntType(64))
|
builder.function.args[0].type = ir.PointerType(ir.IntType(8))
|
||||||
print(builder.function.args[0])
|
print(builder.function.args[0])
|
||||||
field_ptr = self.load_ctx_field(
|
field_ptr = self.load_ctx_field(
|
||||||
builder, builder.function.args[0], globvar_ir
|
builder, builder.function.args[0], globvar_ir
|
||||||
@ -125,19 +125,18 @@ class VmlinuxHandler:
|
|||||||
# Load the offset value
|
# Load the offset value
|
||||||
offset = builder.load(offset_global)
|
offset = builder.load(offset_global)
|
||||||
|
|
||||||
# # Ensure ctx_arg is treated as i8* (byte pointer)
|
# Ensure ctx_arg is treated as i8* (byte pointer)
|
||||||
# # i8_type = ir.IntType(8)
|
i8_ptr_type = ir.PointerType()
|
||||||
# i8_ptr_type = ir.PointerType()
|
|
||||||
|
|
||||||
# Cast ctx_arg to i8* if it isn't already
|
# Cast ctx_arg to i8* if it isn't already
|
||||||
# if str(ctx_arg.type) != str(i8_ptr_type):
|
if str(ctx_arg.type) != str(i8_ptr_type):
|
||||||
# ctx_i8_ptr = builder.bitcast(ctx_arg, i8_ptr_type)
|
ctx_i8_ptr = builder.bitcast(ctx_arg, i8_ptr_type)
|
||||||
# else:
|
else:
|
||||||
# ctx_i8_ptr = ctx_arg
|
ctx_i8_ptr = ctx_arg
|
||||||
|
|
||||||
# GEP with explicit type - this is the key fix
|
# GEP with explicit type - this is the key fix
|
||||||
field_ptr = builder.gep(
|
field_ptr = builder.gep(
|
||||||
ctx_arg,
|
ctx_i8_ptr,
|
||||||
[offset],
|
[offset],
|
||||||
inbounds=False,
|
inbounds=False,
|
||||||
)
|
)
|
||||||
@ -151,8 +150,8 @@ class VmlinuxHandler:
|
|||||||
raise KeyError
|
raise KeyError
|
||||||
except (KeyError, AttributeError):
|
except (KeyError, AttributeError):
|
||||||
passthrough_type = ir.FunctionType(
|
passthrough_type = ir.FunctionType(
|
||||||
ir.PointerType(),
|
i8_ptr_type,
|
||||||
[ir.IntType(32), ir.PointerType()],
|
[ir.IntType(32), i8_ptr_type],
|
||||||
)
|
)
|
||||||
passthrough_fn = ir.Function(
|
passthrough_fn = ir.Function(
|
||||||
module,
|
module,
|
||||||
|
|||||||
@ -13,10 +13,10 @@ from ctypes import c_int64, c_int32, c_void_p # noqa: F401
|
|||||||
|
|
||||||
@bpf
|
@bpf
|
||||||
@section("tracepoint/syscalls/sys_enter_execve")
|
@section("tracepoint/syscalls/sys_enter_execve")
|
||||||
def hello_world(ctx: struct_trace_event_raw_sys_enter) -> c_int32:
|
def hello_world(ctx: struct_trace_event_raw_sys_enter) -> c_int64:
|
||||||
b = ctx.id
|
b = ctx.id
|
||||||
print(f"This is context field {b}")
|
print(f"This is context field {b}")
|
||||||
return c_int32(0)
|
return c_int64(0)
|
||||||
|
|
||||||
|
|
||||||
@bpf
|
@bpf
|
||||||
|
|||||||
Reference in New Issue
Block a user