Skip to content

Commit ddc2076

Browse files
committed
Make windows respect RUST_SEED. Closes #627.
1 parent 0a00fab commit ddc2076

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/rt/rust_util.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,15 @@ isaac_init(sched_or_kernel *sched, randctx *rctx)
130130
{
131131
memset(rctx, 0, sizeof(randctx));
132132

133+
char *rust_seed = sched->env->rust_seed;
134+
if (rust_seed != NULL) {
135+
ub4 seed = (ub4) atoi(rust_seed);
136+
for (size_t i = 0; i < RANDSIZ; i ++) {
137+
memcpy(&rctx->randrsl[i], &seed, sizeof(ub4));
138+
seed = (seed + 0x7ed55d16) + (seed << 12);
139+
}
140+
} else {
133141
#ifdef __WIN32__
134-
{
135142
HCRYPTPROV hProv;
136143
sched->win32_require
137144
(_T("CryptAcquireContext"),
@@ -144,24 +151,16 @@ isaac_init(sched_or_kernel *sched, randctx *rctx)
144151
sched->win32_require
145152
(_T("CryptReleaseContext"),
146153
CryptReleaseContext(hProv, 0));
147-
}
148154
#else
149-
char *rust_seed = sched->env->rust_seed;
150-
if (rust_seed != NULL) {
151-
ub4 seed = (ub4) atoi(rust_seed);
152-
for (size_t i = 0; i < RANDSIZ; i ++) {
153-
memcpy(&rctx->randrsl[i], &seed, sizeof(ub4));
154-
seed = (seed + 0x7ed55d16) + (seed << 12);
155-
}
156-
} else {
157155
int fd = open("/dev/urandom", O_RDONLY);
158156
I(sched, fd > 0);
159157
I(sched,
160158
read(fd, (void*) &rctx->randrsl, sizeof(rctx->randrsl))
161159
== sizeof(rctx->randrsl));
162160
I(sched, close(fd) == 0);
163-
}
164161
#endif
162+
}
163+
165164
randinit(rctx, 1);
166165
}
167166

0 commit comments

Comments
 (0)