]> gitweb.factorcode.org Git - factor.git/blob - vm/os-windows-nt.cpp
misc small documentation fixes, some fixes for factor.vim, changed permissions of...
[factor.git] / vm / os-windows-nt.cpp
1 #include "master.hpp"
2
3 namespace factor
4 {
5
6 s64 current_micros()
7 {
8         FILETIME t;
9         GetSystemTimeAsFileTime(&t);
10         return (((s64)t.dwLowDateTime | (s64)t.dwHighDateTime<<32)
11                 - EPOCH_OFFSET) / 10;
12 }
13
14 FACTOR_STDCALL LONG exception_handler(PEXCEPTION_POINTERS pe)
15 {
16         PEXCEPTION_RECORD e = (PEXCEPTION_RECORD)pe->ExceptionRecord;
17         CONTEXT *c = (CONTEXT*)pe->ContextRecord;
18
19         if(in_code_heap_p(c->EIP))
20                 signal_callstack_top = (stack_frame *)c->ESP;
21         else
22                 signal_callstack_top = NULL;
23
24         if(e->ExceptionCode == EXCEPTION_ACCESS_VIOLATION)
25         {
26                 signal_fault_addr = e->ExceptionInformation[1];
27                 c->EIP = (cell)memory_signal_handler_impl;
28         }
29         /* If the Widcomm bluetooth stack is installed, the BTTray.exe process
30         injects code into running programs. For some reason this results in
31         random SEH exceptions with this (undocumented) exception code being
32         raised. The workaround seems to be ignoring this altogether, since that
33         is what happens if SEH is not enabled. Don't really have any idea what
34         this exception means. */
35         else if(e->ExceptionCode != 0x40010006)
36         {
37                 signal_number = e->ExceptionCode;
38                 c->EIP = (cell)misc_signal_handler_impl;
39         }
40
41         return EXCEPTION_CONTINUE_EXECUTION;
42 }
43
44 void c_to_factor_toplevel(cell quot)
45 {
46         if(!AddVectoredExceptionHandler(0, (PVECTORED_EXCEPTION_HANDLER)exception_handler))
47                 fatal_error("AddVectoredExceptionHandler failed", 0);
48         c_to_factor(quot);
49         RemoveVectoredExceptionHandler((void *)exception_handler);
50 }
51
52 void open_console()
53 {
54 }
55
56 }