ARRAY_ELEM_PTR(9)
π ARRAY_ELEM_PTR π
okay so bestie, welcome to the Kernel API Manual, section 9 β this one's called ARRAY_ELEM_PTR and honestly? it's giving "quietly iconic helper macro" energy. it's the glow-up version of pointer-verifying that actually knows how big your array really is. let's get into it π
β¨ NAME β¨
ARRAY_ELEM_PTR β Obtain the verified pointer to an array element π«Ά
like fr, it hands you back a pointer that's been verified, no cap.
π¦ SYNOPSIS π¦
ARRAY_ELEM_PTR (arr , i , n );
that's the whole vibe. three args, one macro, zero drama β¨
πΈ ARGUMENTS πΈ
arrβ the array you're indexing into. your main character array, if you will πiβ the array index. which element are we sliding into πnβ the number of elements in the array. explicit. on purpose. we'll get to why π
π DESCRIPTION π
so here's the tea β β it's Similar to MEMBER_VPTR but it's intended for use with arrays where the element count needs to be explicit.
why does that matter, you ask? π₯Ί because it can be used in cases where a global array is defined with an initial size but is intended to be be resized before loading the BPF program. and here's the part where it gets messy, bestie β Without this version of the macro, MEMBER_VPTR will use the compile time size of the array to compute the max, which will result in rejection by the verifier πππ
literally the verifier said "no β€οΈ" because the compile-time size wasn't the truth. so we pass n in ourselves and everyone stays unbothered. slay π§
π₯ SEE ALSO π₯
hiii go read these next, they're all besties:
- Kernel file
./tools/sched_ext/include/scx/common.bpf.hβ RESIZABLE_ARRAY(9)MEMBER_VPTR(9)__sink(9)time_delta(9)time_after(9)time_before(9)time_after_eq(9)time_before_eq(9)time_in_range(9)time_in_range_open(9)
π mwah, that's the whole page! this iconic lil manual page lives at ./tools/sched_ext/include/scx and it's dated October 2026 β so yes, it's from the future, and it ate π
β¨ π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms