Changeset 57905 in vbox for trunk/src/VBox/Runtime/r3/win/vcc100-kernel32-fakes.cpp
- Timestamp:
- Sep 25, 2015 8:39:56 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/win/vcc100-kernel32-fakes.cpp
r57865 r57905 31 31 #include <iprt/cdefs.h> 32 32 #include <iprt/types.h> 33 #include <iprt/asm.h> 34 #include <iprt/string.h> 33 35 34 36 #ifndef RT_ARCH_X86 … … 41 43 #define HeapSetInformation Ignore_HeapSetInformation 42 44 #define HeapQueryInformation Ignore_HeapQueryInformation 45 #define CreateTimerQueue Ignore_CreateTimerQueue 46 #define CreateTimerQueueTimer Ignore_CreateTimerQueueTimer 47 #define DeleteTimerQueueTimer Ignore_DeleteTimerQueueTimer 48 #define InitializeSListHead Ignore_InitializeSListHead 49 #define InterlockedFlushSList Ignore_InterlockedFlushSList 50 #define InterlockedPopEntrySList Ignore_InterlockedPopEntrySList 51 #define InterlockedPushEntrySList Ignore_InterlockedPushEntrySList 52 #define QueryDepthSList Ignore_QueryDepthSList 53 #define VerifyVersionInfoA Ignore_VerifyVersionInfoA 54 #define VerSetConditionMask Ignore_VerSetConditionMask 55 43 56 #include <Windows.h> 57 44 58 #undef DecodePointer 45 59 #undef EncodePointer … … 47 61 #undef HeapSetInformation 48 62 #undef HeapQueryInformation 63 #undef CreateTimerQueue 64 #undef CreateTimerQueueTimer 65 #undef DeleteTimerQueueTimer 66 #undef InitializeSListHead 67 #undef InterlockedFlushSList 68 #undef InterlockedPopEntrySList 69 #undef InterlockedPushEntrySList 70 #undef QueryDepthSList 71 #undef VerifyVersionInfoA 72 #undef VerSetConditionMask 49 73 50 74 … … 54 78 55 79 56 /** @todo Try dynamically resolve the functions the first time one of them is 57 * called. */ 80 /** Dynamically resolves an kernel32 API. */ 81 #define RESOLVE_ME(ApiNm) \ 82 static bool volatile s_fInitialized = false; \ 83 static decltype(ApiNm) *s_pfnApi = NULL; \ 84 decltype(ApiNm) *pfnApi; \ 85 if (!s_fInitialized) \ 86 pfnApi = s_pfnApi; \ 87 else \ 88 { \ 89 pfnApi = (decltype(pfnApi))GetProcAddress(GetModuleHandleW(L"kernel32"), #ApiNm); \ 90 s_pfnApi = pfnApi; \ 91 s_fInitialized = true; \ 92 } do {} while (0) \ 93 58 94 59 95 extern "C" … … 61 97 DecodePointer(PVOID pvEncoded) 62 98 { 99 RESOLVE_ME(DecodePointer); 100 if (pfnApi) 101 return pfnApi(pvEncoded); 102 63 103 /* 64 104 * Fallback code. … … 72 112 EncodePointer(PVOID pvNative) 73 113 { 114 RESOLVE_ME(EncodePointer); 115 if (pfnApi) 116 return pfnApi(pvNative); 117 74 118 /* 75 119 * Fallback code. … … 83 127 InitializeCriticalSectionAndSpinCount(LPCRITICAL_SECTION pCritSect, DWORD cSpin) 84 128 { 129 RESOLVE_ME(InitializeCriticalSectionAndSpinCount); 130 if (pfnApi) 131 return pfnApi(pCritSect, cSpin); 85 132 86 133 /* … … 96 143 HeapSetInformation(HANDLE hHeap, HEAP_INFORMATION_CLASS enmInfoClass, PVOID pvBuf, SIZE_T cbBuf) 97 144 { 145 RESOLVE_ME(HeapSetInformation); 146 if (pfnApi) 147 return pfnApi(hHeap, enmInfoClass, pvBuf, cbBuf); 148 98 149 /* 99 150 * Fallback code. … … 121 172 HeapQueryInformation(HANDLE hHeap, HEAP_INFORMATION_CLASS enmInfoClass, PVOID pvBuf, SIZE_T cbBuf, PSIZE_T pcbRet) 122 173 { 174 RESOLVE_ME(HeapQueryInformation); 175 if (pfnApi) 176 return pfnApi(hHeap, enmInfoClass, pvBuf, cbBuf, pcbRet); 123 177 124 178 /* … … 142 196 143 197 198 /* These are used by INTEL\mt_obj\Timer.obj: */ 199 200 extern "C" 201 __declspec(dllexport) 202 HANDLE WINAPI CreateTimerQueue(void) 203 { 204 RESOLVE_ME(CreateTimerQueue); 205 if (pfnApi) 206 return pfnApi(); 207 SetLastError(ERROR_NOT_SUPPORTED); 208 return NULL; 209 } 210 211 extern "C" 212 __declspec(dllexport) 213 BOOL WINAPI CreateTimerQueueTimer(PHANDLE phTimer, HANDLE hTimerQueue, WAITORTIMERCALLBACK pfnCallback, PVOID pvUser, 214 DWORD msDueTime, DWORD msPeriod, ULONG fFlags) 215 { 216 RESOLVE_ME(CreateTimerQueueTimer); 217 if (pfnApi) 218 return pfnApi(phTimer, hTimerQueue, pfnCallback, pvUser, msDueTime, msPeriod, fFlags); 219 SetLastError(ERROR_NOT_SUPPORTED); 220 return FALSE; 221 } 222 223 extern "C" 224 __declspec(dllexport) 225 BOOL WINAPI DeleteTimerQueueTimer(HANDLE hTimerQueue, HANDLE hTimer, HANDLE hEvtCompletion) 226 { 227 RESOLVE_ME(DeleteTimerQueueTimer); 228 if (pfnApi) 229 return pfnApi(hTimerQueue, hTimer, hEvtCompletion); 230 SetLastError(ERROR_NOT_SUPPORTED); 231 return FALSE; 232 } 233 234 /* This is used by several APIs. */ 235 236 extern "C" 237 __declspec(dllexport) 238 VOID WINAPI InitializeSListHead(PSLIST_HEADER pHead) 239 { 240 RESOLVE_ME(InitializeSListHead); 241 if (pfnApi) 242 pfnApi(pHead); 243 else /* fallback: */ 244 pHead->Alignment = 0; 245 } 246 247 248 extern "C" 249 __declspec(dllexport) 250 PSLIST_ENTRY WINAPI InterlockedFlushSList(PSLIST_HEADER pHead) 251 { 252 RESOLVE_ME(InterlockedFlushSList); 253 if (pfnApi) 254 return pfnApi(pHead); 255 256 /* fallback: */ 257 PSLIST_ENTRY pRet = NULL; 258 if (pHead->Next.Next) 259 { 260 for (;;) 261 { 262 SLIST_HEADER OldHead = *pHead; 263 SLIST_HEADER NewHead; 264 NewHead.Alignment = 0; 265 NewHead.Sequence = OldHead.Sequence + 1; 266 if (ASMAtomicCmpXchgU64(&pHead->Alignment, NewHead.Alignment, OldHead.Alignment)) 267 { 268 pRet = OldHead.Next.Next; 269 break; 270 } 271 } 272 } 273 return pRet; 274 } 275 276 extern "C" 277 __declspec(dllexport) 278 PSLIST_ENTRY WINAPI InterlockedPopEntrySList(PSLIST_HEADER pHead) 279 { 280 RESOLVE_ME(InterlockedPopEntrySList); 281 if (pfnApi) 282 return pfnApi(pHead); 283 284 /* fallback: */ 285 PSLIST_ENTRY pRet = NULL; 286 for (;;) 287 { 288 SLIST_HEADER OldHead = *pHead; 289 pRet = OldHead.Next.Next; 290 if (pRet) 291 { 292 SLIST_HEADER NewHead; 293 __try 294 { 295 NewHead.Next.Next = pRet->Next; 296 } 297 __except(EXCEPTION_EXECUTE_HANDLER) 298 { 299 continue; 300 } 301 NewHead.Depth = OldHead.Depth - 1; 302 NewHead.Sequence = OldHead.Sequence + 1; 303 if (ASMAtomicCmpXchgU64(&pHead->Alignment, NewHead.Alignment, OldHead.Alignment)) 304 break; 305 } 306 else 307 break; 308 } 309 return pRet; 310 } 311 312 extern "C" 313 __declspec(dllexport) 314 PSLIST_ENTRY WINAPI InterlockedPushEntrySList(PSLIST_HEADER pHead, PSLIST_ENTRY pEntry) 315 { 316 RESOLVE_ME(InterlockedPushEntrySList); 317 if (pfnApi) 318 return pfnApi(pHead, pEntry); 319 320 /* fallback: */ 321 PSLIST_ENTRY pRet = NULL; 322 for (;;) 323 { 324 SLIST_HEADER OldHead = *pHead; 325 pRet = OldHead.Next.Next; 326 pEntry->Next = pRet; 327 SLIST_HEADER NewHead; 328 NewHead.Next.Next = pEntry; 329 NewHead.Depth = OldHead.Depth + 1; 330 NewHead.Sequence = OldHead.Sequence + 1; 331 if (ASMAtomicCmpXchgU64(&pHead->Alignment, NewHead.Alignment, OldHead.Alignment)) 332 break; 333 } 334 return pRet; 335 } 336 337 extern "C" 338 __declspec(dllexport) 339 WORD WINAPI QueryDepthSList(PSLIST_HEADER pHead) 340 { 341 RESOLVE_ME(QueryDepthSList); 342 if (pfnApi) 343 return pfnApi(pHead); 344 return pHead->Depth; 345 } 346 347 348 /* curl drags these in: */ 349 extern "C" 350 __declspec(dllexport) 351 BOOL WINAPI VerifyVersionInfoA(LPOSVERSIONINFOEXA pInfo, DWORD fTypeMask, DWORDLONG fConditionMask) 352 { 353 RESOLVE_ME(VerifyVersionInfoA); 354 if (pfnApi) 355 return pfnApi(pInfo, fTypeMask, fConditionMask); 356 357 /* fallback to make curl happy: */ 358 OSVERSIONINFOEXA VerInfo; 359 RT_ZERO(VerInfo); 360 VerInfo.dwOSVersionInfoSize = sizeof(VerInfo); 361 if (!GetVersionEx((OSVERSIONINFO *)&VerInfo)) 362 { 363 RT_ZERO(VerInfo); 364 VerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 365 AssertReturn(GetVersionEx((OSVERSIONINFO *)&VerInfo), FALSE); 366 } 367 368 BOOL fRet = TRUE; 369 for (unsigned i = 0; i < 8 && fRet; i++) 370 if (fTypeMask & RT_BIT_32(i)) 371 { 372 uint32_t uLeft, uRight; 373 switch (RT_BIT_32(i)) 374 { 375 #define MY_CASE(a_Num, a_Member) case a_Num: uLeft = VerInfo.a_Member; uRight = pInfo->a_Member; break 376 MY_CASE(VER_MINORVERSION, dwMinorVersion); 377 MY_CASE(VER_MAJORVERSION, dwMajorVersion); 378 MY_CASE(VER_BUILDNUMBER, dwBuildNumber); 379 MY_CASE(VER_PLATFORMID, dwPlatformId); 380 MY_CASE(VER_SERVICEPACKMINOR, wServicePackMinor); 381 MY_CASE(VER_SERVICEPACKMAJOR, wServicePackMinor); 382 MY_CASE(VER_SUITENAME, wSuiteMask); 383 MY_CASE(VER_PRODUCT_TYPE, wProductType); 384 #undef MY_CASE 385 default: uLeft = uRight = 0; AssertFailed(); 386 } 387 switch ((uint8_t)(fConditionMask >> (i*8))) 388 { 389 case VER_EQUAL: fRet = uLeft == uRight; break; 390 case VER_GREATER: fRet = uLeft > uRight; break; 391 case VER_GREATER_EQUAL: fRet = uLeft >= uRight; break; 392 case VER_LESS: fRet = uLeft < uRight; break; 393 case VER_LESS_EQUAL: fRet = uLeft <= uRight; break; 394 case VER_AND: fRet = (uLeft & uRight) == uRight; break; 395 case VER_OR: fRet = (uLeft & uRight) != 0; break; 396 default: fRet = FALSE; AssertFailed(); break; 397 } 398 } 399 400 return fRet; 401 } 402 403 extern "C" 404 __declspec(dllexport) 405 ULONGLONG WINAPI VerSetConditionMask(ULONGLONG fConditionMask, DWORD fTypeMask, BYTE bOperator) 406 { 407 RESOLVE_ME(VerSetConditionMask); 408 if (pfnApi) 409 return pfnApi(fConditionMask, fTypeMask, bOperator); 410 411 /* fallback: */ 412 for (unsigned i = 0; i < 8; i++) 413 if (fTypeMask & RT_BIT_32(i)) 414 { 415 uint64_t fMask = 0xff << (i*8); 416 fConditionMask &= ~fMask; 417 fConditionMask |= (uint64_t)bOperator << (i*8); 418 419 } 420 return fConditionMask; 421 } 422 423 424 425 /* Dummy to force dragging in this object in the link, so the linker 426 won't accidentally use the symbols from kernel32. */ 144 427 extern "C" int vcc100_kernel32_fakes_cpp(void) 145 428 {
Note:
See TracChangeset
for help on using the changeset viewer.