Skip to content

Commit 629e208

Browse files
committed
Fix server crash due to /dev/urandom
1 parent 0c0e72a commit 629e208

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

llama.cpp/random.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <random>
2+
#include <unistd.h>
3+
4+
// TODO(jart): delete this with next cosmocc update
5+
6+
namespace std {
7+
8+
random_device::random_device(const string& __token)
9+
{
10+
if (__token != "/dev/urandom")
11+
__throw_system_error(ENOENT, ("random device not supported " + __token).c_str());
12+
}
13+
14+
random_device::~random_device()
15+
{
16+
}
17+
18+
unsigned
19+
random_device::operator()()
20+
{
21+
unsigned r;
22+
size_t n = sizeof(r);
23+
int err = getentropy(&r, n);
24+
if (err)
25+
__throw_system_error(errno, "random_device getentropy failed");
26+
return r;
27+
}
28+
29+
double
30+
random_device::entropy() const noexcept
31+
{
32+
return 0;
33+
}
34+
35+
} // namespace std

0 commit comments

Comments
 (0)