VirtualBox

Changeset 39485 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Dec 1, 2011 9:51:39 AM (13 years ago)
Author:
vboxsync
Message:

crOpenGL: stubInit syncronization needed for win XPDM guests, some debug tooling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/crOpenGL/load.c

    r38864 r39485  
    5656
    5757static int stub_initialized = 0;
     58#ifdef WINDOWS
     59static CRmutex stub_init_mutex;
     60#define STUB_INIT_LOCK() do { crLockMutex(&stub_init_mutex); } while (0)
     61#define STUB_INIT_UNLOCK() do { crUnlockMutex(&stub_init_mutex); } while (0)
     62#else
     63#define STUB_INIT_LOCK() do { } while (0)
     64#define STUB_INIT_UNLOCK() do { } while (0)
     65#endif
    5866
    5967/* NOTE: 'SPUDispatchTable glim' is declared in NULLfuncs.py now */
     
    311319 * We call all the SPU's cleanup functions.
    312320 */
    313 static void stubSPUTearDown(void)
    314 {
    315     crDebug("stubSPUTearDown");
    316     if (!stub_initialized) return;
    317 
    318     stub_initialized = 0;
     321static void stubSPUTearDownLocked(void)
     322{
     323    crDebug("stubSPUTearDownLocked");
    319324
    320325#ifdef WINDOWS
     
    359364
    360365    crMemset(&stub, 0, sizeof(stub));
     366
     367}
     368
     369/**
     370 * This is called when we exit.
     371 * We call all the SPU's cleanup functions.
     372 */
     373static void stubSPUTearDown(void)
     374{
     375    STUB_INIT_LOCK();
     376    if (stub_initialized)
     377    {
     378        stubSPUTearDownLocked();
     379        stub_initialized = 0;
     380    }
     381    STUB_INIT_UNLOCK();
    361382}
    362383
     
    11011122 * Returns TRUE on success, FALSE otherwise.
    11021123 */
    1103 bool
    1104 stubInit(void)
     1124static bool
     1125stubInitLocked(void)
    11051126{
    11061127    /* Here is where we contact the mothership to find out what we're supposed
     
    11211142    int disable_sync = 0;
    11221143
    1123     if (stub_initialized)
    1124         return true;
    1125 
    11261144    stubInitVars();
    11271145
     
    12561274#endif
    12571275
    1258     stub_initialized = 1;
    12591276    return true;
     1277}
     1278
     1279/**
     1280 * Do one-time initializations for the faker.
     1281 * Returns TRUE on success, FALSE otherwise.
     1282 */
     1283bool
     1284stubInit(void)
     1285{
     1286    bool bRc = true;
     1287    /* we need to serialize the initialization, otherwise racing is possible
     1288     * for XPDM-based d3d when a d3d switcher is testing the gl lib in two or more threads
     1289     * NOTE: the STUB_INIT_LOCK/UNLOCK is a NOP for non-win currently */
     1290    STUB_INIT_LOCK();
     1291    if (!stub_initialized)
     1292        bRc = stub_initialized = stubInitLocked();
     1293    STUB_INIT_UNLOCK();
     1294    return bRc;
    12601295}
    12611296
     
    12721307#include <windows.h>
    12731308
     1309#ifdef DEBUG_misha
     1310 /* debugging: this is to be able to catch first-chance notifications
     1311  * for exceptions other than EXCEPTION_BREAKPOINT in kernel debugger */
     1312# define VDBG_VEHANDLER
     1313#endif
     1314
     1315#ifdef VDBG_VEHANDLER
     1316static PVOID g_VBoxWDbgVEHandler = NULL;
     1317LONG WINAPI vboxVDbgVectoredHandler(struct _EXCEPTION_POINTERS *pExceptionInfo)
     1318{
     1319    PEXCEPTION_RECORD pExceptionRecord = pExceptionInfo->ExceptionRecord;
     1320    PCONTEXT pContextRecord = pExceptionInfo->ContextRecord;
     1321    switch (pExceptionRecord->ExceptionCode)
     1322    {
     1323        case EXCEPTION_BREAKPOINT:
     1324        case EXCEPTION_ACCESS_VIOLATION:
     1325        case EXCEPTION_STACK_OVERFLOW:
     1326        case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
     1327        case EXCEPTION_FLT_DIVIDE_BY_ZERO:
     1328        case EXCEPTION_FLT_INVALID_OPERATION:
     1329        case EXCEPTION_INT_DIVIDE_BY_ZERO:
     1330        case EXCEPTION_ILLEGAL_INSTRUCTION:
     1331            CRASSERT(0);
     1332            break;
     1333        default:
     1334            break;
     1335    }
     1336    return EXCEPTION_CONTINUE_SEARCH;
     1337}
     1338
     1339void vboxVDbgVEHandlerRegister()
     1340{
     1341    CRASSERT(!g_VBoxWDbgVEHandler);
     1342    g_VBoxWDbgVEHandler = AddVectoredExceptionHandler(1,vboxVDbgVectoredHandler);
     1343    CRASSERT(g_VBoxWDbgVEHandler);
     1344}
     1345
     1346void vboxVDbgVEHandlerUnregister()
     1347{
     1348    ULONG uResult;
     1349    if (g_VBoxWDbgVEHandler)
     1350    {
     1351        uResult = RemoveVectoredExceptionHandler(g_VBoxWDbgVEHandler);
     1352        CRASSERT(uResult);
     1353        g_VBoxWDbgVEHandler = NULL;
     1354    }
     1355}
     1356#endif
     1357
    12741358/* Windows crap */
    12751359BOOL WINAPI DllMain(HINSTANCE hDLLInst, DWORD fdwReason, LPVOID lpvReserved)
     
    12821366    {
    12831367        CRNetServer ns;
     1368
     1369        crInitMutex(&stub_init_mutex);
     1370
     1371#ifdef VDBG_VEHANDLER
     1372        vboxVDbgVEHandlerRegister();
     1373#endif
    12841374
    12851375        crNetInit(NULL, NULL);
     
    12901380        {
    12911381            crDebug("Failed to connect to host (is guest 3d acceleration enabled?), aborting ICD load.");
     1382#ifdef VDBG_VEHANDLER
     1383            vboxVDbgVEHandlerUnregister();
     1384#endif
    12921385            return FALSE;
    12931386        }
     
    13011394    {
    13021395        stubSPUSafeTearDown();
     1396
     1397#ifdef VDBG_VEHANDLER
     1398        vboxVDbgVEHandlerUnregister();
     1399#endif
     1400
    13031401        break;
    13041402    }
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