mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 09:58:34 +00:00
A local bound to a map lookup holds a pointer, and get_or_create_ptr_from_arg handed a helper the address of that local's stack slot instead. So count.update(k, prev) stored the kernel address of the map value, not the value, and after prev = prev + 1 it stored the address of the temporary. The verifier accepts both when loading as root, so nothing failed: the failing_tests/vmlinux/named_arg.py example has been passing all along while storing the wrong thing. The slot is now loaded when it holds a pointer. named_arg.py moves to passing_tests, and both it and a new map_update_from_lookup.py are pinned by IR assertions. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
32 lines
693 B
Python
32 lines
693 B
Python
# A map lookup result passed straight to map.update(): the helper gets the
|
|
# pointer the local holds (the map value), as bpf_map_update_elem(&m, &k, prev, 0)
|
|
# would in C, not the address of the local's slot.
|
|
|
|
from pythonbpf import bpf, map, section, bpfglobal, compile
|
|
from pythonbpf.maps import HashMap
|
|
from ctypes import c_void_p, c_int64
|
|
|
|
|
|
@bpf
|
|
@map
|
|
def count() -> HashMap:
|
|
return HashMap(key=c_int64, value=c_int64, max_entries=2)
|
|
|
|
|
|
@bpf
|
|
@section("tracepoint/syscalls/sys_enter_getpid")
|
|
def copy(ctx: c_void_p) -> c_int64:
|
|
prev = count.lookup(0)
|
|
if prev:
|
|
count.update(1, prev)
|
|
return c_int64(0)
|
|
|
|
|
|
@bpf
|
|
@bpfglobal
|
|
def LICENSE() -> str:
|
|
return "GPL"
|
|
|
|
|
|
compile()
|