diff options
author | flywind <43030857+xflywind@users.noreply.github.com> | 2021-02-17 04:52:46 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-17 11:52:46 +0100 |
commit | 4f118721be7b515f1d5e6fb66ae9e73ddb819f02 (patch) | |
tree | 58914fca366d8b1344e5700a5ea0be240ee547e2 /lib/std | |
parent | f32ffb6ed821cc01e52c48181a4caa15e73c0362 (diff) | |
download | Nim-4f118721be7b515f1d5e6fb66ae9e73ddb819f02.tar.gz |
make system random work in VM (#17059)
* make system random work in VM
Diffstat (limited to 'lib/std')
-rw-r--r-- | lib/std/sysrand.nim | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/std/sysrand.nim b/lib/std/sysrand.nim index 9a143adb3..75a1af5a9 100644 --- a/lib/std/sysrand.nim +++ b/lib/std/sysrand.nim @@ -158,7 +158,8 @@ elif defined(windows): result = randomBytes(addr dest[0], size) elif defined(linux): - let SYS_getrandom {.importc: "SYS_getrandom", header: "<sys/syscall.h>".}: clong + # TODO using let, pending bootstrap >= 1.4.0 + var SYS_getrandom {.importc: "SYS_getrandom", header: "<sys/syscall.h>".}: clong const syscallHeader = """#include <unistd.h> #include <sys/syscall.h>""" @@ -209,7 +210,7 @@ elif defined(freebsd): # errno is set to indicate the error. proc getRandomImpl(p: pointer, size: int): int {.inline.} = - result = getrandom(p, csize_t(batchSize), 0) + result = getrandom(p, csize_t(size), 0) elif defined(ios): {.passL: "-framework Security".} @@ -284,7 +285,7 @@ proc urandomInternalImpl(dest: var openArray[byte]): int {.inline.} = proc urandom*(dest: var openArray[byte]): bool = ## Fills `dest` with random bytes suitable for cryptographic use. - ## If succeed, returns `true`. + ## If the call succeeds, returns `true`. ## ## If `dest` is empty, `urandom` immediately returns success, ## without calling underlying operating system api. @@ -305,4 +306,4 @@ proc urandom*(size: Natural): seq[byte] {.inline.} = when defined(js): discard urandomInternalImpl(result) else: if not urandom(result): - raiseOsError(osLastError()) + raiseOSError(osLastError()) |