VirtualBox

Ignore:
Timestamp:
Jul 8, 2014 5:50:10 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
94834
Message:

SUPDrv-win.cpp: Use the RTTerm/RTOnce stuff to clean up that default random number generator instance the driver verifier is upset about (leak).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/once.cpp

    r48807 r51941  
    3434#include <iprt/asm.h>
    3535#include <iprt/assert.h>
    36 #include <iprt/critsect.h>
     36#ifdef IN_RING3
     37# include <iprt/critsect.h>
     38# define RTONCE_USE_CRITSECT_FOR_TERM
     39#elif defined(IN_RING0)
     40# include <iprt/spinlock.h>
     41# define RTONCE_USE_SPINLOCK_FOR_TERM
     42#else
     43# define RTONCE_NO_TERM
     44#endif
    3745#include <iprt/err.h>
    3846#include <iprt/initterm.h>
     
    4452*   Global Variables                                                           *
    4553*******************************************************************************/
    46 #ifdef IN_RING3
    47 
     54#ifndef RTONCE_NO_TERM
    4855/** For initializing the clean-up list code. */
    4956static RTONCE           g_OnceCleanUp = RTONCE_INITIALIZER;
    50 /** Critical section protecting the clean-up list. */
     57/** Lock protecting the clean-up list. */
     58#ifdef RTONCE_USE_CRITSECT_FOR_TERM
    5159static RTCRITSECT       g_CleanUpCritSect;
     60#else
     61static RTSEMFASTMUTEX   g_hCleanUpLock;
     62#endif
    5263/** The clean-up list. */
    5364static RTLISTANCHOR     g_CleanUpList;
     65
     66/** Locks the clean-up list. */
     67#ifdef RTONCE_USE_CRITSECT_FOR_TERM
     68# define RTONCE_CLEANUP_LOCK()      RTCritSectEnter(&g_CleanUpCritSect)
     69#else
     70# define RTONCE_CLEANUP_LOCK()      RTSemFastMutexRequest(g_hCleanUpLock);
     71#endif
     72
     73/** Unlocks the clean-up list. */
     74#ifdef RTONCE_USE_CRITSECT_FOR_TERM
     75# define RTONCE_CLEANUP_UNLOCK()    RTCritSectLeave(&g_CleanUpCritSect);
     76#else
     77# define RTONCE_CLEANUP_UNLOCK()    RTSemFastMutexRelease(g_hCleanUpLock);
     78#endif
     79
    5480
    5581
     
    5884{
    5985    bool const fLazyCleanUpOk = RTTERMREASON_IS_LAZY_CLEANUP_OK(enmReason);
    60     RTCritSectEnter(&g_CleanUpCritSect); /* Potentially dangerous. */
     86    RTONCE_CLEANUP_LOCK();      /* Potentially dangerous. */
    6187
    6288    PRTONCE pCur, pPrev;
     
    87113    }
    88114
    89     RTCritSectLeave(&g_CleanUpCritSect);
    90     NOREF(pvUser); NOREF(enmReason); NOREF(iStatus);
     115    RTONCE_CLEANUP_UNLOCK();
     116
     117    /*
     118     * Reset our own structure and the critsect / mutex.
     119     */
     120    if (!fLazyCleanUpOk)
     121    {
     122# ifdef RTONCE_USE_CRITSECT_FOR_TERM
     123        RTCritSectDelete(&g_CleanUpCritSect);
     124# else
     125        RTSemFastMutexDestroy(g_hCleanUpLock);
     126        g_hCleanUpLock = NIL_RTSEMFASTMUTEX;
     127# endif
     128
     129        ASMAtomicWriteS32(&g_OnceCleanUp.rc, VERR_INTERNAL_ERROR);
     130        ASMAtomicWriteS32(&g_OnceCleanUp.iState, RTONCESTATE_UNINITIALIZED);
     131    }
     132
     133    NOREF(pvUser); NOREF(iStatus);
    91134}
    92135
     
    103146    NOREF(pvUser);
    104147    RTListInit(&g_CleanUpList);
     148# ifdef RTONCE_USE_CRITSECT_FOR_TERM
    105149    int rc = RTCritSectInit(&g_CleanUpCritSect);
     150# else
     151    int rc = RTSemFastMutexCreate(&g_hCleanUpLock);
     152# endif
    106153    if (RT_SUCCESS(rc))
    107154    {
     
    110157            return rc;
    111158
     159# ifdef RTONCE_USE_CRITSECT_FOR_TERM
    112160        RTCritSectDelete(&g_CleanUpCritSect);
     161# else
     162        RTSemFastMutexDestroy(g_hCleanUpLock);
     163        g_hCleanUpLock = NIL_RTSEMFASTMUTEX;
     164# endif
    113165    }
    114166    return rc;
    115167}
    116168
    117 #endif /* IN_RING3 */
    118 
    119 
     169#endif /* !RTONCE_NO_TERM */
    120170
    121171/**
     
    262312                 , VERR_INTERNAL_ERROR);
    263313
    264 #ifndef IN_RING3
     314#ifdef RTONCE_NO_TERM
    265315    AssertReturn(!pfnCleanUp, VERR_NOT_SUPPORTED);
    266 #else /* IN_RING3 */
     316#else /* !RTONCE_NO_TERM */
    267317
    268318    /*
     
    275325            return rc;
    276326    }
    277 #endif /* IN_RING3 */
     327#endif /* !RTONCE_NO_TERM */
    278328
    279329    /*
     
    290340        ASMAtomicWriteS32(&pOnce->rc, rcOnce);
    291341
    292 #ifdef IN_RING3
     342#ifndef RTONCE_NO_TERM
    293343        /*
    294344         * Register clean-up if requested and we were successful.
     
    296346        if (pfnCleanUp && RT_SUCCESS(rcOnce))
    297347        {
    298             RTCritSectEnter(&g_CleanUpCritSect);
     348            RTONCE_CLEANUP_LOCK();
     349
    299350            pOnce->pfnCleanUp = pfnCleanUp;
    300351            pOnce->pvUser     = pvUser;
    301352            RTListAppend(&g_CleanUpList, &pOnce->CleanUpNode);
    302             RTCritSectLeave(&g_CleanUpCritSect);
     353
     354            RTONCE_CLEANUP_UNLOCK();
    303355        }
    304 #endif
     356#endif /* !RTONCE_NO_TERM */
    305357
    306358        /*
     
    367419    NOREF(iState);
    368420
    369 #ifdef IN_RING3
     421#ifndef RTONCE_NO_TERM
    370422    /* Unregister clean-up. */
    371423    if (pOnce->pfnCleanUp)
    372424    {
    373         RTCritSectEnter(&g_CleanUpCritSect);
     425        RTONCE_CLEANUP_LOCK();
     426
    374427        RTListNodeRemove(&pOnce->CleanUpNode);
    375428        pOnce->pfnCleanUp = NULL;
    376429        pOnce->pvUser     = NULL;
    377         RTCritSectLeave(&g_CleanUpCritSect);
    378     }
    379 #endif /* IN_RING3 */
     430
     431        RTONCE_CLEANUP_UNLOCK();
     432    }
     433#endif /* !RTONCE_NO_TERM */
    380434
    381435    /* Do the same as RTONCE_INITIALIZER does. */
Note: See TracChangeset for help on using the changeset viewer.

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