Skip to content

Commit 4cd51c4

Browse files
committed
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.
1 parent 19d2ba3 commit 4cd51c4

File tree

3 files changed

+23
-26
lines changed

3 files changed

+23
-26
lines changed

src/rt/rust_kernel.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -257,25 +257,6 @@ rust_kernel::generate_task_id() {
257257
return id;
258258
}
259259

260-
#ifdef __WIN32__
261-
void
262-
rust_kernel::win32_require(LPCTSTR fn, BOOL ok) {
263-
if (!ok) {
264-
LPTSTR buf;
265-
DWORD err = GetLastError();
266-
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
267-
FORMAT_MESSAGE_FROM_SYSTEM |
268-
FORMAT_MESSAGE_IGNORE_INSERTS,
269-
NULL, err,
270-
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
271-
(LPTSTR) &buf, 0, NULL );
272-
KLOG_ERR_(dom, "%s failed with error %ld: %s", fn, err, buf);
273-
LocalFree((HLOCAL)buf);
274-
assert(ok);
275-
}
276-
}
277-
#endif
278-
279260
void
280261
rust_kernel::set_exit_status(int code) {
281262
scoped_lock with(rval_lock);

src/rt/rust_kernel.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,6 @@ class rust_kernel {
147147
void wait_for_schedulers();
148148
int run();
149149

150-
#ifdef __WIN32__
151-
void win32_require(LPCTSTR fn, BOOL ok);
152-
#endif
153-
154150
rust_task_id generate_task_id();
155151

156152
void set_exit_status(int code);

src/rt/rust_rng.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,26 @@
1212
#include "rust_rng.h"
1313
#include "rust_util.h"
1414

15+
16+
#ifdef __WIN32__
17+
void
18+
win32_require(LPCTSTR fn, BOOL ok) {
19+
if (!ok) {
20+
LPTSTR buf;
21+
DWORD err = GetLastError();
22+
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
23+
FORMAT_MESSAGE_FROM_SYSTEM |
24+
FORMAT_MESSAGE_IGNORE_INSERTS,
25+
NULL, err,
26+
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
27+
(LPTSTR) &buf, 0, NULL );
28+
fprintf(stderr, "%s failed with error %ld: %s", fn, err, buf);
29+
LocalFree((HLOCAL)buf);
30+
abort();
31+
}
32+
}
33+
#endif
34+
1535
size_t
1636
rng_seed_size() {
1737
randctx rctx;
@@ -24,13 +44,13 @@ void
2444
rng_gen_seed(rust_kernel* kernel, uint8_t* dest, size_t size) {
2545
#ifdef __WIN32__
2646
HCRYPTPROV hProv;
27-
kernel->win32_require
47+
win32_require
2848
(_T("CryptAcquireContext"),
2949
CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL,
3050
CRYPT_VERIFYCONTEXT|CRYPT_SILENT));
31-
kernel->win32_require
51+
win32_require
3252
(_T("CryptGenRandom"), CryptGenRandom(hProv, size, (BYTE*) dest));
33-
kernel->win32_require
53+
win32_require
3454
(_T("CryptReleaseContext"), CryptReleaseContext(hProv, 0));
3555
#else
3656
int fd = open("/dev/urandom", O_RDONLY);

0 commit comments

Comments
 (0)