strnlen_user_nofault(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… strnlen_user_nofault πŸ’…

okay bestie, welcome to the kernel API manual for strnlen_user_nofault β€” yes that name is a mouthful, yes it's iconic, and yes we're gonna get through it together 🫢


✨ NAME ✨

strnlen_user_nofault β€” get the size of a user string INCLUDING the final NUL πŸŽ€


🌸 SYNOPSIS 🌸

long strnlen_user_nofault (const void __user *unsafe_addr , long count );

that's the whole signature, no cap. take it in. πŸ“


πŸ¦‹ ARGUMENTS πŸ¦‹

  • unsafe_addr β€” the string we're measuring, literally. give it the address, it gives you the length 🧚
  • count β€” the maximum count, and yes that includes the NUL bestie, don't forget the NUL πŸ’€

πŸ’– DESCRIPTION πŸ’–

So what does it do? It gets the size of a NUL-terminated string in user space without pagefault ✨ like, it just does it. no faulting, no drama.

It returns the size of the string INCLUDING the terminating NUL, periodt πŸ‘‘

Now here's the part where you gotta pay attention: if the string is too long, it returns a number larger than count. so you, the caller, have to check the return value against "> count" yourself. that's on you, bestie πŸ™ˆ

And on exception (or an invalid count), it returns 0. zero. zilch. 😭

Unlike strnlen_user, this one can be used from an IRQ handler etc. because it disables pagefaults πŸ”₯ that's the whole glow-up, iykyk. (and also, lowkey, the reason it's "nofault" β€” the name is giving exactly what it should πŸ’…)

πŸ‘‘ SEE ALSO πŸ‘‘


and that's the page!! 🌈 this lil' beauty lives in ./mm and it's dated October 2026 β€” so yeah, mark your calendar, screenshot it, send it to the group chat, whatever you gotta do πŸ“πŸ’œ mwah, go measure those strings responsibly πŸ’…βœ¨

πŸ“¦ where this page comes from