]> gitweb.factorcode.org Git - factor.git/blob - vm/os-windows.hpp
70e05d00def6583a774daca3db2d8452fb39fa6d
[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
29 typedef wchar_t vm_char;
30 typedef char symbol_char;
31 typedef HANDLE THREADHANDLE;
32
33 #define STRING_LITERAL(string) L##string
34
35 #define MAX_UNICODE_PATH 32768
36 #define VM_C_API extern "C" __declspec(dllexport)
37 #define SSCANF swscanf
38 #define STRCMP wcscmp
39 #define STRNCMP wcsncmp
40 #define STRDUP _wcsdup
41
42 #ifdef _MSC_VER
43         #define FTELL ftell
44         #define FSEEK fseek
45         #define SNPRINTF _snprintf
46 #else
47         #define FTELL ftello64
48         #define FSEEK fseeko64
49         #define SNPRINTF snprintf
50 #endif
51
52 #define FACTOR_OS_STRING "winnt"
53
54 #define FACTOR_DLL NULL
55
56 // SSE traps raise these exception codes, which are defined in internal NT headers
57 // but not winbase.h
58 #ifndef STATUS_FLOAT_MULTIPLE_FAULTS
59 #define STATUS_FLOAT_MULTIPLE_FAULTS 0xC00002B4
60 #endif
61
62 #ifndef STATUS_FLOAT_MULTIPLE_TRAPS
63 #define STATUS_FLOAT_MULTIPLE_TRAPS  0xC00002B5
64 #endif
65
66 #define OPEN_READ(path) _wfopen((path),L"rb")
67 #define OPEN_WRITE(path) _wfopen((path),L"wb")
68
69 inline static void early_init() {}
70 u64 nano_count();
71 void sleep_nanos(u64 nsec);
72 long getpagesize();
73 void move_file(const vm_char *path1, const vm_char *path2);
74 VM_C_API LONG exception_handler(PEXCEPTION_RECORD e, void *frame, PCONTEXT c, void *dispatch);
75 THREADHANDLE start_thread(void *(*start_routine)(void *),void *args);
76 inline static THREADHANDLE thread_id() { return GetCurrentThread(); }
77
78 #define CODE_TO_FUNCTION_POINTER(code) (void)0
79 #define CODE_TO_FUNCTION_POINTER_CALLBACK(vm, code) (void)0
80 #define FUNCTION_CODE_POINTER(ptr) ptr
81 #define FUNCTION_TOC_POINTER(ptr) ptr
82 }