Use correct getrandom linux syscall on non-x86_64
This commit is contained in:
parent
bd2b88f16e
commit
7ee4af9e79
4
dub.json
4
dub.json
@ -9,6 +9,10 @@
|
||||
|
||||
"targetType": "library",
|
||||
|
||||
"dependencies-linux": {
|
||||
"mir-linux-kernel": "~>1.0.0",
|
||||
},
|
||||
|
||||
"configurations": [
|
||||
{
|
||||
"name": "library",
|
||||
|
@ -96,7 +96,8 @@ abstract class EntropySource
|
||||
|
||||
version (linux)
|
||||
{
|
||||
extern (C) long syscall(long number, ...) nothrow @system @nogc;
|
||||
import core.stdc.config : c_long;
|
||||
extern (C) c_long syscall(c_long number, ...) nothrow @system @nogc;
|
||||
|
||||
/**
|
||||
* Uses getrandom system call.
|
||||
@ -137,7 +138,8 @@ version (linux)
|
||||
do
|
||||
{
|
||||
// int getrandom(void *buf, size_t buflen, unsigned int flags);
|
||||
auto length = syscall(318, output.ptr, output.length, 0);
|
||||
import mir.linux._asm.unistd : NR_getrandom;
|
||||
auto length = syscall(NR_getrandom, output.ptr, output.length, 0);
|
||||
Nullable!ubyte ret;
|
||||
|
||||
if (length >= 0)
|
||||
@ -148,16 +150,13 @@ version (linux)
|
||||
}
|
||||
}
|
||||
|
||||
version (X86_64)
|
||||
@nogc @system unittest
|
||||
{
|
||||
private unittest
|
||||
{
|
||||
auto entropy = defaultAllocator.make!Entropy();
|
||||
ubyte[blockSize] output;
|
||||
output = entropy.random;
|
||||
auto entropy = defaultAllocator.make!Entropy();
|
||||
ubyte[blockSize] output;
|
||||
output = entropy.random;
|
||||
|
||||
defaultAllocator.dispose(entropy);
|
||||
}
|
||||
defaultAllocator.dispose(entropy);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user