Moved win32_require to the kernel.

This commit is contained in:
Eric Holk 2011-06-28 11:34:20 -07:00 committed by Graydon Hoare
parent 2f84987a48
commit 02f6645fca
7 changed files with 34 additions and 33 deletions

View File

@ -23,16 +23,16 @@ command_line_args : public kernel_owned<command_line_args>
#if defined(__WIN32__)
LPCWSTR cmdline = GetCommandLineW();
LPWSTR *wargv = CommandLineToArgvW(cmdline, &argc);
task->dom->win32_require("CommandLineToArgvW", wargv != NULL);
kernel->win32_require("CommandLineToArgvW", wargv != NULL);
argv = (char **) kernel->malloc(sizeof(char*) * argc);
for (int i = 0; i < argc; ++i) {
int n_chars = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1,
NULL, 0, NULL, NULL);
task->dom->win32_require("WideCharToMultiByte(0)", n_chars != 0);
kernel->win32_require("WideCharToMultiByte(0)", n_chars != 0);
argv[i] = (char *) kernel->malloc(n_chars);
n_chars = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1,
argv[i], n_chars, NULL, NULL);
task->dom->win32_require("WideCharToMultiByte(1)", n_chars != 0);
kernel->win32_require("WideCharToMultiByte(1)", n_chars != 0);
}
LocalFree(wargv);
#endif

View File

@ -74,25 +74,6 @@ rust_dom::fail() {
rval = 1;
}
#ifdef __WIN32__
void
rust_dom::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 );
DLOG_ERR(this, dom, "%s failed with error %ld: %s", fn, err, buf);
LocalFree((HLOCAL)buf);
I(this, ok);
}
}
#endif
size_t
rust_dom::number_of_live_tasks() {
return running_tasks.length() + blocked_tasks.length();

View File

@ -75,10 +75,6 @@ struct rust_dom : public kernel_owned<rust_dom>, rc_base<rust_dom>
void drain_incoming_message_queue(bool process);
#ifdef __WIN32__
void win32_require(LPCTSTR fn, BOOL ok);
#endif
rust_crate_cache *get_cache();
size_t number_of_live_tasks();

View File

@ -245,6 +245,25 @@ int rust_kernel::start_task_threads(int num_threads)
return dom->rval;
}
#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 );
DLOG_ERR(dom, dom, "%s failed with error %ld: %s", fn, err, buf);
LocalFree((HLOCAL)buf);
I(dom, ok);
}
}
#endif
rust_task_thread::rust_task_thread(int id, rust_kernel *owner)
: id(id), owner(owner)
{

View File

@ -110,10 +110,14 @@ public:
void *malloc(size_t size);
void free(void *mem);
// TODO: this should go away
// FIXME: this should go away
inline rust_dom *get_domain() const { return dom; }
int start_task_threads(int num_threads);
#ifdef __WIN32__
void win32_require(LPCTSTR fn, BOOL ok);
#endif
};
class rust_task_thread : public rust_thread {

View File

@ -57,7 +57,7 @@ rust_timer::rust_timer(rust_dom *dom) :
DLOG(dom, timer, "creating timer for domain 0x%" PRIxPTR, dom);
#if defined(__WIN32__)
thread = CreateThread(NULL, 0, timer_loop, this, 0, NULL);
dom->win32_require("CreateThread", thread != NULL);
dom->kernel->win32_require("CreateThread", thread != NULL);
if (RUNNING_ON_VALGRIND)
Sleep(10);
#else
@ -70,8 +70,9 @@ rust_timer::rust_timer(rust_dom *dom) :
rust_timer::~rust_timer() {
exit_flag = 1;
#if defined(__WIN32__)
dom->win32_require("WaitForSingleObject",
WaitForSingleObject(thread, INFINITE) == WAIT_OBJECT_0);
dom->kernel->win32_require("WaitForSingleObject",
WaitForSingleObject(thread, INFINITE) ==
WAIT_OBJECT_0);
#else
pthread_join(thread, NULL);
#endif

View File

@ -134,15 +134,15 @@ isaac_init(rust_dom *dom, randctx *rctx)
#ifdef __WIN32__
{
HCRYPTPROV hProv;
dom->win32_require
dom->kernel->win32_require
(_T("CryptAcquireContext"),
CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT|CRYPT_SILENT));
dom->win32_require
dom->kernel->win32_require
(_T("CryptGenRandom"),
CryptGenRandom(hProv, sizeof(rctx->randrsl),
(BYTE*)(&rctx->randrsl)));
dom->win32_require
dom->kernel->win32_require
(_T("CryptReleaseContext"),
CryptReleaseContext(hProv, 0));
}