From 7ee4af9e79f294033eaa51a2a272606e1630ffcc Mon Sep 17 00:00:00 2001 From: Nathan Sashihara <21227491+n8sh@users.noreply.github.com> Date: Mon, 19 Feb 2018 07:32:49 -0500 Subject: [PATCH] Use correct getrandom linux syscall on non-x86_64 --- dub.json | 4 ++++ source/tanya/math/random.d | 19 +++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/dub.json b/dub.json index d3cdf03..70cb5b4 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 2275d98..c68f477 100644 --- a/source/tanya/math/random.d +++ b/source/tanya/math/random.d @@ -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); } }