From 6dcedcb410ad2a825549c9b55bb9b9c6df5631ae Mon Sep 17 00:00:00 2001 From: Vadim Skipin Date: Wed, 6 May 2026 16:24:34 +0000 Subject: [PATCH] Add a comment about handling bpf_map_lookup_elem error --- src/profiler/profiler.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/profiler/profiler.cpp b/src/profiler/profiler.cpp index 42b5fe2..dc69c21 100644 --- a/src/profiler/profiler.cpp +++ b/src/profiler/profiler.cpp @@ -204,13 +204,21 @@ void Profiler::collect(Symbolizer * symbolizer) uint64_t userAddrs[MAX_FRAMES] = {}; uint64_t kernelAddrs[MAX_FRAMES] = {}; + // UINT32_MAX is the sentinel the BPF program stores when bpf_get_stackid + // fails (normalizes all negative errno values to -1, which becomes + // 0xFFFFFFFF when cast to u32). Valid stack IDs are always non-negative + // s32 values and never alias UINT32_MAX. + // + // On lookup failure (stack ID evicted between map iteration and lookup) + // the arrays remain zero-initialized, countFrames returns 0, and the + // sample is skipped by the nUser == 0 && nKernel == 0 check below. if (userSid != UINT32_MAX) { - bpf_map_lookup_elem(stackFd, &userSid, userAddrs); + (void)bpf_map_lookup_elem(stackFd, &userSid, userAddrs); } if (kernelSid != UINT32_MAX) { - bpf_map_lookup_elem(stackFd, &kernelSid, kernelAddrs); + (void)bpf_map_lookup_elem(stackFd, &kernelSid, kernelAddrs); } int nUser = countFrames(userAddrs);