| 1 |
/* |
| 2 |
* Copyright © Microsoft Corporation |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice (including the next |
| 12 |
* paragraph) shall be included in all copies or substantial portions of the |
| 13 |
* Software. |
| 14 |
* |
| 15 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 |
* IN THE SOFTWARE. |
| 22 |
*/ |
| 23 |
|
| 24 |
#ifndef _COMPAT_WIN32_H_ |
| 25 |
#define _COMPAT_WIN32_H_ |
| 26 |
|
| 27 |
#include <windows.h> |
| 28 |
#include <winsock.h> |
| 29 |
#include <io.h> |
| 30 |
#include <time.h> |
| 31 |
|
| 32 |
// Include stdlib.h here to make sure we |
| 33 |
// always replace MSVC getenv definition |
| 34 |
// with the macro / _getenv inline below |
| 35 |
#include <stdlib.h> |
| 36 |
|
| 37 |
#ifdef __cplusplus |
| 38 |
extern "C" { |
| 39 |
#endif |
| 40 |
|
| 41 |
#define F_OK 0 |
| 42 |
#define RTLD_NOW 0 |
| 43 |
#define RTLD_GLOBAL 0 |
| 44 |
|
| 45 |
#ifndef NTSTATUS |
| 46 |
typedef LONG NTSTATUS; |
| 47 |
#define STATUS_SUCCESS ((NTSTATUS)0x00000000L) |
| 48 |
#define STATUS_BUFFER_TOO_SMALL ((NTSTATUS)0xC0000023) |
| 49 |
#define NT_SUCCESS(status) (((NTSTATUS)(status)) >= 0) |
| 50 |
#endif |
| 51 |
|
| 52 |
typedef unsigned int __uid_t; |
| 53 |
|
| 54 |
#if _MSC_VER |
| 55 |
#define getenv _getenv |
| 56 |
#define secure_getenv _getenv |
| 57 |
#define HAVE_SECURE_GETENV |
| 58 |
inline char* _getenv(const char *varname) |
| 59 |
{ |
| 60 |
static char _getenv_buf[32767]; |
| 61 |
return GetEnvironmentVariableA(varname, &_getenv_buf[0], sizeof(_getenv_buf)) ? &_getenv_buf[0] : NULL; |
| 62 |
} |
| 63 |
#endif |
| 64 |
|
| 65 |
#ifdef _MSC_VER |
| 66 |
inline char* strtok_r(char *s, const char *delim, char **save_ptr) |
| 67 |
{ |
| 68 |
return strtok_s(s, delim, save_ptr); |
| 69 |
} |
| 70 |
#endif |
| 71 |
|
| 72 |
inline void* dlopen(const char *file, int mode) |
| 73 |
{ |
| 74 |
return LoadLibrary(file); |
| 75 |
} |
| 76 |
|
| 77 |
inline int dlclose(void *handle) |
| 78 |
{ |
| 79 |
return FreeLibrary(handle); |
| 80 |
} |
| 81 |
|
| 82 |
inline void *dlsym(void *handle, const char *name) |
| 83 |
{ |
| 84 |
return GetProcAddress(handle, name); |
| 85 |
} |
| 86 |
|
| 87 |
inline static char* dlerror() |
| 88 |
{ |
| 89 |
static char last_err_string[512]; |
| 90 |
memset(last_err_string, '\0', 512); |
| 91 |
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), |
| 92 |
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), last_err_string, (512 - 1), NULL); |
| 93 |
return last_err_string; |
| 94 |
} |
| 95 |
|
| 96 |
inline __uid_t geteuid() |
| 97 |
{ |
| 98 |
return 0; |
| 99 |
}; |
| 100 |
|
| 101 |
inline __uid_t getuid() |
| 102 |
{ |
| 103 |
return 0; |
| 104 |
}; |
| 105 |
|
| 106 |
typedef DWORD pid_t; |
| 107 |
typedef CRITICAL_SECTION pthread_mutex_t; |
| 108 |
|
| 109 |
inline void pthread_mutex_lock(pthread_mutex_t* a) |
| 110 |
{ |
| 111 |
EnterCriticalSection(a); |
| 112 |
} |
| 113 |
|
| 114 |
inline void pthread_mutex_unlock(pthread_mutex_t* a) |
| 115 |
{ |
| 116 |
LeaveCriticalSection(a); |
| 117 |
} |
| 118 |
|
| 119 |
inline void pthread_mutex_init(pthread_mutex_t* a, void* attr) |
| 120 |
{ |
| 121 |
InitializeCriticalSection(a); |
| 122 |
} |
| 123 |
|
| 124 |
inline void pthread_mutex_destroy(pthread_mutex_t* a) |
| 125 |
{ |
| 126 |
DeleteCriticalSection(a); |
| 127 |
} |
| 128 |
|
| 129 |
inline int gettimeofday(struct timeval *tv, struct timezone* tz) |
| 130 |
{ |
| 131 |
SYSTEMTIME st; |
| 132 |
GetSystemTime(&st); |
| 133 |
tv->tv_sec = st.wSecond; |
| 134 |
tv->tv_usec = st.wMilliseconds * 1000; /* milli to micro sec */ |
| 135 |
return 0; |
| 136 |
} |
| 137 |
|
| 138 |
#ifdef _MSC_VER |
| 139 |
#include <d3dkmthk.h> |
| 140 |
#include <d3dukmdt.h> |
| 141 |
#else |
| 142 |
// |
| 143 |
// DDI level handle that represents a kernel mode object (allocation, device, etc) |
| 144 |
// |
| 145 |
typedef UINT D3DKMT_HANDLE; |
| 146 |
|
| 147 |
typedef struct _D3DKMT_CLOSEADAPTER { |
| 148 |
D3DKMT_HANDLE hAdapter; // in: adapter handle |
| 149 |
} D3DKMT_CLOSEADAPTER; |
| 150 |
|
| 151 |
typedef struct _D3DKMT_OPENADAPTERFROMLUID { |
| 152 |
LUID AdapterLuid; |
| 153 |
D3DKMT_HANDLE hAdapter; |
| 154 |
} D3DKMT_OPENADAPTERFROMLUID; |
| 155 |
|
| 156 |
typedef enum _KMTQUERYADAPTERINFOTYPE { |
| 157 |
KMTQAITYPE_QUERYREGISTRY = 48, |
| 158 |
} KMTQUERYADAPTERINFOTYPE; |
| 159 |
|
| 160 |
typedef struct _D3DKMT_QUERYADAPTERINFO { |
| 161 |
D3DKMT_HANDLE hAdapter; |
| 162 |
KMTQUERYADAPTERINFOTYPE Type; |
| 163 |
VOID* pPrivateDriverData; |
| 164 |
UINT PrivateDriverDataSize; |
| 165 |
} D3DKMT_QUERYADAPTERINFO; |
| 166 |
|
| 167 |
typedef struct _D3DDDI_QUERYREGISTRY_FLAGS { |
| 168 |
union { |
| 169 |
struct { |
| 170 |
UINT TranslatePath : 1; |
| 171 |
UINT MutableValue : 1; |
| 172 |
UINT Reserved : 30; |
| 173 |
}; |
| 174 |
UINT Value; |
| 175 |
}; |
| 176 |
} D3DDDI_QUERYREGISTRY_FLAGS; |
| 177 |
|
| 178 |
typedef enum _D3DDDI_QUERYREGISTRY_TYPE { |
| 179 |
D3DDDI_QUERYREGISTRY_ADAPTERKEY = 1, |
| 180 |
} D3DDDI_QUERYREGISTRY_TYPE; |
| 181 |
|
| 182 |
typedef enum _D3DDDI_QUERYREGISTRY_STATUS { |
| 183 |
D3DDDI_QUERYREGISTRY_STATUS_SUCCESS = 0, |
| 184 |
D3DDDI_QUERYREGISTRY_STATUS_BUFFER_OVERFLOW = 1, |
| 185 |
} D3DDDI_QUERYREGISTRY_STATUS; |
| 186 |
|
| 187 |
typedef struct _D3DDDI_QUERYREGISTRY_INFO { |
| 188 |
D3DDDI_QUERYREGISTRY_TYPE QueryType; // In |
| 189 |
D3DDDI_QUERYREGISTRY_FLAGS QueryFlags; // In |
| 190 |
WCHAR ValueName[MAX_PATH]; // In |
| 191 |
ULONG ValueType; // In |
| 192 |
ULONG PhysicalAdapterIndex; // In |
| 193 |
ULONG OutputValueSize; // Out. Number of bytes written to the output value or required in case of D3DDDI_QUERYREGISTRY_STATUS_BUFFER_OVERFLOW. |
| 194 |
D3DDDI_QUERYREGISTRY_STATUS Status; // Out |
| 195 |
union { |
| 196 |
DWORD OutputDword; // Out |
| 197 |
UINT64 OutputQword; // Out |
| 198 |
WCHAR OutputString[1]; // Out. Dynamic array |
| 199 |
BYTE OutputBinary[1]; // Out. Dynamic array |
| 200 |
}; |
| 201 |
} D3DDDI_QUERYREGISTRY_INFO; |
| 202 |
|
| 203 |
typedef _Check_return_ NTSTATUS(APIENTRY *PFND3DKMT_CLOSEADAPTER)(_In_ CONST D3DKMT_CLOSEADAPTER*); |
| 204 |
typedef _Check_return_ NTSTATUS(APIENTRY *PFND3DKMT_OPENADAPTERFROMLUID)(_Inout_ D3DKMT_OPENADAPTERFROMLUID*); |
| 205 |
typedef _Check_return_ NTSTATUS(APIENTRY *PFND3DKMT_QUERYADAPTERINFO)(_Inout_ CONST D3DKMT_QUERYADAPTERINFO*); |
| 206 |
|
| 207 |
#endif |
| 208 |
|
| 209 |
#ifdef __cplusplus |
| 210 |
} |
| 211 |
#endif |
| 212 |
|
| 213 |
#endif /* _COMPAT_WIN32_H_ */ |