Skip to content

Commit

Permalink
Fix server crash due to /dev/urandom
Browse files Browse the repository at this point in the history
  • Loading branch information
jart committed Jun 24, 2024
1 parent 0c0e72a commit 629e208
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions llama.cpp/random.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <random>
#include <unistd.h>

// TODO(jart): delete this with next cosmocc update

namespace std {

random_device::random_device(const string& __token)
{
if (__token != "/dev/urandom")
__throw_system_error(ENOENT, ("random device not supported " + __token).c_str());
}

random_device::~random_device()
{
}

unsigned
random_device::operator()()
{
unsigned r;
size_t n = sizeof(r);
int err = getentropy(&r, n);
if (err)
__throw_system_error(errno, "random_device getentropy failed");
return r;
}

double
random_device::entropy() const noexcept
{
return 0;
}

} // namespace std

0 comments on commit 629e208

Please sign in to comment.