Don't block in getrandom() detection#26
Merged
newpavlov merged 1 commit intorust-random:masterfrom Jun 10, 2019
Merged
Conversation
On Linux, we detect if `getrandom` is present by calling getrandom with an empty buffer and seeing if `ENOSYS` is returned. However, even with an empty buffer, this call will block unless we explicitly pass a flag. This can be seen in the source for `getrandom`: https://elixir.bootlin.com/linux/v5.1.8/source/drivers/char/random.c#L2043 This change adds a boolean parameter to `syscall_getrandom` to control the blocking behavior. We now don't block in initialization, but do block when actually reading random data.
dhardy
approved these changes
Jun 10, 2019
Member
dhardy
left a comment
There was a problem hiding this comment.
I think in practice it doesn't make much difference since detection happens on first use. Looks good to me however.
Member
|
I also think that blocking is not a big deal. If kernel does not have |
takumi-earth
pushed a commit
to earthlings-dev/getrandom
that referenced
this pull request
Jan 27, 2026
On Linux, we detect if `getrandom` is present by calling getrandom with an empty buffer and seeing if `ENOSYS` is returned. However, even with an empty buffer, this call will block unless we explicitly pass a flag. This can be seen in the source for `getrandom`: https://elixir.bootlin.com/linux/v5.1.8/source/drivers/char/random.c#L2043 This change adds a boolean parameter to `syscall_getrandom` to control the blocking behavior. We now don't block in initialization, but do block when actually reading random data.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Linux, we detect if
getrandomis present by callinggetrandomwithan empty buffer and seeing if
ENOSYSis returned. However, even withan empty buffer, this call will block unless we explicitly pass a flag.
This can be seen in the source for
getrandom:https://elixir.bootlin.com/linux/v5.1.8/source/drivers/char/random.c#L2043
This change adds a boolean parameter to
syscall_getrandomto controlthe blocking behavior. We now don't block in initialization, but do
block when actually reading random data.