]> gitweb.factorcode.org Git - factor.git/blob - vm/os-windows-nt.c
Merge branch 'master' into experimental
[factor.git] / vm / os-windows-nt.c
1 #include "master.h"
2
3 s64 current_micros(void)
4 {
5         FILETIME t;
6         GetSystemTimeAsFileTime(&t);
7         return (((s64)t.dwLowDateTime | (s64)t.dwHighDateTime<<32)
8                 - EPOCH_OFFSET) / 10;
9 }
10
11 long exception_handler(PEXCEPTION_POINTERS pe)
12 {
13         PEXCEPTION_RECORD e = (PEXCEPTION_RECORD)pe->ExceptionRecord;
14         CONTEXT *c = (CONTEXT*)pe->ContextRecord;
15
16         if(in_code_heap_p(c->EIP))
17                 signal_callstack_top = (void *)c->ESP;
18         else
19                 signal_callstack_top = NULL;
20
21         if(e->ExceptionCode == EXCEPTION_ACCESS_VIOLATION)
22         {
23                 signal_fault_addr = e->ExceptionInformation[1];
24                 c->EIP = (CELL)memory_signal_handler_impl;
25         }
26         else if(e->ExceptionCode == EXCEPTION_FLT_DIVIDE_BY_ZERO
27                         || e->ExceptionCode == EXCEPTION_INT_DIVIDE_BY_ZERO)
28         {
29                 signal_number = ERROR_DIVIDE_BY_ZERO;
30                 c->EIP = (CELL)divide_by_zero_signal_handler_impl;
31         }
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)
39         {
40                 signal_number = 11;
41                 c->EIP = (CELL)misc_signal_handler_impl;
42         }
43
44         return EXCEPTION_CONTINUE_EXECUTION;
45 }
46
47 void c_to_factor_toplevel(CELL quot)
48 {
49         if(!AddVectoredExceptionHandler(0, (void*)exception_handler))
50                 fatal_error("AddVectoredExceptionHandler failed", 0);
51         c_to_factor(quot);
52         RemoveVectoredExceptionHandler((void*)exception_handler);
53 }
54
55 void open_console(void)
56 {
57 }