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