-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make system random work in VM #17059
Conversation
@@ -158,7 +158,8 @@ elif defined(windows): | |||
result = randomBytes(addr dest[0], size) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about adding this at top-level:
when defined(nimExperimentalSysrand):
... # all module goes here
refs timotheecour#575
until we stabilize the API
that flag can still be used in stdlib eg in random.randomize
:
when defined(nimExperimentalSysrand):
# use std/sysrandom
else:
# use time based version
EDIT: would require when defined(nimExperimentalSysrand) or defined(booting):
so that it also works with vmops
|
||
proc getNodeAddr*(a: VmArgs; i: Natural): PNode = | ||
doAssert i < a.rc-1 | ||
doAssert a.slots[i+a.rb+1].kind == rkNodeAddr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in future work we may need to revisit whether to use assert
instead of doAssert
in most places in this file (depends whether it's a bottleneck)
@@ -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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is cleaner, less different code paths:
proc urandom*(size: Natural): seq[byte] {.inline.} =
## Returns random bytes suitable for cryptographic use.
result = newSeq[byte](size)
if not urandom(result):
when not defined(js):
raiseOSError(osLastError())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I can reduce a JS call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM; remaining suggestions can be done either here or in future work
This reverts commit 4f11872.
* make system random work in VM
No description provided.