Changeset 25307 in vbox for trunk/src/VBox/HostDrivers/Support
- Timestamp:
- Dec 10, 2009 4:30:31 PM (15 years ago)
- Location:
- trunk/src/VBox/HostDrivers/Support
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/SUPDrv.c
r25300 r25307 103 103 static int supdrvLdrAddUsage(PSUPDRVSESSION pSession, PSUPDRVLDRIMAGE pImage); 104 104 static void supdrvLdrFree(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage); 105 DECLINLINE(int) supdrvLdrLock(PSUPDRVDEVEXT pDevExt); 106 DECLINLINE(int) supdrvLdrUnlock(PSUPDRVDEVEXT pDevExt); 105 107 static int supdrvIOCtl_CallServiceModule(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPCALLSERVICE pReq); 106 108 static int supdrvIOCtl_LoggerSettings(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLOGGERSETTINGS pReq); … … 499 501 if (!rc) 500 502 { 503 #ifdef SUPDRV_USE_MUTEX_FOR_LDR 504 rc = RTSemMutexCreate(&pDevExt->mtxLdr); 505 #else 501 506 rc = RTSemFastMutexCreate(&pDevExt->mtxLdr); 507 #endif 502 508 if (!rc) 503 509 { … … 574 580 pDevExt->mtxComponentFactory = NIL_RTSEMFASTMUTEX; 575 581 } 582 #ifdef SUPDRV_USE_MUTEX_FOR_LDR 583 RTSemMutexDestroy(pDevExt->mtxLdr); 584 pDevExt->mtxLdr = NIL_RTSEMMUTEX; 585 #else 576 586 RTSemFastMutexDestroy(pDevExt->mtxLdr); 577 587 pDevExt->mtxLdr = NIL_RTSEMFASTMUTEX; 588 #endif 578 589 } 579 590 RTSpinlockDestroy(pDevExt->Spinlock); … … 604 615 RTSemFastMutexDestroy(pDevExt->mtxGip); 605 616 pDevExt->mtxGip = NIL_RTSEMFASTMUTEX; 617 #ifdef SUPDRV_USE_MUTEX_FOR_LDR 618 RTSemMutexDestroy(pDevExt->mtxLdr); 619 pDevExt->mtxLdr = NIL_RTSEMMUTEX; 620 #else 606 621 RTSemFastMutexDestroy(pDevExt->mtxLdr); 607 622 pDevExt->mtxLdr = NIL_RTSEMFASTMUTEX; 623 #endif 608 624 RTSpinlockDestroy(pDevExt->Spinlock); 609 625 pDevExt->Spinlock = NIL_RTSPINLOCK; … … 917 933 * Loaded images needs to be dereferenced and possibly freed up. 918 934 */ 919 RTSemFastMutexRequest(pDevExt->mtxLdr);935 supdrvLdrLock(pDevExt); 920 936 Log2(("freeing images:\n")); 921 937 if (pSession->pLdrUsage) … … 936 952 } 937 953 } 938 RTSemFastMutexRelease(pDevExt->mtxLdr);954 supdrvLdrUnlock(pDevExt); 939 955 Log2(("freeing images - done\n")); 940 956 … … 3456 3472 * Check if we got an instance of the image already. 3457 3473 */ 3458 RTSemFastMutexRequest(pDevExt->mtxLdr);3474 supdrvLdrLock(pDevExt); 3459 3475 for (pImage = pDevExt->pLdrImages; pImage; pImage = pImage->pNext) 3460 3476 { … … 3468 3484 pReq->u.Out.fNativeLoader = pImage->fNative; 3469 3485 supdrvLdrAddUsage(pSession, pImage); 3470 RTSemFastMutexRelease(pDevExt->mtxLdr);3486 supdrvLdrUnlock(pDevExt); 3471 3487 return VINF_SUCCESS; 3472 3488 } … … 3480 3496 if (!pv) 3481 3497 { 3482 RTSemFastMutexRelease(pDevExt->mtxLdr);3498 supdrvLdrUnlock(pDevExt); 3483 3499 Log(("supdrvIOCtl_LdrOpen: RTMemAlloc() failed\n")); 3484 3500 return VERR_NO_MEMORY; … … 3519 3535 if (RT_FAILURE(rc)) 3520 3536 { 3521 RTSemFastMutexRelease(pDevExt->mtxLdr);3537 supdrvLdrUnlock(pDevExt); 3522 3538 RTMemFree(pImage); 3523 3539 Log(("supdrvIOCtl_LdrOpen(%s): failed - %Rrc\n", pReq->u.In.szName, rc)); … … 3537 3553 pReq->u.Out.fNeedsLoading = true; 3538 3554 pReq->u.Out.fNativeLoader = pImage->fNative; 3539 RTSemFastMutexRelease(pDevExt->mtxLdr);3555 supdrvLdrUnlock(pDevExt); 3540 3556 3541 3557 #if defined(RT_OS_WINDOWS) && defined(DEBUG) … … 3566 3582 if ((uintptr_t)pv - (uintptr_t)pImage->pvImage >= pImage->cbImageBits) 3567 3583 { 3568 RTSemFastMutexRelease(pDevExt->mtxLdr);3584 supdrvLdrUnlock(pDevExt); 3569 3585 Log(("Out of range (%p LB %#x): %s=%p\n", pImage->pvImage, pImage->cbImageBits, pszWhat, pv)); 3570 3586 return VERR_INVALID_PARAMETER; … … 3576 3592 if (RT_FAILURE(rc)) 3577 3593 { 3578 RTSemFastMutexRelease(pDevExt->mtxLdr);3594 supdrvLdrUnlock(pDevExt); 3579 3595 Log(("Bad entry point address: %s=%p (rc=%Rrc)\n", pszWhat, pv, rc)); 3580 3596 return rc; … … 3606 3622 * Find the ldr image. 3607 3623 */ 3608 RTSemFastMutexRequest(pDevExt->mtxLdr);3624 supdrvLdrLock(pDevExt); 3609 3625 pUsage = pSession->pLdrUsage; 3610 3626 while (pUsage && pUsage->pImage->pvImage != pReq->u.In.pvImageBase) … … 3612 3628 if (!pUsage) 3613 3629 { 3614 RTSemFastMutexRelease(pDevExt->mtxLdr);3630 supdrvLdrUnlock(pDevExt); 3615 3631 Log(("SUP_IOCTL_LDR_LOAD: couldn't find image!\n")); 3616 3632 return VERR_INVALID_HANDLE; … … 3624 3640 || pImage->cbImageBits != pReq->u.In.cbImageBits) 3625 3641 { 3626 RTSemFastMutexRelease(pDevExt->mtxLdr);3642 supdrvLdrUnlock(pDevExt); 3627 3643 Log(("SUP_IOCTL_LDR_LOAD: image size mismatch!! %d(prep) != %d(load) or %d != %d\n", 3628 3644 pImage->cbImageWithTabs, pReq->u.In.cbImageWithTabs, pImage->cbImageBits, pReq->u.In.cbImageBits)); … … 3633 3649 { 3634 3650 unsigned uState = pImage->uState; 3635 RTSemFastMutexRelease(pDevExt->mtxLdr);3651 supdrvLdrUnlock(pDevExt); 3636 3652 if (uState != SUP_IOCTL_LDR_LOAD) 3637 3653 AssertMsgFailed(("SUP_IOCTL_LDR_LOAD: invalid image state %d (%#x)!\n", uState, uState)); … … 3664 3680 || pReq->u.In.EP.Service.apvReserved[2] != NIL_RTR0PTR) 3665 3681 { 3666 RTSemFastMutexRelease(pDevExt->mtxLdr);3682 supdrvLdrUnlock(pDevExt); 3667 3683 Log(("Out of range (%p LB %#x): apvReserved={%p,%p,%p} MBZ!\n", 3668 3684 pImage->pvImage, pReq->u.In.cbImageWithTabs, … … 3675 3691 3676 3692 default: 3677 RTSemFastMutexRelease(pDevExt->mtxLdr);3693 supdrvLdrUnlock(pDevExt); 3678 3694 Log(("Invalid eEPType=%d\n", pReq->u.In.eEPType)); 3679 3695 return VERR_INVALID_PARAMETER; … … 3779 3795 } 3780 3796 3781 RTSemFastMutexRelease(pDevExt->mtxLdr);3797 supdrvLdrUnlock(pDevExt); 3782 3798 return rc; 3783 3799 } … … 3803 3819 * Find the ldr image. 3804 3820 */ 3805 RTSemFastMutexRequest(pDevExt->mtxLdr);3821 supdrvLdrLock(pDevExt); 3806 3822 pUsagePrev = NULL; 3807 3823 pUsage = pSession->pLdrUsage; … … 3813 3829 if (!pUsage) 3814 3830 { 3815 RTSemFastMutexRelease(pDevExt->mtxLdr);3831 supdrvLdrUnlock(pDevExt); 3816 3832 Log(("SUP_IOCTL_LDR_FREE: couldn't find image!\n")); 3817 3833 return VERR_INVALID_HANDLE; … … 3889 3905 } 3890 3906 3891 RTSemFastMutexRelease(pDevExt->mtxLdr);3907 supdrvLdrUnlock(pDevExt); 3892 3908 return rc; 3893 3909 } … … 3918 3934 * Find the ldr image. 3919 3935 */ 3920 RTSemFastMutexRequest(pDevExt->mtxLdr);3936 supdrvLdrLock(pDevExt); 3921 3937 pUsage = pSession->pLdrUsage; 3922 3938 while (pUsage && pUsage->pImage->pvImage != pReq->u.In.pvImageBase) … … 3924 3940 if (!pUsage) 3925 3941 { 3926 RTSemFastMutexRelease(pDevExt->mtxLdr);3942 supdrvLdrUnlock(pDevExt); 3927 3943 Log(("SUP_IOCTL_LDR_GET_SYMBOL: couldn't find image!\n")); 3928 3944 return VERR_INVALID_HANDLE; … … 3932 3948 { 3933 3949 unsigned uState = pImage->uState; 3934 RTSemFastMutexRelease(pDevExt->mtxLdr);3950 supdrvLdrUnlock(pDevExt); 3935 3951 Log(("SUP_IOCTL_LDR_GET_SYMBOL: invalid image state %d (%#x)!\n", uState, uState)); NOREF(uState); 3936 3952 return VERR_ALREADY_LOADED; … … 3953 3969 } 3954 3970 } 3955 RTSemFastMutexRelease(pDevExt->mtxLdr);3971 supdrvLdrUnlock(pDevExt); 3956 3972 pReq->u.Out.pvSymbol = pvSymbol; 3957 3973 return rc; … … 4014 4030 PSUPDRVLDRIMAGE pImage; 4015 4031 4016 RTSemFastMutexRequest(pDevExt->mtxLdr);4032 supdrvLdrLock(pDevExt); 4017 4033 4018 4034 for (pImage = pDevExt->pLdrImages; pImage; pImage = pImage->pNext) … … 4044 4060 rc = pImage ? VERR_WRONG_ORDER : VERR_MODULE_NOT_FOUND; 4045 4061 4046 RTSemFastMutexRelease(pDevExt->mtxLdr);4062 supdrvLdrUnlock(pDevExt); 4047 4063 } 4048 4064 return rc; … … 4234 4250 4235 4251 /** 4252 * Acquires the loader lock. 4253 * 4254 * @returns IPRT status code. 4255 * @param pDevExt The device extension. 4256 */ 4257 DECLINLINE(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 */ 4273 DECLINLINE(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 /** 4236 4284 * Implements the service call request. 4237 4285 * … … 4249 4297 * Find the module first in the module referenced by the calling session. 4250 4298 */ 4251 rc = RTSemFastMutexRequest(pDevExt->mtxLdr);4299 rc = supdrvLdrLock(pDevExt); 4252 4300 if (RT_SUCCESS(rc)) 4253 4301 { … … 4262 4310 break; 4263 4311 } 4264 RTSemFastMutexRelease(pDevExt->mtxLdr);4312 supdrvLdrUnlock(pDevExt); 4265 4313 4266 4314 if (pfnServiceReqHandler) -
trunk/src/VBox/HostDrivers/Support/SUPDrvInternal.h
r25278 r25307 174 174 * to actually be much lower. The values here have been determined experimentally. 175 175 */ 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 183 187 184 188 /* … … 601 605 /** Loader mutex. 602 606 * This protects pvVMMR0, pvVMMR0Entry, pImages and SUPDRVSESSION::pLdrUsage. */ 607 #ifdef SUPDRV_USE_MUTEX_FOR_LDR 608 RTSEMMUTEX mtxLdr; 609 #else 603 610 RTSEMFASTMUTEX mtxLdr; 611 #endif 604 612 605 613 /** VMM Module 'handle'.
Note:
See TracChangeset
for help on using the changeset viewer.