mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
format chore
This commit is contained in:
@ -79,7 +79,7 @@ def _get_field_debug_type(
|
|||||||
"""
|
"""
|
||||||
# Handle complex types (arrays, pointers)
|
# Handle complex types (arrays, pointers)
|
||||||
if field.ctype_complex_type is not None:
|
if field.ctype_complex_type is not None:
|
||||||
#TODO: Check if this is a CFUNCTYPE (function pointer), but sadly it just checks callable for now
|
# TODO: Check if this is a CFUNCTYPE (function pointer), but sadly it just checks callable for now
|
||||||
if callable(field.ctype_complex_type):
|
if callable(field.ctype_complex_type):
|
||||||
# Handle function pointer types, create a void pointer as a placeholder
|
# Handle function pointer types, create a void pointer as a placeholder
|
||||||
return generator.create_pointer_type(None), 64
|
return generator.create_pointer_type(None), 64
|
||||||
|
|||||||
@ -14,6 +14,7 @@ class IRGenerator:
|
|||||||
# This field keeps track of the non_struct names to avoid duplicate name errors.
|
# This field keeps track of the non_struct names to avoid duplicate name errors.
|
||||||
type_number = 0
|
type_number = 0
|
||||||
unprocessed_store = []
|
unprocessed_store = []
|
||||||
|
|
||||||
# get the assignments dict and add this stuff to it.
|
# get the assignments dict and add this stuff to it.
|
||||||
def __init__(self, llvm_module, handler: DependencyHandler, assignments):
|
def __init__(self, llvm_module, handler: DependencyHandler, assignments):
|
||||||
self.llvm_module = llvm_module
|
self.llvm_module = llvm_module
|
||||||
@ -187,13 +188,17 @@ class IRGenerator:
|
|||||||
while hasattr(base_containing_type, "_type_"):
|
while hasattr(base_containing_type, "_type_"):
|
||||||
next_type = base_containing_type._type_
|
next_type = base_containing_type._type_
|
||||||
# Stop if _type_ is a string (like 'c' for c_char)
|
# Stop if _type_ is a string (like 'c' for c_char)
|
||||||
#TODO: stacked pointers not handl;ing ctypes check here as well
|
# TODO: stacked pointers not handl;ing ctypes check here as well
|
||||||
if isinstance(next_type, str):
|
if isinstance(next_type, str):
|
||||||
break
|
break
|
||||||
base_containing_type = next_type
|
base_containing_type = next_type
|
||||||
|
|
||||||
# Get the base struct name
|
# Get the base struct name
|
||||||
base_struct_name = base_containing_type.__name__ if hasattr(base_containing_type, "__name__") else str(base_containing_type)
|
base_struct_name = (
|
||||||
|
base_containing_type.__name__
|
||||||
|
if hasattr(base_containing_type, "__name__")
|
||||||
|
else str(base_containing_type)
|
||||||
|
)
|
||||||
|
|
||||||
# Look up the size using the base struct name
|
# Look up the size using the base struct name
|
||||||
containing_type_size = self.handler[base_struct_name].current_offset
|
containing_type_size = self.handler[base_struct_name].current_offset
|
||||||
@ -212,14 +217,23 @@ class IRGenerator:
|
|||||||
else:
|
else:
|
||||||
for i in range(0, array_size):
|
for i in range(0, array_size):
|
||||||
field_co_re_name, returned = self._struct_name_generator(
|
field_co_re_name, returned = self._struct_name_generator(
|
||||||
struct, field, field_index, True, i, containing_type_size
|
struct,
|
||||||
|
field,
|
||||||
|
field_index,
|
||||||
|
True,
|
||||||
|
i,
|
||||||
|
containing_type_size,
|
||||||
)
|
)
|
||||||
globvar = ir.GlobalVariable(
|
globvar = ir.GlobalVariable(
|
||||||
self.llvm_module, ir.IntType(64), name=field_co_re_name
|
self.llvm_module, ir.IntType(64), name=field_co_re_name
|
||||||
)
|
)
|
||||||
globvar.linkage = "external"
|
globvar.linkage = "external"
|
||||||
globvar.set_metadata("llvm.preserve.access.index", debug_info)
|
globvar.set_metadata(
|
||||||
self.generated_field_names[struct.name][field_name] = globvar
|
"llvm.preserve.access.index", debug_info
|
||||||
|
)
|
||||||
|
self.generated_field_names[struct.name][field_name] = (
|
||||||
|
globvar
|
||||||
|
)
|
||||||
field_index += 1
|
field_index += 1
|
||||||
else:
|
else:
|
||||||
field_co_re_name, returned = self._struct_name_generator(
|
field_co_re_name, returned = self._struct_name_generator(
|
||||||
@ -272,7 +286,7 @@ class IRGenerator:
|
|||||||
return unprocessed_type + "_" + str(self.type_number), False
|
return unprocessed_type + "_" + str(self.type_number), False
|
||||||
else:
|
else:
|
||||||
self.unprocessed_store.append(unprocessed_type)
|
self.unprocessed_store.append(unprocessed_type)
|
||||||
return unprocessed_type, False
|
return unprocessed_type, False
|
||||||
# raise TypeError(
|
# raise TypeError(
|
||||||
# "Name generation cannot occur due to type name not starting with struct"
|
# "Name generation cannot occur due to type name not starting with struct"
|
||||||
# )
|
# )
|
||||||
|
|||||||
@ -7,8 +7,8 @@ from ctypes import c_int64, c_void_p
|
|||||||
@bpf
|
@bpf
|
||||||
@section("kprobe/blk_mq_start_request")
|
@section("kprobe/blk_mq_start_request")
|
||||||
def example(ctx: c_void_p) -> c_int64:
|
def example(ctx: c_void_p) -> c_int64:
|
||||||
d = XDP_PASS # This gives an error, but
|
d = XDP_PASS # This gives an error, but
|
||||||
e = XDP_PASS + 0 # this does not
|
e = XDP_PASS + 0 # this does not
|
||||||
print(f"test1 {e} test2 {d}")
|
print(f"test1 {e} test2 {d}")
|
||||||
return c_int64(0)
|
return c_int64(0)
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
from vmlinux import struct_request, struct_pt_regs
|
from vmlinux import struct_request, struct_pt_regs
|
||||||
from pythonbpf import bpf, section, bpfglobal, compile_to_ir
|
from pythonbpf import bpf, section, bpfglobal, compile_to_ir
|
||||||
import logging
|
import logging
|
||||||
from ctypes import c_int64, c_void_p
|
from ctypes import c_int64
|
||||||
|
|
||||||
|
|
||||||
@bpf
|
@bpf
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
from vmlinux import struct_request, struct_pt_regs, XDP_PASS
|
from vmlinux import struct_pt_regs
|
||||||
from pythonbpf import bpf, section, bpfglobal, compile_to_ir
|
from pythonbpf import bpf, section, bpfglobal, compile_to_ir
|
||||||
import logging
|
import logging
|
||||||
from ctypes import c_int64
|
from ctypes import c_int64
|
||||||
|
|||||||
Reference in New Issue
Block a user