MEMBER_VPTR(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… MEMBER_VPTR(9) β€” the Kernel API Manual, bestie edition πŸŽ€

okay so real talk, this one lives in the Kernel API Manual, section 9, and it's called MEMBER_VPTR. It's the glow-up macro that gets you a verified pointer to a struct or array member. no cap. ✨


🌸 NAME 🌸

MEMBER_VPTR β€” obtain the verified pointer to a struct or array member 🫢


✨ SYNOPSIS ✨

MEMBER_VPTR (base , member );

that's the whole vibe. two things go in, one pointer comes out πŸ’…


πŸŽ€ ARGUMENTS πŸŽ€

  • base β€” the struct or array you're indexing. this is the thing you're poking at 🫢
  • member β€” the dereferenced member, like .field, [idx0][idx1], .field[idx0] ... you know the drill. give it the dereferenced form, not a pointer form 😭

πŸ¦‹ DESCRIPTION πŸ¦‹

ok so here's the situation, bestie: the verifier gets confused constantly by the instruction sequence the compiler spits out when you index struct fields or arrays. like, it just does not get it. πŸ’€

This macro's whole job is to force the compiler to generate a code sequence that:

  1. first calculates the byte offset,
  2. checks it against the struct or array size,
  3. and then adds that byte offset to generate the pointer to the member.

all of that so the verifier can actually follow along and chill. it's giving hand-holding for the verifier and honestly? iconic. πŸ‘‘

Ideally, we want to abort if the calculated offset is out-of-bounds. However, BPF currently doesn't support abort, so it evaluates to NULL instead. 😭 The caller must check for NULL and take appropriate action to appease the verifier. To avoid confusing the verifier, it's best to check for NULL and dereference immediately.

vptr = MEMBER_VPTR(my_array, [i][j]); if (!vptr) return error; *vptr = new_value;
🚨 also, sizeof(base) should encompass the memory area to be accessed and thus can't be a pointer to the area. so use MEMBER_VPTR(*ptr, .member) instead of MEMBER_VPTR(ptr, ->member). do not come for me on this one, it's literally right there 🫠

🌈 SEE ALSO 🌈


and that's the tea, bestie πŸ“ this page comes courtesy of ./tools/sched_ext/include/scx, dated October 2026 β€” so go forth, index those members, and check for NULL before you dereference. mwah πŸ’–πŸ§šπŸ’œ

πŸ“¦ where this page comes from