Skip to content

Commit 02f6645

Browse files
Eric Holkgraydon
Eric Holk
authored andcommitted
Moved win32_require to the kernel.
1 parent 2f84987 commit 02f6645

File tree

7 files changed

+34
-33
lines changed

7 files changed

+34
-33
lines changed

src/rt/rust.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ command_line_args : public kernel_owned<command_line_args>
2323
#if defined(__WIN32__)
2424
LPCWSTR cmdline = GetCommandLineW();
2525
LPWSTR *wargv = CommandLineToArgvW(cmdline, &argc);
26-
task->dom->win32_require("CommandLineToArgvW", wargv != NULL);
26+
kernel->win32_require("CommandLineToArgvW", wargv != NULL);
2727
argv = (char **) kernel->malloc(sizeof(char*) * argc);
2828
for (int i = 0; i < argc; ++i) {
2929
int n_chars = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1,
3030
NULL, 0, NULL, NULL);
31-
task->dom->win32_require("WideCharToMultiByte(0)", n_chars != 0);
31+
kernel->win32_require("WideCharToMultiByte(0)", n_chars != 0);
3232
argv[i] = (char *) kernel->malloc(n_chars);
3333
n_chars = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1,
3434
argv[i], n_chars, NULL, NULL);
35-
task->dom->win32_require("WideCharToMultiByte(1)", n_chars != 0);
35+
kernel->win32_require("WideCharToMultiByte(1)", n_chars != 0);
3636
}
3737
LocalFree(wargv);
3838
#endif

src/rt/rust_dom.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,6 @@ rust_dom::fail() {
7474
rval = 1;
7575
}
7676

77-
#ifdef __WIN32__
78-
void
79-
rust_dom::win32_require(LPCTSTR fn, BOOL ok) {
80-
if (!ok) {
81-
LPTSTR buf;
82-
DWORD err = GetLastError();
83-
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
84-
FORMAT_MESSAGE_FROM_SYSTEM |
85-
FORMAT_MESSAGE_IGNORE_INSERTS,
86-
NULL, err,
87-
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
88-
(LPTSTR) &buf, 0, NULL );
89-
DLOG_ERR(this, dom, "%s failed with error %ld: %s", fn, err, buf);
90-
LocalFree((HLOCAL)buf);
91-
I(this, ok);
92-
}
93-
}
94-
#endif
95-
9677
size_t
9778
rust_dom::number_of_live_tasks() {
9879
return running_tasks.length() + blocked_tasks.length();

src/rt/rust_dom.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ struct rust_dom : public kernel_owned<rust_dom>, rc_base<rust_dom>
7575

7676
void drain_incoming_message_queue(bool process);
7777

78-
#ifdef __WIN32__
79-
void win32_require(LPCTSTR fn, BOOL ok);
80-
#endif
81-
8278
rust_crate_cache *get_cache();
8379
size_t number_of_live_tasks();
8480

src/rt/rust_kernel.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,25 @@ int rust_kernel::start_task_threads(int num_threads)
245245
return dom->rval;
246246
}
247247

248+
#ifdef __WIN32__
249+
void
250+
rust_kernel::win32_require(LPCTSTR fn, BOOL ok) {
251+
if (!ok) {
252+
LPTSTR buf;
253+
DWORD err = GetLastError();
254+
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
255+
FORMAT_MESSAGE_FROM_SYSTEM |
256+
FORMAT_MESSAGE_IGNORE_INSERTS,
257+
NULL, err,
258+
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
259+
(LPTSTR) &buf, 0, NULL );
260+
DLOG_ERR(dom, dom, "%s failed with error %ld: %s", fn, err, buf);
261+
LocalFree((HLOCAL)buf);
262+
I(dom, ok);
263+
}
264+
}
265+
#endif
266+
248267
rust_task_thread::rust_task_thread(int id, rust_kernel *owner)
249268
: id(id), owner(owner)
250269
{

src/rt/rust_kernel.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,14 @@ class rust_kernel : public rust_thread {
110110
void *malloc(size_t size);
111111
void free(void *mem);
112112

113-
// TODO: this should go away
113+
// FIXME: this should go away
114114
inline rust_dom *get_domain() const { return dom; }
115115

116116
int start_task_threads(int num_threads);
117+
118+
#ifdef __WIN32__
119+
void win32_require(LPCTSTR fn, BOOL ok);
120+
#endif
117121
};
118122

119123
class rust_task_thread : public rust_thread {

src/rt/rust_timer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ rust_timer::rust_timer(rust_dom *dom) :
5757
DLOG(dom, timer, "creating timer for domain 0x%" PRIxPTR, dom);
5858
#if defined(__WIN32__)
5959
thread = CreateThread(NULL, 0, timer_loop, this, 0, NULL);
60-
dom->win32_require("CreateThread", thread != NULL);
60+
dom->kernel->win32_require("CreateThread", thread != NULL);
6161
if (RUNNING_ON_VALGRIND)
6262
Sleep(10);
6363
#else
@@ -70,8 +70,9 @@ rust_timer::rust_timer(rust_dom *dom) :
7070
rust_timer::~rust_timer() {
7171
exit_flag = 1;
7272
#if defined(__WIN32__)
73-
dom->win32_require("WaitForSingleObject",
74-
WaitForSingleObject(thread, INFINITE) == WAIT_OBJECT_0);
73+
dom->kernel->win32_require("WaitForSingleObject",
74+
WaitForSingleObject(thread, INFINITE) ==
75+
WAIT_OBJECT_0);
7576
#else
7677
pthread_join(thread, NULL);
7778
#endif

src/rt/rust_util.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,15 @@ isaac_init(rust_dom *dom, randctx *rctx)
134134
#ifdef __WIN32__
135135
{
136136
HCRYPTPROV hProv;
137-
dom->win32_require
137+
dom->kernel->win32_require
138138
(_T("CryptAcquireContext"),
139139
CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL,
140140
CRYPT_VERIFYCONTEXT|CRYPT_SILENT));
141-
dom->win32_require
141+
dom->kernel->win32_require
142142
(_T("CryptGenRandom"),
143143
CryptGenRandom(hProv, sizeof(rctx->randrsl),
144144
(BYTE*)(&rctx->randrsl)));
145-
dom->win32_require
145+
dom->kernel->win32_require
146146
(_T("CryptReleaseContext"),
147147
CryptReleaseContext(hProv, 0));
148148
}

0 commit comments

Comments
 (0)