2007-09-20 18:09:08 -04:00
|
|
|
#include "master.h"
|
|
|
|
|
2008-11-19 02:50:05 -05:00
|
|
|
s64 current_micros(void)
|
2007-09-20 18:09:08 -04:00
|
|
|
{
|
|
|
|
FILETIME t;
|
|
|
|
GetSystemTimeAsFileTime(&t);
|
|
|
|
return (((s64)t.dwLowDateTime | (s64)t.dwHighDateTime<<32)
|
2008-11-19 02:50:05 -05:00
|
|
|
- EPOCH_OFFSET) / 10;
|
2007-09-20 18:09:08 -04:00
|
|
|
}
|
|
|
|
|
2007-09-25 04:37:45 -04:00
|
|
|
long exception_handler(PEXCEPTION_POINTERS pe)
|
2007-09-20 18:09:08 -04:00
|
|
|
{
|
2007-09-25 04:37:45 -04:00
|
|
|
PEXCEPTION_RECORD e = (PEXCEPTION_RECORD)pe->ExceptionRecord;
|
|
|
|
CONTEXT *c = (CONTEXT*)pe->ContextRecord;
|
|
|
|
|
2008-02-04 12:45:53 -05:00
|
|
|
if(in_code_heap_p(c->EIP))
|
|
|
|
signal_callstack_top = (void *)c->ESP;
|
2007-09-27 16:10:37 -04:00
|
|
|
else
|
|
|
|
signal_callstack_top = NULL;
|
2007-09-25 04:37:45 -04:00
|
|
|
|
|
|
|
if(e->ExceptionCode == EXCEPTION_ACCESS_VIOLATION)
|
|
|
|
{
|
|
|
|
signal_fault_addr = e->ExceptionInformation[1];
|
2008-02-04 12:45:53 -05:00
|
|
|
c->EIP = (CELL)memory_signal_handler_impl;
|
2007-09-25 04:37:45 -04:00
|
|
|
}
|
|
|
|
else if(e->ExceptionCode == EXCEPTION_FLT_DIVIDE_BY_ZERO
|
|
|
|
|| e->ExceptionCode == EXCEPTION_INT_DIVIDE_BY_ZERO)
|
|
|
|
{
|
|
|
|
signal_number = ERROR_DIVIDE_BY_ZERO;
|
2008-02-04 12:45:53 -05:00
|
|
|
c->EIP = (CELL)divide_by_zero_signal_handler_impl;
|
2007-09-25 04:37:45 -04:00
|
|
|
}
|
2008-11-17 22:21:57 -05:00
|
|
|
/* If the Widcomm bluetooth stack is installed, the BTTray.exe process
|
|
|
|
injects code into running programs. For some reason this results in
|
|
|
|
random SEH exceptions with this (undocumented) exception code being
|
|
|
|
raised. The workaround seems to be ignoring this altogether, since that
|
|
|
|
is what happens if SEH is not enabled. Don't really have any idea what
|
|
|
|
this exception means. */
|
|
|
|
else if(e->ExceptionCode != 0x40010006)
|
2007-09-25 04:37:45 -04:00
|
|
|
{
|
|
|
|
signal_number = 11;
|
2008-02-04 12:45:53 -05:00
|
|
|
c->EIP = (CELL)misc_signal_handler_impl;
|
2007-09-25 04:37:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return EXCEPTION_CONTINUE_EXECUTION;
|
2007-09-20 18:09:08 -04:00
|
|
|
}
|
|
|
|
|
2007-09-24 00:52:58 -04:00
|
|
|
void c_to_factor_toplevel(CELL quot)
|
2007-09-20 18:09:08 -04:00
|
|
|
{
|
2007-12-12 02:29:41 -05:00
|
|
|
if(!AddVectoredExceptionHandler(0, (void*)exception_handler))
|
|
|
|
fatal_error("AddVectoredExceptionHandler failed", 0);
|
2007-09-24 00:52:58 -04:00
|
|
|
c_to_factor(quot);
|
2007-12-12 14:01:25 -05:00
|
|
|
RemoveVectoredExceptionHandler((void*)exception_handler);
|
2007-09-25 04:37:45 -04:00
|
|
|
}
|
2007-11-21 15:27:25 -05:00
|
|
|
|
|
|
|
void open_console(void)
|
|
|
|
{
|
|
|
|
}
|