mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 01:48:35 +00:00
Core: Implement ArrayMap as BPF_MAP_TYPE_ARRAY
process_array_map was a stub raising NotImplementedError while ArrayMap was exported from pythonbpf.maps as if usable. The lowering is the hash map's with a different type constant: the same lookup/update/delete helpers, and the kernel fixes the key at a 4-byte index. The lookup allocation path accepts ARRAY alongside HASH, the audit tool lists ARRAY as supported, and the array_map_lookup_update case is a passing test now instead of a strict xfail. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@ -208,7 +208,7 @@ def _allocate_for_map_method(
|
||||
return
|
||||
|
||||
map_params = map_sym_tab[map_name].params
|
||||
if map_params["type"] != BPFMapType.HASH:
|
||||
if map_params["type"] not in (BPFMapType.HASH, BPFMapType.ARRAY):
|
||||
logger.warning(
|
||||
"Map method lookup used on non-hash map, using fallback allocation"
|
||||
)
|
||||
|
||||
@ -145,10 +145,22 @@ def process_hash_map(map_name, rval, compilation_context):
|
||||
|
||||
@MapProcessorRegistry.register("ArrayMap")
|
||||
def process_array_map(map_name, rval, compilation_context):
|
||||
"""Document the planned BPF_ARRAY map support with an explicit failure."""
|
||||
raise NotImplementedError(
|
||||
"ArrayMap is not implemented yet; add BPF_MAP_TYPE_ARRAY metadata support"
|
||||
"""Process a BPF_ARRAY map declaration: the same lowering as a hash map
|
||||
with BPF_MAP_TYPE_ARRAY, through the same lookup/update/delete helpers;
|
||||
the kernel requires a 4-byte key (an index)."""
|
||||
logger.info(f"Processing ArrayMap: {map_name}")
|
||||
map_params = _parse_map_params(rval, expected_args=["key", "value", "max_entries"])
|
||||
map_params["type"] = BPFMapType.ARRAY
|
||||
|
||||
logger.info(f"Map parameters: {map_params}")
|
||||
map_global = create_bpf_map(compilation_context, map_name, map_params)
|
||||
create_map_debug_info(
|
||||
compilation_context,
|
||||
map_global.var,
|
||||
map_name,
|
||||
map_params,
|
||||
)
|
||||
return map_global
|
||||
|
||||
|
||||
@MapProcessorRegistry.register("PerfEventArray")
|
||||
|
||||
@ -74,9 +74,9 @@ cursor, which together constrain the design more than anything here does.
|
||||
`.bss`, `.data` and `.rodata` become internal array maps at load time. Two consequences:
|
||||
|
||||
- A one-element **`ArrayMap`** is the structurally faithful stand-in for a global, not a
|
||||
`HashMap`. `HashMap` is used here only because `ArrayMap` is still a placeholder that
|
||||
raises `NotImplementedError`. Landing `ArrayMap` first would make the eventual migration
|
||||
to real globals close to mechanical.
|
||||
`HashMap`. The `HashMap` stand-ins predate `ArrayMap`, which lowers now
|
||||
(`BPF_MAP_TYPE_ARRAY`, the same helpers as `HashMap`); real `@bpfglobal` scalars have
|
||||
landed since, so the migration is to those.
|
||||
- **Most of the ELF work is already done.** `@bpfglobal` is vestigial — a metadata carrier
|
||||
for `LICENSE` — but the machinery behind it already emits globals that LLVM places into
|
||||
`.bss` and `.data` correctly, and that libbpf already recognises:
|
||||
|
||||
@ -61,7 +61,6 @@
|
||||
|
||||
"failing_tests/loops/for_map_items.py" = {reason = "for/while loops not implemented: no sugar over bpf_for_each_map_elem()-style map iteration exists yet", level = "ir"}
|
||||
|
||||
"kernel_selftest_equivalent/maps/array_map_lookup_update.py" = {reason = "ArrayMap / BPF_MAP_TYPE_ARRAY support is planned but not implemented yet", level = "ir"}
|
||||
|
||||
"kernel_selftest_equivalent/ringbuf/reserve_submit_discard.py" = {reason = "RingBuffer reserve/typed record/discard workflow is planned but not implemented yet", level = "ir"}
|
||||
|
||||
|
||||
@ -52,8 +52,8 @@ SUPPORTED_HELPERS = {
|
||||
"bpf_skb_store_bytes",
|
||||
}
|
||||
|
||||
# BPF_MAP_TYPE_* that pythonbpf/maps lowers (ArrayMap is still a stub).
|
||||
SUPPORTED_MAP_TYPES = {"HASH", "PERF_EVENT_ARRAY", "RINGBUF"}
|
||||
# BPF_MAP_TYPE_* that pythonbpf/maps lowers.
|
||||
SUPPORTED_MAP_TYPES = {"ARRAY", "HASH", "PERF_EVENT_ARRAY", "RINGBUF"}
|
||||
|
||||
# Things that look like helper calls but are libbpf macros, not helpers.
|
||||
NOT_HELPERS = {
|
||||
|
||||
Reference in New Issue
Block a user