aboutsummaryrefslogtreecommitdiff
path: root/src/rt/rust_util.h
diff options
context:
space:
mode:
authorMichael Bebenita <[email protected]>2010-08-09 07:30:48 -0700
committerMichael Bebenita <[email protected]>2010-08-09 07:30:48 -0700
commitc5744c8aefa1c9f74e779af2c5ceb852640b28b7 (patch)
tree35117b98ea7562db7af3e46ba4f34a9e9101526b /src/rt/rust_util.h
parentAdded a python script to run test cases repeatedly. This helps with debugging... (diff)
downloadrust-c5744c8aefa1c9f74e779af2c5ceb852640b28b7.tar.xz
rust-c5744c8aefa1c9f74e779af2c5ceb852640b28b7.zip
Added the RUST_SEED env variable to seed the Rust task scheduler -- helpful when debugging task race conditions within a single thread domain.
Diffstat (limited to 'src/rt/rust_util.h')
-rw-r--r--src/rt/rust_util.h19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/rt/rust_util.h b/src/rt/rust_util.h
index 42082119..6f2ab4c3 100644
--- a/src/rt/rust_util.h
+++ b/src/rt/rust_util.h
@@ -140,11 +140,20 @@ isaac_init(rust_dom *dom, randctx *rctx)
CryptReleaseContext(hProv, 0));
}
#else
- int fd = open("/dev/urandom", O_RDONLY);
- I(dom, fd > 0);
- I(dom, read(fd, (void*) &rctx->randrsl, sizeof(rctx->randrsl))
- == sizeof(rctx->randrsl));
- I(dom, close(fd) == 0);
+ char *rust_seed = getenv("RUST_SEED");
+ if (rust_seed != NULL) {
+ ub4 seed = (ub4) atoi(rust_seed);
+ for (size_t i = 0; i < RANDSIZ; i ++) {
+ memcpy(&rctx->randrsl[i], &seed, sizeof(ub4));
+ seed = (seed + 0x7ed55d16) + (seed << 12);
+ }
+ } else {
+ int fd = open("/dev/urandom", O_RDONLY);
+ I(dom, fd > 0);
+ I(dom, read(fd, (void*) &rctx->randrsl, sizeof(rctx->randrsl))
+ == sizeof(rctx->randrsl));
+ I(dom, close(fd) == 0);
+ }
#endif
randinit(rctx, 1);
}