factor/vm/os-windows.hpp

96 lines
2.2 KiB
C++
Raw Permalink Normal View History

2009-05-02 05:04:19 -04:00
#include <ctype.h>
#ifndef wcslen
// for cygwin
2013-05-11 22:24:31 -04:00
#include <wchar.h>
2009-05-02 05:04:19 -04:00
#endif
#if _WIN32_WINNT != 0x0600
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0501 // For AddVectoredExceptionHandler, WinXP support
//#define _WIN32_WINNT 0x0600 // For CancelSynchronousIo
#endif
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
#include <shellapi.h>
#ifdef _MSC_VER
2013-05-11 22:24:31 -04:00
#undef min
#undef max
#endif
// Difference between Jan 1 00:00:00 1601 and Jan 1 00:00:00 1970
#define EPOCH_OFFSET 0x019db1ded53e8000LL
2013-05-11 22:24:31 -04:00
namespace factor {
2009-05-02 05:04:19 -04:00
2009-05-04 05:50:24 -04:00
typedef wchar_t vm_char;
typedef char symbol_char;
typedef HANDLE THREADHANDLE;
2009-05-02 05:04:19 -04:00
#define STRING_LITERAL(string) L##string
#define MAX_UNICODE_PATH 32768
#define VM_C_API extern "C" __declspec(dllexport)
2009-05-02 05:04:19 -04:00
#define SSCANF swscanf
#define STRCMP wcscmp
#define STRNCMP wcsncmp
#define STRDUP _wcsdup
#ifdef _MSC_VER
2013-05-11 22:24:31 -04:00
#define FTELL ftell
#define FSEEK fseek
#else
2013-05-11 22:24:31 -04:00
#define FTELL ftello64
#define FSEEK fseeko64
2009-05-02 05:04:19 -04:00
#endif
#define FACTOR_OS_STRING "windows"
// SSE traps raise these exception codes, which are defined in internal NT
// headers
// but not winbase.h
#ifndef STATUS_FLOAT_MULTIPLE_FAULTS
#define STATUS_FLOAT_MULTIPLE_FAULTS 0xC00002B4
#endif
#ifndef STATUS_FLOAT_MULTIPLE_TRAPS
2013-05-11 22:24:31 -04:00
#define STATUS_FLOAT_MULTIPLE_TRAPS 0xC00002B5
#endif
2013-05-11 22:24:31 -04:00
#define OPEN_READ(path) _wfopen((path), L"rb")
#define OPEN_WRITE(path) _wfopen((path), L"wb")
2014-07-05 21:58:24 -04:00
#define THREADSAFE_STRERROR(errnum, buf, buflen) strerror_s(buf, buflen, errnum)
2009-05-02 05:04:19 -04:00
2009-05-05 12:33:35 -04:00
inline static void early_init() {}
uint64_t nano_count();
void sleep_nanos(uint64_t nsec);
2009-09-26 03:41:01 -04:00
long getpagesize();
2013-05-11 22:24:31 -04:00
VM_C_API LONG exception_handler(PEXCEPTION_RECORD e, void* frame, PCONTEXT c,
void* dispatch);
THREADHANDLE start_thread(void* (*start_routine)(void*), void* args);
inline static THREADHANDLE thread_id() {
DWORD id = GetCurrentThreadId();
HANDLE threadHandle = OpenThread(
THREAD_GET_CONTEXT | THREAD_SET_CONTEXT | THREAD_SUSPEND_RESUME, FALSE,
id);
FACTOR_ASSERT(threadHandle != NULL);
return threadHandle;
}
2009-05-02 05:04:19 -04:00
2013-05-11 22:24:31 -04:00
inline static void breakpoint() { DebugBreak(); }
#define CODE_TO_FUNCTION_POINTER(code) (void)0
#define CODE_TO_FUNCTION_POINTER_CALLBACK(vm, code) (void)0
2011-05-20 18:11:50 -04:00
#define FUNCTION_CODE_POINTER(ptr) ptr
#define FUNCTION_TOC_POINTER(ptr) ptr
extern HANDLE boot_thread;
2014-07-04 06:00:08 -04:00
2009-05-04 02:46:13 -04:00
}