make asn1 work again
[factor/jcg.git] / vm / os-windows-nt.c
blobf982abfb1b94c295c510a88f5b4b971dc0cb43c2
1 #include "master.h"
3 s64 current_micros(void)
5 FILETIME t;
6 GetSystemTimeAsFileTime(&t);
7 return (((s64)t.dwLowDateTime | (s64)t.dwHighDateTime<<32)
8 - EPOCH_OFFSET) / 10;
11 long exception_handler(PEXCEPTION_POINTERS pe)
13 PEXCEPTION_RECORD e = (PEXCEPTION_RECORD)pe->ExceptionRecord;
14 CONTEXT *c = (CONTEXT*)pe->ContextRecord;
16 if(in_code_heap_p(c->EIP))
17 signal_callstack_top = (void *)c->ESP;
18 else
19 signal_callstack_top = NULL;
21 if(e->ExceptionCode == EXCEPTION_ACCESS_VIOLATION)
23 signal_fault_addr = e->ExceptionInformation[1];
24 c->EIP = (CELL)memory_signal_handler_impl;
26 else if(e->ExceptionCode == EXCEPTION_FLT_DIVIDE_BY_ZERO
27 || e->ExceptionCode == EXCEPTION_INT_DIVIDE_BY_ZERO)
29 signal_number = ERROR_DIVIDE_BY_ZERO;
30 c->EIP = (CELL)divide_by_zero_signal_handler_impl;
32 /* If the Widcomm bluetooth stack is installed, the BTTray.exe process
33 injects code into running programs. For some reason this results in
34 random SEH exceptions with this (undocumented) exception code being
35 raised. The workaround seems to be ignoring this altogether, since that
36 is what happens if SEH is not enabled. Don't really have any idea what
37 this exception means. */
38 else if(e->ExceptionCode != 0x40010006)
40 signal_number = 11;
41 c->EIP = (CELL)misc_signal_handler_impl;
44 return EXCEPTION_CONTINUE_EXECUTION;
47 void c_to_factor_toplevel(CELL quot)
49 if(!AddVectoredExceptionHandler(0, (void*)exception_handler))
50 fatal_error("AddVectoredExceptionHandler failed", 0);
51 c_to_factor(quot);
52 RemoveVectoredExceptionHandler((void*)exception_handler);
55 void open_console(void)
58 // Do this: http://www.cygwin.com/ml/cygwin/2007-11/msg00432.html
59 if(console_open)
60 return;
62 if(AttachConsole(ATTACH_PARENT_PROCESS) || AllocConsole())
64 console_open = true;