]> gitweb.factorcode.org Git - factor.git/blob - vm/os-windows-nt.cpp
535e7b8640c5ec674ffd87f4c6b09272d4a6c400
[factor.git] / vm / os-windows-nt.cpp
1 #include "master.hpp"
2
3 namespace factor
4 {
5
6 s64 factorvm::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         switch (e->ExceptionCode)
25         {
26         case EXCEPTION_ACCESS_VIOLATION:
27                 signal_fault_addr = e->ExceptionInformation[1];
28                 c->EIP = (cell)memory_signal_handler_impl;
29         break;
30
31         case STATUS_FLOAT_DENORMAL_OPERAND:
32         case STATUS_FLOAT_DIVIDE_BY_ZERO:
33         case STATUS_FLOAT_INEXACT_RESULT:
34         case STATUS_FLOAT_INVALID_OPERATION:
35         case STATUS_FLOAT_OVERFLOW:
36         case STATUS_FLOAT_STACK_CHECK:
37         case STATUS_FLOAT_UNDERFLOW:
38         case STATUS_FLOAT_MULTIPLE_FAULTS:
39         case STATUS_FLOAT_MULTIPLE_TRAPS:
40                 signal_fpu_status = fpu_status(X87SW(c) | MXCSR(c));
41                 X87SW(c) = 0;
42                 MXCSR(c) &= 0xffffffc0;
43                 c->EIP = (cell)fp_signal_handler_impl;
44                 break;
45         case 0x40010006:
46                 /* If the Widcomm bluetooth stack is installed, the BTTray.exe
47                 process injects code into running programs. For some reason this
48                 results in random SEH exceptions with this (undocumented)
49                 exception code being raised. The workaround seems to be ignoring
50                 this altogether, since that is what happens if SEH is not
51                 enabled. Don't really have any idea what this exception means. */
52                 break;
53         default:
54                 signal_number = e->ExceptionCode;
55                 c->EIP = (cell)misc_signal_handler_impl;
56                 break;
57         }
58         return EXCEPTION_CONTINUE_EXECUTION;
59 }
60
61 void factorvm::c_to_factor_toplevel(cell quot)
62 {
63         if(!AddVectoredExceptionHandler(0, (PVECTORED_EXCEPTION_HANDLER)exception_handler))
64                 fatal_error("AddVectoredExceptionHandler failed", 0);
65         c_to_factor(quot,this);
66         RemoveVectoredExceptionHandler((void *)exception_handler);
67 }
68
69 void factorvm::open_console()
70 {
71 }
72
73 }