]> gitweb.factorcode.org Git - factor.git/blob - vm/os-windows.hpp
Windows: Add two new targets, x86-32-vista and x86-64-vista for bjourne's
[factor.git] / vm / os-windows.hpp
1 #include <ctype.h>
2
3 #ifndef wcslen
4 /* for cygwin */
5 #include <wchar.h>
6 #endif
7
8 #if _WIN32_WINNT != 0x0600
9 #undef _WIN32_WINNT
10 #define _WIN32_WINNT 0x0501  // For AddVectoredExceptionHandler, WinXP support
11 //#define _WIN32_WINNT 0x0600  // For CancelSynchronousIo
12 #endif
13
14 #ifndef UNICODE
15 #define UNICODE
16 #endif
17
18 #include <windows.h>
19 #include <shellapi.h>
20
21 #ifdef _MSC_VER
22 #undef min
23 #undef max
24 #endif
25
26 /* Difference between Jan 1 00:00:00 1601 and Jan 1 00:00:00 1970 */
27 #define EPOCH_OFFSET 0x019db1ded53e8000LL
28
29 namespace factor {
30
31 typedef wchar_t vm_char;
32 typedef char symbol_char;
33 typedef HANDLE THREADHANDLE;
34
35 #define STRING_LITERAL(string) L##string
36
37 #define MAX_UNICODE_PATH 32768
38 #define VM_C_API extern "C" __declspec(dllexport)
39 #define SSCANF swscanf
40 #define STRCMP wcscmp
41 #define STRNCMP wcsncmp
42 #define STRDUP _wcsdup
43
44 #ifdef _MSC_VER
45 #define FTELL ftell
46 #define FSEEK fseek
47 #define SNPRINTF _snprintf
48 #else
49 #define FTELL ftello64
50 #define FSEEK fseeko64
51 #define SNPRINTF snprintf
52 #endif
53
54 #define FACTOR_OS_STRING "windows"
55
56 // SSE traps raise these exception codes, which are defined in internal NT
57 // headers
58 // but not winbase.h
59 #ifndef STATUS_FLOAT_MULTIPLE_FAULTS
60 #define STATUS_FLOAT_MULTIPLE_FAULTS 0xC00002B4
61 #endif
62
63 #ifndef STATUS_FLOAT_MULTIPLE_TRAPS
64 #define STATUS_FLOAT_MULTIPLE_TRAPS 0xC00002B5
65 #endif
66
67 #define OPEN_READ(path) _wfopen((path), L"rb")
68 #define OPEN_WRITE(path) _wfopen((path), L"wb")
69
70 inline static void early_init() {}
71 uint64_t nano_count();
72 void sleep_nanos(uint64_t nsec);
73 long getpagesize();
74 void move_file(const vm_char* path1, const vm_char* path2);
75 VM_C_API LONG exception_handler(PEXCEPTION_RECORD e, void* frame, PCONTEXT c,
76                                 void* dispatch);
77 THREADHANDLE start_thread(void* (*start_routine)(void*), void* args);
78
79 inline static THREADHANDLE thread_id() {
80   DWORD id = GetCurrentThreadId();
81   HANDLE threadHandle = OpenThread(
82       THREAD_GET_CONTEXT | THREAD_SET_CONTEXT | THREAD_SUSPEND_RESUME, FALSE,
83       id);
84   FACTOR_ASSERT(threadHandle != NULL);
85   return threadHandle;
86 }
87
88 inline static void breakpoint() { DebugBreak(); }
89
90 #define CODE_TO_FUNCTION_POINTER(code) (void)0
91 #define CODE_TO_FUNCTION_POINTER_CALLBACK(vm, code) (void)0
92 #define FUNCTION_CODE_POINTER(ptr) ptr
93 #define FUNCTION_TOC_POINTER(ptr) ptr
94
95 extern HANDLE boot_thread;
96 }