vm: get CtrlHandler working on windows
parent
6d57eb4f59
commit
ca0dfc5730
|
@ -34,7 +34,7 @@ void factor_vm::default_parameters(vm_parameters *p)
|
||||||
p->signals = true;
|
p->signals = true;
|
||||||
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
p->console = false;
|
p->console = GetConsoleWindow() != NULL;
|
||||||
#else
|
#else
|
||||||
p->console = true;
|
p->console = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -266,32 +266,46 @@ LONG factor_vm::exception_handler(PEXCEPTION_RECORD e, void *frame, PCONTEXT c,
|
||||||
|
|
||||||
VM_C_API LONG exception_handler(PEXCEPTION_RECORD e, void *frame, PCONTEXT c, void *dispatch)
|
VM_C_API LONG exception_handler(PEXCEPTION_RECORD e, void *frame, PCONTEXT c, void *dispatch)
|
||||||
{
|
{
|
||||||
return current_vm()->exception_handler(e,frame,c,dispatch);
|
factor_vm *vm = current_vm_p();
|
||||||
|
if (vm)
|
||||||
|
return vm->exception_handler(e,frame,c,dispatch);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fatal_error("Foreign thread received exception ", e->ExceptionCode);
|
||||||
|
return 0; // to placate MSVC
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL factor_vm::ctrl_handler(DWORD dwCtrlType)
|
static BOOL WINAPI ctrl_handler(DWORD dwCtrlType)
|
||||||
{
|
{
|
||||||
switch (dwCtrlType) {
|
switch (dwCtrlType) {
|
||||||
case CTRL_C_EVENT:
|
case CTRL_C_EVENT:
|
||||||
case CTRL_BREAK_EVENT:
|
case CTRL_BREAK_EVENT:
|
||||||
enqueue_safepoint_fep();
|
{
|
||||||
|
/* The CtrlHandler runs in its own thread without stopping the main thread.
|
||||||
|
Since in practice nobody uses the multi-VM stuff yet, we just grab the first
|
||||||
|
VM we can get. This will not be a good idea when we actually support native
|
||||||
|
threads. */
|
||||||
|
assert(thread_vms.size() == 1);
|
||||||
|
THREADHANDLE vm_thread = thread_vms.begin()->first;
|
||||||
|
factor_vm *vm = thread_vms.begin()->second;
|
||||||
|
|
||||||
|
assert(SuspendThread(vm_thread) == 0);
|
||||||
|
std::cout << "handling ctrl-c" << std::endl;
|
||||||
|
|
||||||
|
vm->enqueue_safepoint_fep();
|
||||||
|
MemoryBarrier();
|
||||||
|
assert(ResumeThread(vm_thread) == 1);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VM_C_API BOOL ctrl_handler(DWORD dwCtrlType)
|
|
||||||
{
|
|
||||||
factor_vm *vm = current_vm_p();
|
|
||||||
if (vm != NULL)
|
|
||||||
return vm->ctrl_handler(dwCtrlType);
|
|
||||||
else
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void factor_vm::open_console()
|
void factor_vm::open_console()
|
||||||
{
|
{
|
||||||
|
std::cout << "setting ctrl handler\n";
|
||||||
SetConsoleCtrlHandler(factor::ctrl_handler, TRUE);
|
SetConsoleCtrlHandler(factor::ctrl_handler, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -720,7 +720,6 @@ struct factor_vm
|
||||||
|
|
||||||
void open_console();
|
void open_console();
|
||||||
LONG exception_handler(PEXCEPTION_RECORD e, void *frame, PCONTEXT c, void *dispatch);
|
LONG exception_handler(PEXCEPTION_RECORD e, void *frame, PCONTEXT c, void *dispatch);
|
||||||
BOOL ctrl_handler(DWORD dwCtrlType);
|
|
||||||
|
|
||||||
#else // UNIX
|
#else // UNIX
|
||||||
void dispatch_signal(void *uap, void (handler)());
|
void dispatch_signal(void *uap, void (handler)());
|
||||||
|
|
Loading…
Reference in New Issue