mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 01:48:35 +00:00
On this kernel `struct pt_regs` wraps `cs` and `ss` in anonymous unions. ctypes lifts those names onto the parent class, exactly as C does, but the parser only walked the top-level `_fields_`, so `cs` and `ss` were unknown to the compiler and `ctx.cs` blew up. Register the members of an anonymous member as fields of the parent, one level deep, taking the ABSOLUTE offset ctypes reports on the parent (no arithmetic) and recording the access path (anonymous member index, member index). The anonymous member itself stays registered as before. Deliberately conservative: only scalar ctypes members are flattened. Nested vmlinux structs (`fred_cs`, `fred_ss`) and bitfields are skipped with a warning rather than half-registered, and a flattened member never overwrites an existing top-level field of the same name. Overlapping members are kept as distinct fields, since `cs` and `csx` both legitimately live at offset 136. Flattened fields are not yet emitted: IR generation and DWARF generation skip them, and critically they do not consume a top-level field index, so existing CO-RE names are untouched. Every vmlinux/xdp test program still compiles to a byte-identical .ll. Entirely inert for any struct without `_anonymous_`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>