VirtualBox

Ignore:
Timestamp:
Dec 10, 2009 4:30:31 PM (15 years ago)
Author:
vboxsync
Message:

SUPDrv: Use RTSemMutex instead of RTSemFastMutex for the loader on windows.

Location:
trunk/src/VBox/HostDrivers/Support
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/SUPDrv.c

    r25300 r25307  
    103103static int      supdrvLdrAddUsage(PSUPDRVSESSION pSession, PSUPDRVLDRIMAGE pImage);
    104104static void     supdrvLdrFree(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
     105DECLINLINE(int) supdrvLdrLock(PSUPDRVDEVEXT pDevExt);
     106DECLINLINE(int) supdrvLdrUnlock(PSUPDRVDEVEXT pDevExt);
    105107static int      supdrvIOCtl_CallServiceModule(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPCALLSERVICE pReq);
    106108static int      supdrvIOCtl_LoggerSettings(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLOGGERSETTINGS pReq);
     
    499501    if (!rc)
    500502    {
     503#ifdef SUPDRV_USE_MUTEX_FOR_LDR
     504        rc = RTSemMutexCreate(&pDevExt->mtxLdr);
     505#else
    501506        rc = RTSemFastMutexCreate(&pDevExt->mtxLdr);
     507#endif
    502508        if (!rc)
    503509        {
     
    574580                pDevExt->mtxComponentFactory = NIL_RTSEMFASTMUTEX;
    575581            }
     582#ifdef SUPDRV_USE_MUTEX_FOR_LDR
     583            RTSemMutexDestroy(pDevExt->mtxLdr);
     584            pDevExt->mtxLdr = NIL_RTSEMMUTEX;
     585#else
    576586            RTSemFastMutexDestroy(pDevExt->mtxLdr);
    577587            pDevExt->mtxLdr = NIL_RTSEMFASTMUTEX;
     588#endif
    578589        }
    579590        RTSpinlockDestroy(pDevExt->Spinlock);
     
    604615    RTSemFastMutexDestroy(pDevExt->mtxGip);
    605616    pDevExt->mtxGip = NIL_RTSEMFASTMUTEX;
     617#ifdef SUPDRV_USE_MUTEX_FOR_LDR
     618    RTSemMutexDestroy(pDevExt->mtxLdr);
     619    pDevExt->mtxLdr = NIL_RTSEMMUTEX;
     620#else
    606621    RTSemFastMutexDestroy(pDevExt->mtxLdr);
    607622    pDevExt->mtxLdr = NIL_RTSEMFASTMUTEX;
     623#endif
    608624    RTSpinlockDestroy(pDevExt->Spinlock);
    609625    pDevExt->Spinlock = NIL_RTSPINLOCK;
     
    917933     * Loaded images needs to be dereferenced and possibly freed up.
    918934     */
    919     RTSemFastMutexRequest(pDevExt->mtxLdr);
     935    supdrvLdrLock(pDevExt);
    920936    Log2(("freeing images:\n"));
    921937    if (pSession->pLdrUsage)
     
    936952        }
    937953    }
    938     RTSemFastMutexRelease(pDevExt->mtxLdr);
     954    supdrvLdrUnlock(pDevExt);
    939955    Log2(("freeing images - done\n"));
    940956
     
    34563472     * Check if we got an instance of the image already.
    34573473     */
    3458     RTSemFastMutexRequest(pDevExt->mtxLdr);
     3474    supdrvLdrLock(pDevExt);
    34593475    for (pImage = pDevExt->pLdrImages; pImage; pImage = pImage->pNext)
    34603476    {
     
    34683484            pReq->u.Out.fNativeLoader = pImage->fNative;
    34693485            supdrvLdrAddUsage(pSession, pImage);
    3470             RTSemFastMutexRelease(pDevExt->mtxLdr);
     3486            supdrvLdrUnlock(pDevExt);
    34713487            return VINF_SUCCESS;
    34723488        }
     
    34803496    if (!pv)
    34813497    {
    3482         RTSemFastMutexRelease(pDevExt->mtxLdr);
     3498        supdrvLdrUnlock(pDevExt);
    34833499        Log(("supdrvIOCtl_LdrOpen: RTMemAlloc() failed\n"));
    34843500        return VERR_NO_MEMORY;
     
    35193535    if (RT_FAILURE(rc))
    35203536    {
    3521         RTSemFastMutexRelease(pDevExt->mtxLdr);
     3537        supdrvLdrUnlock(pDevExt);
    35223538        RTMemFree(pImage);
    35233539        Log(("supdrvIOCtl_LdrOpen(%s): failed - %Rrc\n", pReq->u.In.szName, rc));
     
    35373553    pReq->u.Out.fNeedsLoading = true;
    35383554    pReq->u.Out.fNativeLoader = pImage->fNative;
    3539     RTSemFastMutexRelease(pDevExt->mtxLdr);
     3555    supdrvLdrUnlock(pDevExt);
    35403556
    35413557#if defined(RT_OS_WINDOWS) && defined(DEBUG)
     
    35663582        if ((uintptr_t)pv - (uintptr_t)pImage->pvImage >= pImage->cbImageBits)
    35673583        {
    3568             RTSemFastMutexRelease(pDevExt->mtxLdr);
     3584            supdrvLdrUnlock(pDevExt);
    35693585            Log(("Out of range (%p LB %#x): %s=%p\n", pImage->pvImage, pImage->cbImageBits, pszWhat, pv));
    35703586            return VERR_INVALID_PARAMETER;
     
    35763592            if (RT_FAILURE(rc))
    35773593            {
    3578                 RTSemFastMutexRelease(pDevExt->mtxLdr);
     3594                supdrvLdrUnlock(pDevExt);
    35793595                Log(("Bad entry point address: %s=%p (rc=%Rrc)\n", pszWhat, pv, rc));
    35803596                return rc;
     
    36063622     * Find the ldr image.
    36073623     */
    3608     RTSemFastMutexRequest(pDevExt->mtxLdr);
     3624    supdrvLdrLock(pDevExt);
    36093625    pUsage = pSession->pLdrUsage;
    36103626    while (pUsage && pUsage->pImage->pvImage != pReq->u.In.pvImageBase)
     
    36123628    if (!pUsage)
    36133629    {
    3614         RTSemFastMutexRelease(pDevExt->mtxLdr);
     3630        supdrvLdrUnlock(pDevExt);
    36153631        Log(("SUP_IOCTL_LDR_LOAD: couldn't find image!\n"));
    36163632        return VERR_INVALID_HANDLE;
     
    36243640        || pImage->cbImageBits     != pReq->u.In.cbImageBits)
    36253641    {
    3626         RTSemFastMutexRelease(pDevExt->mtxLdr);
     3642        supdrvLdrUnlock(pDevExt);
    36273643        Log(("SUP_IOCTL_LDR_LOAD: image size mismatch!! %d(prep) != %d(load) or %d != %d\n",
    36283644             pImage->cbImageWithTabs, pReq->u.In.cbImageWithTabs, pImage->cbImageBits, pReq->u.In.cbImageBits));
     
    36333649    {
    36343650        unsigned uState = pImage->uState;
    3635         RTSemFastMutexRelease(pDevExt->mtxLdr);
     3651        supdrvLdrUnlock(pDevExt);
    36363652        if (uState != SUP_IOCTL_LDR_LOAD)
    36373653            AssertMsgFailed(("SUP_IOCTL_LDR_LOAD: invalid image state %d (%#x)!\n", uState, uState));
     
    36643680                ||  pReq->u.In.EP.Service.apvReserved[2] != NIL_RTR0PTR)
    36653681            {
    3666                 RTSemFastMutexRelease(pDevExt->mtxLdr);
     3682                supdrvLdrUnlock(pDevExt);
    36673683                Log(("Out of range (%p LB %#x): apvReserved={%p,%p,%p} MBZ!\n",
    36683684                     pImage->pvImage, pReq->u.In.cbImageWithTabs,
     
    36753691
    36763692        default:
    3677             RTSemFastMutexRelease(pDevExt->mtxLdr);
     3693            supdrvLdrUnlock(pDevExt);
    36783694            Log(("Invalid eEPType=%d\n", pReq->u.In.eEPType));
    36793695            return VERR_INVALID_PARAMETER;
     
    37793795    }
    37803796
    3781     RTSemFastMutexRelease(pDevExt->mtxLdr);
     3797    supdrvLdrUnlock(pDevExt);
    37823798    return rc;
    37833799}
     
    38033819     * Find the ldr image.
    38043820     */
    3805     RTSemFastMutexRequest(pDevExt->mtxLdr);
     3821    supdrvLdrLock(pDevExt);
    38063822    pUsagePrev = NULL;
    38073823    pUsage = pSession->pLdrUsage;
     
    38133829    if (!pUsage)
    38143830    {
    3815         RTSemFastMutexRelease(pDevExt->mtxLdr);
     3831        supdrvLdrUnlock(pDevExt);
    38163832        Log(("SUP_IOCTL_LDR_FREE: couldn't find image!\n"));
    38173833        return VERR_INVALID_HANDLE;
     
    38893905    }
    38903906
    3891     RTSemFastMutexRelease(pDevExt->mtxLdr);
     3907    supdrvLdrUnlock(pDevExt);
    38923908    return rc;
    38933909}
     
    39183934     * Find the ldr image.
    39193935     */
    3920     RTSemFastMutexRequest(pDevExt->mtxLdr);
     3936    supdrvLdrLock(pDevExt);
    39213937    pUsage = pSession->pLdrUsage;
    39223938    while (pUsage && pUsage->pImage->pvImage != pReq->u.In.pvImageBase)
     
    39243940    if (!pUsage)
    39253941    {
    3926         RTSemFastMutexRelease(pDevExt->mtxLdr);
     3942        supdrvLdrUnlock(pDevExt);
    39273943        Log(("SUP_IOCTL_LDR_GET_SYMBOL: couldn't find image!\n"));
    39283944        return VERR_INVALID_HANDLE;
     
    39323948    {
    39333949        unsigned uState = pImage->uState;
    3934         RTSemFastMutexRelease(pDevExt->mtxLdr);
     3950        supdrvLdrUnlock(pDevExt);
    39353951        Log(("SUP_IOCTL_LDR_GET_SYMBOL: invalid image state %d (%#x)!\n", uState, uState)); NOREF(uState);
    39363952        return VERR_ALREADY_LOADED;
     
    39533969        }
    39543970    }
    3955     RTSemFastMutexRelease(pDevExt->mtxLdr);
     3971    supdrvLdrUnlock(pDevExt);
    39563972    pReq->u.Out.pvSymbol = pvSymbol;
    39573973    return rc;
     
    40144030        PSUPDRVLDRIMAGE pImage;
    40154031
    4016         RTSemFastMutexRequest(pDevExt->mtxLdr);
     4032        supdrvLdrLock(pDevExt);
    40174033
    40184034        for (pImage = pDevExt->pLdrImages; pImage; pImage = pImage->pNext)
     
    40444060            rc = pImage ? VERR_WRONG_ORDER : VERR_MODULE_NOT_FOUND;
    40454061
    4046         RTSemFastMutexRelease(pDevExt->mtxLdr);
     4062        supdrvLdrUnlock(pDevExt);
    40474063    }
    40484064    return rc;
     
    42344250
    42354251/**
     4252 * Acquires the loader lock.
     4253 *
     4254 * @returns IPRT status code.
     4255 * @param   pDevExt         The device extension.
     4256 */
     4257DECLINLINE(int) supdrvLdrLock(PSUPDRVDEVEXT pDevExt)
     4258{
     4259#ifdef SUPDRV_USE_MUTEX_FOR_LDR
     4260    return RTSemMutexRequest(pDevExt->mtxLdr, RT_INDEFINITE_WAIT);
     4261#else
     4262    return RTSemFastMutexRequest(pDevExt->mtxLdr);
     4263#endif
     4264}
     4265
     4266
     4267/**
     4268 * Releases the loader lock.
     4269 *
     4270 * @returns IPRT status code.
     4271 * @param   pDevExt         The device extension.
     4272 */
     4273DECLINLINE(int) supdrvLdrUnlock(PSUPDRVDEVEXT pDevExt)
     4274{
     4275#ifdef SUPDRV_USE_MUTEX_FOR_LDR
     4276    return RTSemMutexRelease(pDevExt->mtxLdr);
     4277#else
     4278    return RTSemFastMutexRelease(pDevExt->mtxLdr);
     4279#endif
     4280}
     4281
     4282
     4283/**
    42364284 * Implements the service call request.
    42374285 *
     
    42494297     * Find the module first in the module referenced by the calling session.
    42504298     */
    4251     rc = RTSemFastMutexRequest(pDevExt->mtxLdr);
     4299    rc = supdrvLdrLock(pDevExt);
    42524300    if (RT_SUCCESS(rc))
    42534301    {
     
    42624310                break;
    42634311            }
    4264         RTSemFastMutexRelease(pDevExt->mtxLdr);
     4312        supdrvLdrUnlock(pDevExt);
    42654313
    42664314        if (pfnServiceReqHandler)
  • trunk/src/VBox/HostDrivers/Support/SUPDrvInternal.h

    r25278 r25307  
    174174 * to actually be much lower. The values here have been determined experimentally.
    175175 */
    176 #ifdef RT_ARCH_X86
    177 # define MAX_LOCK_MEM_SIZE   (32*1024*1024) /* 32mb */
    178 #endif
    179 #ifdef RT_ARCH_AMD64
    180 # define MAX_LOCK_MEM_SIZE   (24*1024*1024) /* 24mb */
    181 #endif
    182 
     176# ifdef RT_ARCH_X86
     177#  define MAX_LOCK_MEM_SIZE   (32*1024*1024) /* 32mb */
     178# endif
     179# ifdef RT_ARCH_AMD64
     180#  define MAX_LOCK_MEM_SIZE   (24*1024*1024) /* 24mb */
     181# endif
     182
     183/** Use a normal mutex for the loader so we remain at the same IRQL after
     184 * taking it.
     185 * @todo fix the mutex implementation on linux and make this the default. */
     186# define SUPDRV_USE_MUTEX_FOR_LDR
    183187
    184188/*
     
    601605    /** Loader mutex.
    602606     * This protects pvVMMR0, pvVMMR0Entry, pImages and SUPDRVSESSION::pLdrUsage. */
     607#ifdef SUPDRV_USE_MUTEX_FOR_LDR
     608    RTSEMMUTEX                      mtxLdr;
     609#else
    603610    RTSEMFASTMUTEX                  mtxLdr;
     611#endif
    604612
    605613    /** VMM Module 'handle'.
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