__get_unaligned_t(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ __get_unaligned_t(9) ✨

okay so bestie, grab your iced coffee πŸ“ β€” this is a page from the Kernel API Manual and it's literally about reading an unaligned value out of memory. no cap, it's giving "tiny helper, big safety energy" πŸ’…


πŸ¦‹ NAME πŸ¦‹

__get_unaligned_t β€” read an unaligned value from memory 🫢


🌸 SYNOPSIS 🌸

__get_unaligned_t (type , ptr );

πŸŽ€ ARGUMENTS πŸŽ€

  • type β€” the type you're loading from the pointer, like, the whole entire personality of the load πŸ’–
  • ptr β€” the pointer you're loading from. the source. the main character ✨

πŸ’œ DESCRIPTION πŸ’œ

so the way this works is it uses memcpy to do an unaligned type-sized load, and that's on purpose β€” it's dodging the undefined behavior you'd get from approaches like type punning, which need -fno-strict-aliasing in order to be correct. like, no thank you, we're not doing that πŸ™ˆ

since type may be const, it uses __unqual_scalar_typeof to map over to a non-const type β€” because you literally can't memcpy into a const type, that's just the rules, periodt πŸ’€

and the __get_unaligned_ctrl_type gives __unqual_scalar_typeof the required expression rather than a type, and a pointer is used to avoid warnings about mixing the use of 0 and NULL. iykyk πŸ”₯

last thing: the void* cast silences ubsan warnings. slay, honestly πŸ‘‘


🌈 SEE ALSO 🌈

  • Kernel file ./tools/include/vdso/unaligned.h
  • __put_unaligned_t(9) β€” the other half of the duo, go say hi πŸ¦‹

and that's the whole vibe check, bestie β€” this page came from ./tools/include/vdso, dated October 2026, and it was iconic from start to finish πŸ˜­πŸ’–

πŸ“¦ where this page comes from