Skip to content

Commit

Permalink
Fix Linux getrandom failure in interpreted code
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed Sep 25, 2024
1 parent cde543a commit 2d6d0d8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/crystal/system/unix/getrandom.cr
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,16 @@ module Crystal::System::Random
loop do
read_bytes = Syscall.getrandom(buf.to_unsafe, LibC::SizeT.new(buf.size), Syscall::GRND_NONBLOCK)
if read_bytes < 0
err = Errno.new(-read_bytes.to_i)
# TODO: Implement syscall for interpreter
# when using `LibC.getrandom` instead, the return value is always -1 and
# the error is set via `Errno.value` instead
err =
{% if flag?(:interpreted) %}
Errno.value
{% else %}
Errno.new(-read_bytes.to_i)
{% end %}

if err.in?(Errno::EINTR, Errno::EAGAIN)
::Fiber.yield
else
Expand Down

0 comments on commit 2d6d0d8

Please sign in to comment.