rt: Move win32_require out of the rust_kernel type
This is only used on rust_rng, which I am trying to extricate from the kernel.
This commit is contained in:
parent
19d2ba3383
commit
4cd51c416b
|
@ -257,25 +257,6 @@ rust_kernel::generate_task_id() {
|
|||
return id;
|
||||
}
|
||||
|
||||
#ifdef __WIN32__
|
||||
void
|
||||
rust_kernel::win32_require(LPCTSTR fn, BOOL ok) {
|
||||
if (!ok) {
|
||||
LPTSTR buf;
|
||||
DWORD err = GetLastError();
|
||||
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, err,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPTSTR) &buf, 0, NULL );
|
||||
KLOG_ERR_(dom, "%s failed with error %ld: %s", fn, err, buf);
|
||||
LocalFree((HLOCAL)buf);
|
||||
assert(ok);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
rust_kernel::set_exit_status(int code) {
|
||||
scoped_lock with(rval_lock);
|
||||
|
|
|
@ -147,10 +147,6 @@ public:
|
|||
void wait_for_schedulers();
|
||||
int run();
|
||||
|
||||
#ifdef __WIN32__
|
||||
void win32_require(LPCTSTR fn, BOOL ok);
|
||||
#endif
|
||||
|
||||
rust_task_id generate_task_id();
|
||||
|
||||
void set_exit_status(int code);
|
||||
|
|
|
@ -12,6 +12,26 @@
|
|||
#include "rust_rng.h"
|
||||
#include "rust_util.h"
|
||||
|
||||
|
||||
#ifdef __WIN32__
|
||||
void
|
||||
win32_require(LPCTSTR fn, BOOL ok) {
|
||||
if (!ok) {
|
||||
LPTSTR buf;
|
||||
DWORD err = GetLastError();
|
||||
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, err,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPTSTR) &buf, 0, NULL );
|
||||
fprintf(stderr, "%s failed with error %ld: %s", fn, err, buf);
|
||||
LocalFree((HLOCAL)buf);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t
|
||||
rng_seed_size() {
|
||||
randctx rctx;
|
||||
|
@ -24,13 +44,13 @@ void
|
|||
rng_gen_seed(rust_kernel* kernel, uint8_t* dest, size_t size) {
|
||||
#ifdef __WIN32__
|
||||
HCRYPTPROV hProv;
|
||||
kernel->win32_require
|
||||
win32_require
|
||||
(_T("CryptAcquireContext"),
|
||||
CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL,
|
||||
CRYPT_VERIFYCONTEXT|CRYPT_SILENT));
|
||||
kernel->win32_require
|
||||
win32_require
|
||||
(_T("CryptGenRandom"), CryptGenRandom(hProv, size, (BYTE*) dest));
|
||||
kernel->win32_require
|
||||
win32_require
|
||||
(_T("CryptReleaseContext"), CryptReleaseContext(hProv, 0));
|
||||
#else
|
||||
int fd = open("/dev/urandom", O_RDONLY);
|
||||
|
|
Loading…
Reference in New Issue