__cvdso_getrandom_data(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸŽ€ __cvdso_getrandom_data(9) β€” the Kernel API Manual bestie ✨

okay so real talk, this page lives in the Kernel API Manual and it's all about __cvdso_getrandom_data β€” the generic vDSO implementation of the getrandom() syscall. yes, the generic one. the vibe is "one implementation to rule them all" and honestly? iconic. πŸ’…


✨ NAME ✨

__cvdso_getrandom_data β€” the generic vDSO implementation of the getrandom() syscall. that's it, that's the whole thing, and it ate. 🫢


🌸 SYNOPSIS 🌸

ssize_t __cvdso_getrandom_data (const struct vdso_rng_data *rng_info ,
void *buffer , size_t len , unsigned int flags , void *opaque_state ,
size_t opaque_len );

like, that's the whole signature, no cap. five-ish args and a ssize_t return. main character function energy fr fr. πŸ¦‹


πŸ’œ ARGUMENTS πŸ’œ

okay bestie, let's meet the cast:

  • rng_info β€” describes the state of the kernel RNG. it's memory shared with the kernel, so don't go doing weird stuff to it, mwah. 🌈
  • buffer β€” the destination buffer that gets filled with random bytes. this is the whole point, lowkey. ✨
  • len β€” the size of buffer, in bytes. yes, bytes. not vibes, bytes.
  • flags β€” zero or more GRND_* flags. zero is allowed! zero or more! πŸŽ€
  • opaque_state β€” a pointer to an opaque state area. mysterious. love that for it. πŸ™ˆ
  • opaque_len β€” the length of that opaque state area. gotta match, iykyk.

🧚 DESCRIPTION 🧚

so this implements a "fast key erasure" RNG using ChaCha20, in exactly the same way the kernel's getrandom syscall does. same way! it periodically reseeds its key from the kernel's RNG, on the same schedule that the kernel's RNG is reseeded. synchronization slay. πŸ”₯

and if the kernel's RNG is not ready? then this always calls into the syscall. no shortcuts, no pretending. it knows when to defer. πŸ‘‘

okay here's the special little handshake mode, pay attention bestie:

if buffer, len, and flags are 0, and opaque_len is ~0UL, then opaque_state is populated with a struct vgetrandom_opaque_params and the function returns 0. and if it does not return 0, this function should not be used. like, at all. that's the vibe check and it failed. πŸ’€

now the rules about opaque_state, and these are strict:

  • opaque_state must be allocated by calling mmap(2) using the mmap_prot and mmap_flags fields from the struct vgetrandom_opaque_params. no malloc, no "i'll just put it on the stack", none of that. 🚫
  • states must not straddle pages. that's a hard no.
  • unless external locking is used, one state must be allocated per thread β€” because it is not safe to call this function concurrently with the same opaque_state. periodt. 😭
  • however β€” and this is the cute exception β€” it is safe to call this using the same opaque_state that's shared between main code and signal handling code, within the same thread. same thread only though! don't push your luck. πŸ“

⭐ RETURN ⭐

the number of random bytes written to buffer, or a negative value indicating an error. that's it. bytes or bad news. 🌸


🌈 SEE ALSO 🌈

  • Kernel file ./lib/vdso/getrandom.c β€” go read the source, it's giving transparency. πŸ‘‘

so yeah, that's the whole page! straight from ./lib/vdso, dated October 2026, and honestly? she's a keeper. go forth and get your random bytes responsibly, bestie πŸ«ΆπŸ’–βœ¨

πŸ“¦ where this page comes from