__cvdso_getrandom_data(9)
π __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 ofbuffer, in bytes. yes, bytes. not vibes, bytes.flagsβ zero or moreGRND_*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_statemust be allocated by callingmmap(2)using themmap_protandmmap_flagsfields from thestruct vgetrandom_opaque_params. nomalloc, 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_statethat'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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms