rt: Make isaac_init not a template

This commit is contained in:
Brian Anderson 2012-02-03 18:42:12 -08:00
parent f7a727e861
commit 21d783c338
5 changed files with 12 additions and 19 deletions

View File

@ -139,7 +139,7 @@ rand_new() {
task->fail();
return NULL;
}
isaac_init(thread, rctx);
isaac_init(thread->kernel, rctx);
return rctx;
}

View File

@ -9,7 +9,7 @@ rust_scheduler::rust_scheduler(rust_kernel *kernel,
env(srv->env),
num_threads(num_threads)
{
isaac_init(this, &rctx);
isaac_init(kernel, &rctx);
create_task_threads();
}

View File

@ -37,7 +37,7 @@ rust_task_thread::rust_task_thread(rust_scheduler *sched,
should_exit(false)
{
LOGPTR(this, "new dom", (uintptr_t)this);
isaac_init(this, &rctx);
isaac_init(kernel, &rctx);
#ifndef __WIN32__
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, 1024 * 1024);

View File

@ -117,12 +117,6 @@ struct rust_task_thread : public kernel_owned<rust_task_thread>,
virtual void run();
#ifdef __WIN32__
inline void win32_require(LPCTSTR fn, BOOL ok) {
kernel->win32_require(fn, ok);
}
#endif
void init_tls();
void place_task_in_tls(rust_task *task);

View File

@ -124,13 +124,12 @@ align_to(T size, size_t alignment) {
// Initialization helper for ISAAC RNG
template <typename thread_or_kernel>
static inline void
isaac_init(thread_or_kernel *thread, randctx *rctx)
inline void
isaac_init(rust_kernel *kernel, randctx *rctx)
{
memset(rctx, 0, sizeof(randctx));
char *rust_seed = thread->env->rust_seed;
char *rust_seed = kernel->env->rust_seed;
if (rust_seed != NULL) {
ub4 seed = (ub4) atoi(rust_seed);
for (size_t i = 0; i < RANDSIZ; i ++) {
@ -140,24 +139,24 @@ isaac_init(thread_or_kernel *thread, randctx *rctx)
} else {
#ifdef __WIN32__
HCRYPTPROV hProv;
thread->win32_require
kernel->win32_require
(_T("CryptAcquireContext"),
CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT|CRYPT_SILENT));
thread->win32_require
kernel->win32_require
(_T("CryptGenRandom"),
CryptGenRandom(hProv, sizeof(rctx->randrsl),
(BYTE*)(&rctx->randrsl)));
thread->win32_require
kernel->win32_require
(_T("CryptReleaseContext"),
CryptReleaseContext(hProv, 0));
#else
int fd = open("/dev/urandom", O_RDONLY);
I(thread, fd > 0);
I(thread,
I(kernel, fd > 0);
I(kernel,
read(fd, (void*) &rctx->randrsl, sizeof(rctx->randrsl))
== sizeof(rctx->randrsl));
I(thread, close(fd) == 0);
I(kernel, close(fd) == 0);
#endif
}