VirtualBox

Changeset 70375 in vbox


Ignore:
Timestamp:
Dec 28, 2017 8:46:21 PM (7 years ago)
Author:
vboxsync
Message:

iprt/vcc100-kernel32-fakes*: Redid the resolving to be more optimal for platforms that provides the APIs we fake, and also added version checks (in strict builds) that we're able to resolve the symbols.

Location:
trunk/src/VBox/Runtime/r3/win
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/win/vcc100-kernel32-fakes.cpp

    r70360 r70375  
    2929*   Header Files                                                                                                                 *
    3030*********************************************************************************************************************************/
    31 #define RT_NO_STRICT /* Minimal deps so that it works on NT 3.51 too. */
    3231#include <iprt/cdefs.h>
    3332#include <iprt/types.h>
     
    3534#include <iprt/assert.h>
    3635#include <iprt/string.h>
     36#ifdef DEBUG
     37# include <stdio.h> /* _snprintf */
     38#endif
    3739
    3840#ifndef RT_ARCH_X86
     
    4042#endif
    4143
    42 #define DecodePointer                           Ignore_DecodePointer
    43 #define EncodePointer                           Ignore_EncodePointer
    44 #define InitializeCriticalSectionAndSpinCount   Ignore_InitializeCriticalSectionAndSpinCount
    45 #define HeapSetInformation                      Ignore_HeapSetInformation
    46 #define HeapQueryInformation                    Ignore_HeapQueryInformation
    47 #define CreateTimerQueue                        Ignore_CreateTimerQueue
    48 #define CreateTimerQueueTimer                   Ignore_CreateTimerQueueTimer
    49 #define DeleteTimerQueueTimer                   Ignore_DeleteTimerQueueTimer
    50 #define InitializeSListHead                     Ignore_InitializeSListHead
    51 #define InterlockedFlushSList                   Ignore_InterlockedFlushSList
    52 #define InterlockedPopEntrySList                Ignore_InterlockedPopEntrySList
    53 #define InterlockedPushEntrySList               Ignore_InterlockedPushEntrySList
    54 #define QueryDepthSList                         Ignore_QueryDepthSList
    55 #define VerifyVersionInfoA                      Ignore_VerifyVersionInfoA
    56 #define VerSetConditionMask                     Ignore_VerSetConditionMask
    57 #define IsProcessorFeaturePresent               Ignore_IsProcessorFeaturePresent    /* NT 3.51 start */
    58 #define CancelIo                                Ignore_CancelIo
    59 #define IsDebuggerPresent                       Ignore_IsDebuggerPresent            /* NT 3.50 start */
    60 #define GetSystemTimeAsFileTime                 Ignore_GetSystemTimeAsFileTime
    61 #define GetVersionExA                           Ignore_GetVersionExA                /* NT 3.1 start */
    62 #define GetVersionExW                           Ignore_GetVersionExW
    63 #define GetEnvironmentStringsW                  Ignore_GetEnvironmentStringsW
    64 #define FreeEnvironmentStringsW                 Ignore_FreeEnvironmentStringsW
    65 #define GetLocaleInfoA                          Ignore_GetLocaleInfoA
    66 #define EnumSystemLocalesA                      Ignore_EnumSystemLocalesA
    67 #define IsValidLocale                           Ignore_IsValidLocale
    68 #define SetThreadAffinityMask                   Ignore_SetThreadAffinityMask
    69 #define GetProcessAffinityMask                  Ignore_GetProcessAffinityMask
    70 #define GetHandleInformation                    Ignore_GetHandleInformation
    71 #define SetHandleInformation                    Ignore_SetHandleInformation
    72 
    7344#include <iprt/nt/nt-and-windows.h>
    7445
    75 #undef DecodePointer
    76 #undef EncodePointer
    77 #undef InitializeCriticalSectionAndSpinCount
    78 #undef HeapSetInformation
    79 #undef HeapQueryInformation
    80 #undef CreateTimerQueue
    81 #undef CreateTimerQueueTimer
    82 #undef DeleteTimerQueueTimer
    83 #undef InitializeSListHead
    84 #undef InterlockedFlushSList
    85 #undef InterlockedPopEntrySList
    86 #undef InterlockedPushEntrySList
    87 #undef QueryDepthSList
    88 #undef VerifyVersionInfoA
    89 #undef VerSetConditionMask
    90 #undef IsProcessorFeaturePresent
    91 #undef CancelIo
    92 #undef IsDebuggerPresent
    93 #undef GetSystemTimeAsFileTime
    94 #undef GetVersionExA
    95 #undef GetVersionExW
    96 #undef GetEnvironmentStringsW
    97 #undef FreeEnvironmentStringsW
    98 #undef GetLocaleInfoA
    99 #undef EnumSystemLocalesA
    100 #undef IsValidLocale
    101 #undef SetThreadAffinityMask
    102 #undef GetProcessAffinityMask
    103 #undef GetHandleInformation
    104 #undef SetHandleInformation
     46#include "vcc100-fakes.h"
    10547
    10648
     
    11355
    11456
    115 /** Dynamically resolves an kernel32 API.   */
    116 #define RESOLVE_ME(ApiNm) \
    117     static bool volatile    s_fInitialized = false; \
    118     static decltype(ApiNm) *s_pfnApi = NULL; \
    119     decltype(ApiNm)        *pfnApi; \
    120     if (s_fInitialized) \
    121         pfnApi = s_pfnApi; \
    122     else \
    123     { \
    124         pfnApi = (decltype(pfnApi))GetProcAddress(GetModuleHandleW(L"kernel32"), #ApiNm); \
    125         s_pfnApi = pfnApi; \
    126         s_fInitialized = true; \
    127     } do {} while (0)
    128 
    129 
    130 /** Dynamically resolves an NTDLL API we need.   */
    131 #define RESOLVE_NTDLL_API(ApiNm) \
    132     static bool volatile    s_fInitialized##ApiNm = false; \
    133     static decltype(ApiNm) *s_pfn##ApiNm = NULL; \
    134     decltype(ApiNm)        *pfn##ApiNm; \
    135     if (s_fInitialized##ApiNm) \
    136         pfn##ApiNm = s_pfn##ApiNm; \
    137     else \
    138     { \
    139         pfn##ApiNm = (decltype(pfn##ApiNm))GetProcAddress(GetModuleHandleW(L"ntdll"), #ApiNm); \
    140         s_pfn##ApiNm = pfn##ApiNm; \
    141         s_fInitialized##ApiNm = true; \
    142     } do {} while (0)
    143 
    144 
    14557/** Declare a kernel32 API.
    14658 * @note We are not exporting them as that causes duplicate symbol troubles in
     
    14961
    15062
     63
    15164/*********************************************************************************************************************************
    152 *   Internal Functions                                                                                                           *
     65*   Global Variables                                                                                                             *
    15366*********************************************************************************************************************************/
    154 DECL_KERNEL32(BOOL) WINAPI GetVersionExA(LPOSVERSIONINFOA pInfo);
    155 
    156 
    157 DECL_KERNEL32(PVOID) DecodePointer(PVOID pvEncoded)
    158 {
    159     RESOLVE_ME(DecodePointer);
    160     if (pfnApi)
    161         return pfnApi(pvEncoded);
     67static volatile bool g_fInitialized = false;
     68#define MAKE_IMPORT_ENTRY(a_uMajorVer, a_uMinorVer, a_Name, a_cb) DECLARE_FUNCTION_POINTER(a_Name, a_cb)
     69#include "vcc100-kernel32-fakes.h"
     70
     71
     72/**
     73 * Resolves all the APIs ones and for all, updating the fake IAT entries.
     74 */
     75static void InitFakes(void)
     76{
     77    CURRENT_VERSION_VARIABLE();
     78
     79    HMODULE hmod = GetModuleHandleW(L"kernel32");
     80    MY_ASSERT(hmod != NULL, "kernel32");
     81
     82#undef MAKE_IMPORT_ENTRY
     83#define MAKE_IMPORT_ENTRY(a_uMajorVer, a_uMinorVer, a_Name, a_cb) RESOLVE_IMPORT(a_uMajorVer, a_uMinorVer, a_Name, a_cb)
     84#include "vcc100-kernel32-fakes.h"
     85
     86    g_fInitialized = true;
     87}
     88
     89
     90DECL_KERNEL32(PVOID) Fake_DecodePointer(PVOID pvEncoded)
     91{
     92    INIT_FAKES(DecodePointer,(pvEncoded));
    16293
    16394    /*
     
    16899
    169100
    170 DECL_KERNEL32(PVOID) EncodePointer(PVOID pvNative)
    171 {
    172     RESOLVE_ME(EncodePointer);
    173     if (pfnApi)
    174         return pfnApi(pvNative);
     101DECL_KERNEL32(PVOID) Fake_EncodePointer(PVOID pvNative)
     102{
     103    INIT_FAKES(EncodePointer, (pvNative));
    175104
    176105    /*
     
    181110
    182111
    183 DECL_KERNEL32(BOOL) InitializeCriticalSectionAndSpinCount(LPCRITICAL_SECTION pCritSect, DWORD cSpin)
    184 {
    185     RESOLVE_ME(InitializeCriticalSectionAndSpinCount);
    186     if (pfnApi)
    187         return pfnApi(pCritSect, cSpin);
     112DECL_KERNEL32(BOOL) Fake_InitializeCriticalSectionAndSpinCount(LPCRITICAL_SECTION pCritSect, DWORD cSpin)
     113{
     114    INIT_FAKES(InitializeCriticalSectionAndSpinCount, (pCritSect, cSpin));
    188115
    189116    /*
     
    195122
    196123
    197 DECL_KERNEL32(BOOL) HeapSetInformation(HANDLE hHeap, HEAP_INFORMATION_CLASS enmInfoClass, PVOID pvBuf, SIZE_T cbBuf)
    198 {
    199     RESOLVE_ME(HeapSetInformation);
    200     if (pfnApi)
    201         return pfnApi(hHeap, enmInfoClass, pvBuf, cbBuf);
     124DECL_KERNEL32(BOOL) Fake_HeapSetInformation(HANDLE hHeap, HEAP_INFORMATION_CLASS enmInfoClass, PVOID pvBuf, SIZE_T cbBuf)
     125{
     126    INIT_FAKES(HeapSetInformation, (hHeap, enmInfoClass, pvBuf, cbBuf));
    202127
    203128    /*
     
    222147
    223148
    224 DECL_KERNEL32(BOOL) HeapQueryInformation(HANDLE hHeap, HEAP_INFORMATION_CLASS enmInfoClass,
    225                                          PVOID pvBuf, SIZE_T cbBuf, PSIZE_T pcbRet)
    226 {
    227     RESOLVE_ME(HeapQueryInformation);
    228     if (pfnApi)
    229         return pfnApi(hHeap, enmInfoClass, pvBuf, cbBuf, pcbRet);
     149DECL_KERNEL32(BOOL) Fake_HeapQueryInformation(HANDLE hHeap, HEAP_INFORMATION_CLASS enmInfoClass,
     150                                              PVOID pvBuf, SIZE_T cbBuf, PSIZE_T pcbRet)
     151{
     152    INIT_FAKES(HeapQueryInformation, (hHeap, enmInfoClass, pvBuf, cbBuf, pcbRet));
    230153
    231154    /*
     
    251174/* These are used by INTEL\mt_obj\Timer.obj: */
    252175
    253 DECL_KERNEL32(HANDLE) CreateTimerQueue(void)
    254 {
    255     RESOLVE_ME(CreateTimerQueue);
    256     if (pfnApi)
    257         return pfnApi();
     176DECL_KERNEL32(HANDLE) Fake_CreateTimerQueue(void)
     177{
     178    INIT_FAKES(CreateTimerQueue, ());
     179
    258180    SetLastError(ERROR_NOT_SUPPORTED);
    259181    return NULL;
    260182}
    261183
    262 DECL_KERNEL32(BOOL) CreateTimerQueueTimer(PHANDLE phTimer, HANDLE hTimerQueue, WAITORTIMERCALLBACK pfnCallback, PVOID pvUser,
    263                                           DWORD msDueTime, DWORD msPeriod, ULONG fFlags)
    264 {
    265     RESOLVE_ME(CreateTimerQueueTimer);
    266     if (pfnApi)
    267         return pfnApi(phTimer, hTimerQueue, pfnCallback, pvUser, msDueTime, msPeriod, fFlags);
     184DECL_KERNEL32(BOOL) Fake_CreateTimerQueueTimer(PHANDLE phTimer, HANDLE hTimerQueue, WAITORTIMERCALLBACK pfnCallback, PVOID pvUser,
     185                                               DWORD msDueTime, DWORD msPeriod, ULONG fFlags)
     186{
     187    INIT_FAKES(CreateTimerQueueTimer, (phTimer, hTimerQueue, pfnCallback, pvUser, msDueTime, msPeriod, fFlags));
     188
    268189    SetLastError(ERROR_NOT_SUPPORTED);
    269190    return FALSE;
    270191}
    271192
    272 DECL_KERNEL32(BOOL) DeleteTimerQueueTimer(HANDLE hTimerQueue, HANDLE hTimer, HANDLE hEvtCompletion)
    273 {
    274     RESOLVE_ME(DeleteTimerQueueTimer);
    275     if (pfnApi)
    276         return pfnApi(hTimerQueue, hTimer, hEvtCompletion);
     193DECL_KERNEL32(BOOL) Fake_DeleteTimerQueueTimer(HANDLE hTimerQueue, HANDLE hTimer, HANDLE hEvtCompletion)
     194{
     195    INIT_FAKES(DeleteTimerQueueTimer, (hTimerQueue, hTimer, hEvtCompletion));
     196
    277197    SetLastError(ERROR_NOT_SUPPORTED);
    278198    return FALSE;
     
    281201/* This is used by several APIs. */
    282202
    283 DECL_KERNEL32(VOID) InitializeSListHead(PSLIST_HEADER pHead)
    284 {
    285     RESOLVE_ME(InitializeSListHead);
    286     if (pfnApi)
    287         pfnApi(pHead);
    288     else /* fallback: */
    289         pHead->Alignment = 0;
    290 }
    291 
    292 
    293 DECL_KERNEL32(PSLIST_ENTRY) InterlockedFlushSList(PSLIST_HEADER pHead)
    294 {
    295     RESOLVE_ME(InterlockedFlushSList);
    296     if (pfnApi)
    297         return pfnApi(pHead);
     203DECL_KERNEL32(VOID) Fake_InitializeSListHead(PSLIST_HEADER pHead)
     204{
     205    INIT_FAKES_VOID(InitializeSListHead, (pHead));
     206
     207    /* fallback: */
     208    pHead->Alignment = 0;
     209}
     210
     211
     212DECL_KERNEL32(PSLIST_ENTRY) Fake_InterlockedFlushSList(PSLIST_HEADER pHead)
     213{
     214    INIT_FAKES(InterlockedFlushSList, (pHead));
    298215
    299216    /* fallback: */
     
    317234}
    318235
    319 DECL_KERNEL32(PSLIST_ENTRY) InterlockedPopEntrySList(PSLIST_HEADER pHead)
    320 {
    321     RESOLVE_ME(InterlockedPopEntrySList);
    322     if (pfnApi)
    323         return pfnApi(pHead);
     236DECL_KERNEL32(PSLIST_ENTRY) Fake_InterlockedPopEntrySList(PSLIST_HEADER pHead)
     237{
     238    INIT_FAKES(InterlockedPopEntrySList, (pHead));
    324239
    325240    /* fallback: */
     
    351266}
    352267
    353 DECL_KERNEL32(PSLIST_ENTRY) InterlockedPushEntrySList(PSLIST_HEADER pHead, PSLIST_ENTRY pEntry)
    354 {
    355     RESOLVE_ME(InterlockedPushEntrySList);
    356     if (pfnApi)
    357         return pfnApi(pHead, pEntry);
     268DECL_KERNEL32(PSLIST_ENTRY) Fake_InterlockedPushEntrySList(PSLIST_HEADER pHead, PSLIST_ENTRY pEntry)
     269{
     270    INIT_FAKES(InterlockedPushEntrySList, (pHead, pEntry));
    358271
    359272    /* fallback: */
     
    374287}
    375288
    376 DECL_KERNEL32(WORD) QueryDepthSList(PSLIST_HEADER pHead)
    377 {
    378     RESOLVE_ME(QueryDepthSList);
    379     if (pfnApi)
    380         return pfnApi(pHead);
     289DECL_KERNEL32(WORD) Fake_QueryDepthSList(PSLIST_HEADER pHead)
     290{
     291    INIT_FAKES(QueryDepthSList, (pHead));
     292
     293    /* fallback: */
    381294    return pHead->Depth;
    382295}
     
    384297
    385298/* curl drags these in: */
    386 DECL_KERNEL32(BOOL) VerifyVersionInfoA(LPOSVERSIONINFOEXA pInfo, DWORD fTypeMask, DWORDLONG fConditionMask)
    387 {
    388     RESOLVE_ME(VerifyVersionInfoA);
    389     if (pfnApi)
    390         return pfnApi(pInfo, fTypeMask, fConditionMask);
     299DECL_KERNEL32(BOOL) Fake_VerifyVersionInfoA(LPOSVERSIONINFOEXA pInfo, DWORD fTypeMask, DWORDLONG fConditionMask)
     300{
     301    INIT_FAKES(VerifyVersionInfoA, (pInfo, fTypeMask, fConditionMask));
    391302
    392303    /* fallback to make curl happy: */
     
    398309        RT_ZERO(VerInfo);
    399310        VerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    400         AssertReturn(GetVersionExA((OSVERSIONINFO *)&VerInfo), FALSE);
     311        BOOL fRet = GetVersionExA((OSVERSIONINFO *)&VerInfo);
     312        if (fRet)
     313        { /* likely */ }
     314        else
     315        {
     316            MY_ASSERT(false, "VerifyVersionInfoA: #1");
     317            return FALSE;
     318        }
    401319    }
    402320
     
    418336                MY_CASE(VER_PRODUCT_TYPE,       wProductType);
    419337#undef  MY_CASE
    420                 default: uLeft = uRight = 0; AssertFailed();
     338                default: uLeft = uRight = 0; MY_ASSERT(false, "VerifyVersionInfoA: #2");
    421339            }
    422340            switch ((uint8_t)(fConditionMask >> (i*8)))
     
    429347                case VER_AND:               fRet = (uLeft & uRight) == uRight; break;
    430348                case VER_OR:                fRet = (uLeft & uRight) != 0; break;
    431                 default:                    fRet = FALSE; AssertFailed(); break;
     349                default:                    fRet = FALSE; MY_ASSERT(false, "VerifyVersionInfoA: #3"); break;
    432350            }
    433351        }
     
    437355
    438356
    439 DECL_KERNEL32(ULONGLONG) VerSetConditionMask(ULONGLONG fConditionMask, DWORD fTypeMask, BYTE bOperator)
    440 {
    441     RESOLVE_ME(VerSetConditionMask);
    442     if (pfnApi)
    443         return pfnApi(fConditionMask, fTypeMask, bOperator);
     357DECL_KERNEL32(ULONGLONG) Fake_VerSetConditionMask(ULONGLONG fConditionMask, DWORD fTypeMask, BYTE bOperator)
     358{
     359    INIT_FAKES(VerSetConditionMask, (fConditionMask, fTypeMask, bOperator));
    444360
    445361    /* fallback: */
     
    460376 */
    461377
    462 DECL_KERNEL32(BOOL) IsProcessorFeaturePresent(DWORD enmProcessorFeature)
    463 {
    464     RESOLVE_ME(IsProcessorFeaturePresent);
    465     if (pfnApi)
    466         return pfnApi(enmProcessorFeature);
     378DECL_KERNEL32(BOOL) Fake_IsProcessorFeaturePresent(DWORD enmProcessorFeature)
     379{
     380    INIT_FAKES(IsProcessorFeaturePresent, (enmProcessorFeature));
    467381
    468382    /* Could make more of an effort here... */
     
    471385
    472386
    473 DECL_KERNEL32(BOOL) CancelIo(HANDLE hHandle)
    474 {
    475     RESOLVE_ME(CancelIo);
    476     if (pfnApi)
    477         return pfnApi(hHandle);
     387DECL_KERNEL32(BOOL) Fake_CancelIo(HANDLE hHandle)
     388{
     389    INIT_FAKES(CancelIo, (hHandle));
    478390
    479391    /* NT 3.51 have the NTDLL API this corresponds to. */
     
    500412 */
    501413
    502 DECL_KERNEL32(BOOL) IsDebuggerPresent(VOID)
    503 {
    504     RESOLVE_ME(IsDebuggerPresent);
    505     if (pfnApi)
    506         return pfnApi();
    507     return FALSE;
    508 }
    509 
    510 
    511 DECL_KERNEL32(VOID) GetSystemTimeAsFileTime(LPFILETIME pTime)
    512 {
    513     RESOLVE_ME(GetSystemTimeAsFileTime);
    514     if (pfnApi)
    515         pfnApi(pTime);
     414DECL_KERNEL32(BOOL) Fake_IsDebuggerPresent(VOID)
     415{
     416    INIT_FAKES(IsDebuggerPresent, ());
     417
     418    /* Fallback: */
     419    return FALSE;
     420}
     421
     422
     423DECL_KERNEL32(VOID) Fake_GetSystemTimeAsFileTime(LPFILETIME pTime)
     424{
     425    INIT_FAKES_VOID(GetSystemTimeAsFileTime, (pTime));
     426
     427    DWORD dwVersion = GetVersion();
     428    if (   (dwVersion & 0xff) > 3
     429        || (   (dwVersion & 0xff) == 3
     430            && ((dwVersion >> 8) & 0xff) >= 50) )
     431    {
     432        PKUSER_SHARED_DATA pUsd = (PKUSER_SHARED_DATA)MM_SHARED_USER_DATA_VA;
     433
     434        /* use interrupt time */
     435        LARGE_INTEGER Time;
     436        do
     437        {
     438            Time.HighPart = pUsd->SystemTime.High1Time;
     439            Time.LowPart  = pUsd->SystemTime.LowPart;
     440        } while (pUsd->SystemTime.High2Time != Time.HighPart);
     441
     442        pTime->dwHighDateTime = Time.HighPart;
     443        pTime->dwLowDateTime  = Time.LowPart;
     444    }
    516445    else
    517446    {
    518         DWORD dwVersion = GetVersion();
    519         if (   (dwVersion & 0xff) > 3
    520             || (   (dwVersion & 0xff) == 3
    521                 && ((dwVersion >> 8) & 0xff) >= 50) )
    522         {
    523             PKUSER_SHARED_DATA pUsd = (PKUSER_SHARED_DATA)MM_SHARED_USER_DATA_VA;
    524 
    525             /* use interrupt time */
    526             LARGE_INTEGER Time;
    527             do
    528             {
    529                 Time.HighPart = pUsd->SystemTime.High1Time;
    530                 Time.LowPart  = pUsd->SystemTime.LowPart;
    531             } while (pUsd->SystemTime.High2Time != Time.HighPart);
    532 
    533             pTime->dwHighDateTime = Time.HighPart;
    534             pTime->dwLowDateTime  = Time.LowPart;
    535         }
     447        /* NT 3.1 didn't have a KUSER_SHARED_DATA nor a GetSystemTimeAsFileTime export. */
     448        SYSTEMTIME SystemTime;
     449        GetSystemTime(&SystemTime);
     450        BOOL fRet = SystemTimeToFileTime(&SystemTime, pTime);
     451        if (fRet)
     452        { /* likely */ }
    536453        else
    537454        {
    538             /* NT 3.1 didn't have a KUSER_SHARED_DATA nor a GetSystemTimeAsFileTime export. */
    539             SYSTEMTIME SystemTime;
    540             GetSystemTime(&SystemTime);
    541             BOOL fRet = SystemTimeToFileTime(&SystemTime, pTime);
    542             AssertStmt(fRet, pTime->dwHighDateTime = pTime->dwLowDateTime = 0);
     455            MY_ASSERT(false, "GetSystemTimeAsFileTime: #2");
     456            pTime->dwHighDateTime = 0;
     457            pTime->dwLowDateTime  = 0;
    543458        }
    544459    }
     
    550465 */
    551466
    552 DECL_KERNEL32(BOOL) GetVersionExA(LPOSVERSIONINFOA pInfo)
    553 {
    554     RESOLVE_ME(GetVersionExA);
    555     if (pfnApi)
    556         return pfnApi(pInfo);
    557 
     467DECL_KERNEL32(BOOL) Fake_GetVersionExA(LPOSVERSIONINFOA pInfo)
     468{
     469    INIT_FAKES(GetVersionExA, (pInfo));
     470
     471    /*
     472     * Fallback.
     473     */
    558474    DWORD dwVersion = GetVersion();
    559475
     
    590506
    591507
    592 DECL_KERNEL32(BOOL) GetVersionExW(LPOSVERSIONINFOW pInfo)
    593 {
    594     RESOLVE_ME(GetVersionExW);
    595     if (pfnApi)
    596         return pfnApi(pInfo);
    597 
     508DECL_KERNEL32(BOOL) Fake_GetVersionExW(LPOSVERSIONINFOW pInfo)
     509{
     510    INIT_FAKES(GetVersionExW, (pInfo));
     511
     512    /*
     513     * Fallback.
     514     */
    598515    DWORD dwVersion = GetVersion();
    599516
     
    630547
    631548
    632 DECL_KERNEL32(LPWCH) GetEnvironmentStringsW(void)
    633 {
    634     RESOLVE_ME(GetEnvironmentStringsW);
    635     if (pfnApi)
    636         return pfnApi();
    637 
    638     /*
     549DECL_KERNEL32(LPWCH) Fake_GetEnvironmentStringsW(void)
     550{
     551    INIT_FAKES(GetEnvironmentStringsW, ());
     552
     553    /*
     554     * Fallback:
     555     *
    639556     * Environment is ANSI in NT 3.1. We should only be here for NT 3.1.
    640557     * For now, don't try do a perfect job converting it, just do it.
     
    664581
    665582
    666 DECL_KERNEL32(BOOL) FreeEnvironmentStringsW(LPWCH pwszzEnv)
    667 {
    668     RESOLVE_ME(FreeEnvironmentStringsW);
    669     if (pfnApi)
    670         return pfnApi(pwszzEnv);
     583DECL_KERNEL32(BOOL) Fake_FreeEnvironmentStringsW(LPWCH pwszzEnv)
     584{
     585    INIT_FAKES(FreeEnvironmentStringsW, (pwszzEnv));
     586
     587    /* Fallback: */
    671588    if (pwszzEnv)
    672589        HeapFree(GetProcessHeap(), 0, pwszzEnv);
     
    675592
    676593
    677 DECL_KERNEL32(int) GetLocaleInfoA(LCID idLocale, LCTYPE enmType, LPSTR pData, int cchData)
    678 {
    679     RESOLVE_ME(GetLocaleInfoA);
    680     if (pfnApi)
    681         return pfnApi(idLocale, enmType, pData, cchData);
    682 
    683     AssertMsgFailed(("GetLocaleInfoA: idLocale=%#x enmType=%#x cchData=%#x\n", idLocale, enmType, cchData));
     594DECL_KERNEL32(int) Fake_GetLocaleInfoA(LCID idLocale, LCTYPE enmType, LPSTR pData, int cchData)
     595{
     596    INIT_FAKES(GetLocaleInfoA, (idLocale, enmType, pData, cchData));
     597
     598    /* Fallback: */
     599    MY_ASSERT(false, "GetLocaleInfoA: idLocale=%#x enmType=%#x cchData=%#x", idLocale, enmType, cchData);
    684600    SetLastError(ERROR_NOT_SUPPORTED);
    685601    return 0;
     
    687603
    688604
    689 DECL_KERNEL32(BOOL) EnumSystemLocalesA(LOCALE_ENUMPROCA pfnCallback, DWORD fFlags)
    690 {
    691     RESOLVE_ME(EnumSystemLocalesA);
    692     if (pfnApi)
    693         return pfnApi(pfnCallback, fFlags);
    694 
    695     AssertMsgFailed(("EnumSystemLocalesA: pfnCallback=%p fFlags=%#x\n", pfnCallback, fFlags));
     605DECL_KERNEL32(BOOL) Fake_EnumSystemLocalesA(LOCALE_ENUMPROCA pfnCallback, DWORD fFlags)
     606{
     607    INIT_FAKES(EnumSystemLocalesA, (pfnCallback, fFlags));
     608
     609    /* Fallback: */
     610    MY_ASSERT(false, "EnumSystemLocalesA: pfnCallback=%p fFlags=%#x", pfnCallback, fFlags);
    696611    SetLastError(ERROR_NOT_SUPPORTED);
    697612    return FALSE;
     
    699614
    700615
    701 DECL_KERNEL32(BOOL) IsValidLocale(LCID idLocale, DWORD fFlags)
    702 {
    703     RESOLVE_ME(IsValidLocale);
    704     if (pfnApi)
    705         return pfnApi(idLocale, fFlags);
    706 
    707     AssertMsgFailed(("IsValidLocale: idLocale fFlags=%#x\n", idLocale, fFlags));
     616DECL_KERNEL32(BOOL) Fake_IsValidLocale(LCID idLocale, DWORD fFlags)
     617{
     618    INIT_FAKES(IsValidLocale, (idLocale, fFlags));
     619
     620    /* Fallback: */
     621    MY_ASSERT(false, "IsValidLocale: idLocale fFlags=%#x", idLocale, fFlags);
    708622    SetLastError(ERROR_NOT_SUPPORTED);
    709623    return FALSE;
     
    711625
    712626
    713 DECL_KERNEL32(DWORD_PTR) SetThreadAffinityMask(HANDLE hThread, DWORD_PTR fAffinityMask)
    714 {
    715     RESOLVE_ME(SetThreadAffinityMask);
    716     if (pfnApi)
    717         return pfnApi(hThread, fAffinityMask);
    718 
     627DECL_KERNEL32(DWORD_PTR) Fake_SetThreadAffinityMask(HANDLE hThread, DWORD_PTR fAffinityMask)
     628{
     629    INIT_FAKES(SetThreadAffinityMask, (hThread, fAffinityMask));
     630
     631    /* Fallback: */
    719632    SYSTEM_INFO SysInfo;
    720633    GetSystemInfo(&SysInfo);
    721     AssertMsgFailed(("SetThreadAffinityMask: hThread=%p fAffinityMask=%p SysInfo.dwActiveProcessorMask=%p\n",
    722                      hThread, fAffinityMask, SysInfo.dwActiveProcessorMask));
     634    MY_ASSERT(false, "SetThreadAffinityMask: hThread=%p fAffinityMask=%p SysInfo.dwActiveProcessorMask=%p",
     635              hThread, fAffinityMask, SysInfo.dwActiveProcessorMask);
    723636    if (   SysInfo.dwActiveProcessorMask == fAffinityMask
    724637        || fAffinityMask                 == ~(DWORD_PTR)0)
     
    730643
    731644
    732 DECL_KERNEL32(BOOL) GetProcessAffinityMask(HANDLE hProcess, PDWORD_PTR pfProcessAffinityMask, PDWORD_PTR pfSystemAffinityMask)
    733 {
    734     RESOLVE_ME(GetProcessAffinityMask);
    735     if (pfnApi)
    736         return pfnApi(hProcess, pfProcessAffinityMask, pfSystemAffinityMask);
    737 
     645DECL_KERNEL32(BOOL) Fake_GetProcessAffinityMask(HANDLE hProcess, PDWORD_PTR pfProcessAffinityMask, PDWORD_PTR pfSystemAffinityMask)
     646{
     647    INIT_FAKES(GetProcessAffinityMask, (hProcess, pfProcessAffinityMask, pfSystemAffinityMask));
     648
     649    /* Fallback: */
    738650    SYSTEM_INFO SysInfo;
    739651    GetSystemInfo(&SysInfo);
    740     AssertMsgFailed(("GetProcessAffinityMask: SysInfo.dwActiveProcessorMask=%p\n", SysInfo.dwActiveProcessorMask));
     652    MY_ASSERT(false, "GetProcessAffinityMask: SysInfo.dwActiveProcessorMask=%p", SysInfo.dwActiveProcessorMask);
    741653    if (pfProcessAffinityMask)
    742654        *pfProcessAffinityMask = SysInfo.dwActiveProcessorMask;
     
    747659
    748660
    749 DECL_KERNEL32(BOOL) GetHandleInformation(HANDLE hObject, DWORD *pfFlags)
    750 {
    751     RESOLVE_ME(GetHandleInformation);
    752     if (pfnApi)
    753         return pfnApi(hObject, pfFlags);
    754 
    755 
     661DECL_KERNEL32(BOOL) Fake_GetHandleInformation(HANDLE hObject, DWORD *pfFlags)
     662{
     663    INIT_FAKES(GetHandleInformation, (hObject, pfFlags));
     664
     665    /* Fallback: */
    756666    OBJECT_HANDLE_FLAG_INFORMATION  Info  = { 0, 0 };
    757667    DWORD                           cbRet = sizeof(Info);
     
    764674    }
    765675    *pfFlags = 0;
    766     AssertMsg(rcNt == STATUS_INVALID_HANDLE, ("rcNt=%#x\n", rcNt));
    767     SetLastError(rcNt == STATUS_INVALID_HANDLE ? ERROR_INVALID_HANDLE : ERROR_INVALID_FUNCTION);
    768     return FALSE;
    769 }
    770 
    771 
    772 DECL_KERNEL32(BOOL) SetHandleInformation(HANDLE hObject, DWORD fMask, DWORD fFlags)
    773 {
    774     RESOLVE_ME(SetHandleInformation);
    775     if (pfnApi)
    776         return pfnApi(hObject, fMask, fFlags);
    777 
     676    MY_ASSERT(rcNt == STATUS_INVALID_HANDLE, "rcNt=%#x", rcNt);
     677    SetLastError(rcNt == STATUS_INVALID_HANDLE ? ERROR_INVALID_HANDLE : ERROR_INVALID_FUNCTION); /* see also process-win.cpp */
     678    return FALSE;
     679}
     680
     681
     682DECL_KERNEL32(BOOL) Fake_SetHandleInformation(HANDLE hObject, DWORD fMask, DWORD fFlags)
     683{
     684    INIT_FAKES(SetHandleInformation, (hObject, fMask, fFlags));
     685
     686    /* Fallback: */
    778687    SetLastError(ERROR_INVALID_FUNCTION);
    779688    return FALSE;
  • trunk/src/VBox/Runtime/r3/win/vcc100-kernel32-fakesA.asm

    r70345 r70375  
    2626
    2727
    28 %include "iprt/asmdefs.mac"
    29 
    30 %ifndef RT_ARCH_X86
    31  %error "This is x86 only code.
    32 %endif
    33 
    34 
    35 %macro MAKE_IMPORT_ENTRY 2
    36 extern _ %+ %1 %+ @ %+ %2
    37 global __imp__ %+ %1 %+ @ %+ %2
    38 __imp__ %+ %1 %+ @ %+ %2:
    39     dd _ %+ %1 %+ @ %+ %2
    40 
    41 %endmacro
    42 
     28%include "vcc100-fakes.mac"
    4329
    4430BEGINDATA
    4531GLOBALNAME vcc100_kernel32_fakes_asm
    4632
    47 ; NT 4
    48 MAKE_IMPORT_ENTRY DecodePointer, 4
    49 MAKE_IMPORT_ENTRY EncodePointer, 4
    50 MAKE_IMPORT_ENTRY InitializeCriticalSectionAndSpinCount, 8
    51 MAKE_IMPORT_ENTRY HeapSetInformation, 16
    52 MAKE_IMPORT_ENTRY HeapQueryInformation, 20
    53 MAKE_IMPORT_ENTRY CreateTimerQueue, 0
    54 MAKE_IMPORT_ENTRY CreateTimerQueueTimer, 28
    55 MAKE_IMPORT_ENTRY DeleteTimerQueueTimer, 12
    56 MAKE_IMPORT_ENTRY InitializeSListHead, 4
    57 MAKE_IMPORT_ENTRY InterlockedFlushSList, 4
    58 MAKE_IMPORT_ENTRY InterlockedPopEntrySList, 4
    59 MAKE_IMPORT_ENTRY InterlockedPushEntrySList, 8
    60 MAKE_IMPORT_ENTRY QueryDepthSList, 4
    61 MAKE_IMPORT_ENTRY VerifyVersionInfoA, 16
    62 MAKE_IMPORT_ENTRY VerSetConditionMask, 16
    63 ; NT 3.51
    64 MAKE_IMPORT_ENTRY IsProcessorFeaturePresent, 4
    65 MAKE_IMPORT_ENTRY CancelIo, 4
    66 ; NT 3.50
    67 MAKE_IMPORT_ENTRY IsDebuggerPresent, 0
    68 MAKE_IMPORT_ENTRY GetSystemTimeAsFileTime, 4
    69 ; NT 3.1
    70 MAKE_IMPORT_ENTRY GetVersionExA, 4
    71 MAKE_IMPORT_ENTRY GetVersionExW, 4
    72 MAKE_IMPORT_ENTRY GetEnvironmentStringsW, 0
    73 MAKE_IMPORT_ENTRY FreeEnvironmentStringsW, 4
    74 MAKE_IMPORT_ENTRY GetLocaleInfoA, 16
    75 MAKE_IMPORT_ENTRY EnumSystemLocalesA, 8
    76 MAKE_IMPORT_ENTRY IsValidLocale, 8
    77 MAKE_IMPORT_ENTRY SetThreadAffinityMask, 8
    78 MAKE_IMPORT_ENTRY GetProcessAffinityMask, 12
    79 MAKE_IMPORT_ENTRY GetHandleInformation, 8
    80 MAKE_IMPORT_ENTRY SetHandleInformation, 12
     33%include "vcc100-kernel32-fakes.h"
    8134
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette