|
1 | 1 | from llvmlite import ir |
2 | 2 | import ast |
| 3 | +import ctypes |
3 | 4 | import logging |
4 | 5 |
|
5 | 6 | from pythonbpf.helper import ( |
6 | 7 | HelperHandlerRegistry, |
7 | 8 | ) |
8 | | -from pythonbpf.type_deducer import ctypes_to_ir |
| 9 | +from pythonbpf.type_deducer import ctypes_to_ir, is_ctypes |
9 | 10 | from pythonbpf.expr import ( |
10 | 11 | eval_expr, |
11 | 12 | handle_expr, |
@@ -325,13 +326,28 @@ def process_func_body( |
325 | 326 | f"Unsupported annotation type: {ast.dump(context_arg.annotation)}" |
326 | 327 | ) |
327 | 328 |
|
| 329 | + # NOTE: `var` is None for the context parameter. It is the sentinel |
| 330 | + # that tells consumers the symbol is an incoming function argument |
| 331 | + # (`func.args[0]`) rather than a stack slot they can load from. |
328 | 332 | if VmlinuxHandlerRegistry.is_vmlinux_struct(context_type_name): |
329 | 333 | resolved_type = VmlinuxHandlerRegistry.get_struct_type( |
330 | 334 | context_type_name |
331 | 335 | ) |
332 | 336 | context_type = LocalSymbol(None, None, resolved_type) |
333 | 337 | local_sym_tab[context_name] = context_type |
334 | 338 | logger.info(f"Added argument '{context_name}' to local symbol table") |
| 339 | + elif is_ctypes(context_type_name): |
| 340 | + # Plain ctypes annotation, e.g. `ctx: c_void_p`. Register it so |
| 341 | + # helpers that take the raw context (probe_read, ...) can resolve |
| 342 | + # the name. Metadata is the annotated Python type, mirroring the |
| 343 | + # vmlinux branch above. |
| 344 | + context_type = LocalSymbol( |
| 345 | + None, |
| 346 | + ir.PointerType(), |
| 347 | + getattr(ctypes, context_type_name, None), |
| 348 | + ) |
| 349 | + local_sym_tab[context_name] = context_type |
| 350 | + logger.info(f"Added argument '{context_name}' to local symbol table") |
335 | 351 |
|
336 | 352 | # pre-allocate dynamic variables |
337 | 353 | local_sym_tab = allocate_mem( |
|
0 commit comments