summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2018-02-22 05:25:59 +0100
committerEugen Wissner <belka@caraus.de>2018-02-22 05:25:59 +0100
commitaf942116e4acc5424c5e9883eb8173904f0b84df (patch)
treeb931f7410e89f3f1601c66b46eeaf22f0f02f033
parent9876d9245c76056e190a12c9ed471f047e57a37e (diff)
parent7ee4af9e79f294033eaa51a2a272606e1630ffcc (diff)
downloadtanya-af942116e4acc5424c5e9883eb8173904f0b84df.tar.gz
Merge remote-tracking branch 'n8sh/getrandom-syscall'
Fix #18.
-rw-r--r--dub.json4
-rw-r--r--source/tanya/math/random.d19
2 files changed, 13 insertions, 10 deletions
diff --git a/dub.json b/dub.json
index f60f05b..f25a4e6 100644
--- a/dub.json
+++ b/dub.json
@@ -9,6 +9,10 @@
"targetType": "library",
+ "dependencies-linux": {
+ "mir-linux-kernel": "~>1.0.0",
+ },
+
"configurations": [
{
"name": "library",
diff --git a/source/tanya/math/random.d b/source/tanya/math/random.d
index 6978f8d..79399c1 100644
--- a/source/tanya/math/random.d
+++ b/source/tanya/math/random.d
@@ -117,7 +117,8 @@ else version (Solaris)
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.
@@ -158,7 +159,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)
@@ -169,16 +171,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);
}
}
else version (SecureARC4Random)