STRUCT HID_BPF_CTX(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… struct hid_bpf_ctx(9) β€” Kernel API Manual, but make it cute

okay bestie, so this is struct hid_bpf_ctx β€” it's literally the user-accessible data for all HID programs ✨. Like, every single one. That's the whole vibe.


✨ SYNOPSIS ✨

struct hid_bpf_ctx {
    struct hid_device *hid;
    __u32 allocated_size;
    union {
      __s32 retval;
      __s32 size;
    };
 };

no cap, that's exactly it, copy it character for character 🫢


πŸŽ€ Members πŸŽ€

  • hid β€” the struct hid_device that represents the device itself. main character energy, honestly πŸ‘‘
  • allocated_size β€” how much data is allocated. the size of the data. that's it, that's the tweet πŸ’…
  • {unnamed_union} β€” anonymous. yes really, it's just chillin' there unnamed πŸ™ˆ
  • retval β€” the return value of the previous program. lowkey important πŸ‘€
  • size β€” the valid data in the data field. the actual usable amount πŸ”₯

πŸ¦‹ Description πŸ¦‹

so here's the thing bestie β€” data is not directly accessible from the context. 😭 like you can't just grab it. you gotta issue a call to hid_bpf_get_data in order to get a pointer to that field. that's the whole move, iykyk.

allocated_size is how much memory is available and can be requested by the HID program. and important note, fr fr: for HID_BPF_RDESC_FIXUP, that memory is set to 4096 (4 KB). periodt.

programs can get the available valid size in data by fetching this field. programs can also change this value by returning a positive number in the program. and to discard the event? return a negative error code. simple as that πŸ’€

⚠️ size must always be less or equal than allocated_size β€” and yes it's enforced once all BPF programs have been run. so don't try it, the kernel will vibe check you 😀

and for the read/write tea: hid and allocated_size are read-only, while size and retval are read-write. slay, now you know 🌸


🌈 SEE ALSO 🌈

  • Kernel file ./include/linux/hid_bpf.h
  • struct hid_bpf_ops(9)

and that's the whole page, bestie! πŸ’– this absolute icon came from ./include/linux, dated October 2026, and it's filed under struct hid_bpf_ctx(9) β€” go off, king πŸ§šβœ¨πŸŽ€

πŸ“¦ where this page comes from