Changeset 14332 in vbox for trunk/src/VBox
- Timestamp:
- Nov 18, 2008 10:11:06 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 39535
- Location:
- trunk/src/VBox/HostDrivers/Support
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/SUPDrv.c
r13871 r14332 141 141 static int supdrvLdrAddUsage(PSUPDRVSESSION pSession, PSUPDRVLDRIMAGE pImage); 142 142 static void supdrvLdrFree(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage); 143 static int supdrvIOCtl_CallServiceModule(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPCALLSERVICE pReq); 143 144 static SUPPAGINGMODE supdrvIOCtl_GetPagingMode(void); 144 145 static SUPGIPMODE supdrvGipDeterminTscMode(PSUPDRVDEVEXT pDevExt); … … 160 161 DECLASM(int) supdrvNtWrapModuleInit(PFNRT pfnModuleInit); 161 162 DECLASM(void) supdrvNtWrapModuleTerm(PFNRT pfnModuleTerm); 163 DECLASM(int) supdrvNtWrapServiceReqHandler(PFNRT pfnServiceReqHandler, PSUPDRVSESSION pSession, uint32_t uOperation, uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr); 162 164 163 165 DECLASM(int) UNWIND_WRAP(SUPR0ComponentRegisterFactory)(PSUPDRVSESSION pSession, PCSUPDRVFACTORY pFactory); … … 1417 1419 } 1418 1420 1421 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_CALL_SERVICE(0)): 1422 { 1423 /* validate */ 1424 PSUPCALLSERVICE pReq = (PSUPCALLSERVICE)pReqHdr; 1425 Log4(("SUP_IOCTL_CALL_SERVICE: op=%u in=%u arg=%RX64 p/t=%RTproc/%RTthrd\n", 1426 pReq->u.In.uOperation, pReq->Hdr.cbIn, pReq->u.In.u64Arg, RTProcSelf(), RTThreadNativeSelf())); 1427 1428 if (pReq->Hdr.cbIn == SUP_IOCTL_CALL_SERVICE_SIZE(0)) 1429 REQ_CHECK_SIZES_EX(SUP_IOCTL_CALL_SERVICE, SUP_IOCTL_CALL_SERVICE_SIZE_IN(0), SUP_IOCTL_CALL_SERVICE_SIZE_OUT(0)); 1430 else 1431 { 1432 PSUPR0SERVICEREQHDR pSrvReq = (PSUPR0SERVICEREQHDR)&pReq->abReqPkt[0]; 1433 REQ_CHECK_EXPR_FMT(pReq->Hdr.cbIn >= SUP_IOCTL_CALL_SERVICE_SIZE(sizeof(SUPR0SERVICEREQHDR)), 1434 ("SUP_IOCTL_CALL_SERVICE: cbIn=%#x < %#lx\n", pReq->Hdr.cbIn, SUP_IOCTL_CALL_SERVICE_SIZE(sizeof(SUPR0SERVICEREQHDR)))); 1435 REQ_CHECK_EXPR(SUP_IOCTL_CALL_SERVICE, pSrvReq->u32Magic == SUPR0SERVICEREQHDR_MAGIC); 1436 REQ_CHECK_SIZES_EX(SUP_IOCTL_CALL_SERVICE, SUP_IOCTL_CALL_SERVICE_SIZE_IN(pSrvReq->cbReq), SUP_IOCTL_CALL_SERVICE_SIZE_OUT(pSrvReq->cbReq)); 1437 } 1438 REQ_CHECK_EXPR(SUP_IOCTL_CALL_SERVICE, memchr(pReq->u.In.szName, '\0', sizeof(pReq->u.In.szName))); 1439 1440 /* execute */ 1441 pReq->Hdr.rc = supdrvIOCtl_CallServiceModule(pDevExt, pSession, pReq); 1442 return 0; 1443 } 1444 1419 1445 default: 1420 1446 Log(("Unknown IOCTL %#lx\n", (long)uIOCtl)); … … 3713 3739 pImage->pfnModuleInit = NULL; 3714 3740 pImage->pfnModuleTerm = NULL; 3741 pImage->pfnServiceReqHandler = NULL; 3715 3742 pImage->uState = SUP_IOCTL_LDR_OPEN; 3716 3743 pImage->cUsage = 1; … … 3782 3809 case SUPLDRLOADEP_NOTHING: 3783 3810 break; 3811 3784 3812 case SUPLDRLOADEP_VMMR0: 3785 3813 if ( !pReq->u.In.EP.VMMR0.pvVMMR0 … … 3806 3834 } 3807 3835 break; 3836 3837 case SUPLDRLOADEP_SERVICE: 3838 if (!pReq->u.In.EP.Service.pfnServiceReq) 3839 { 3840 RTSemFastMutexRelease(pDevExt->mtxLdr); 3841 Log(("NULL pointer: pfnServiceReq=%p!\n", pReq->u.In.EP.Service.pfnServiceReq)); 3842 return VERR_INVALID_PARAMETER; 3843 } 3844 if ((uintptr_t)pReq->u.In.EP.Service.pfnServiceReq - (uintptr_t)pImage->pvImage >= pReq->u.In.cbImage) 3845 { 3846 RTSemFastMutexRelease(pDevExt->mtxLdr); 3847 Log(("Out of range (%p LB %#x): pfnServiceReq=%p, pvVMMR0EntryFast=%p or pvVMMR0EntryEx=%p is NULL!\n", 3848 pImage->pvImage, pReq->u.In.cbImage, pReq->u.In.EP.Service.pfnServiceReq)); 3849 return VERR_INVALID_PARAMETER; 3850 } 3851 if ( pReq->u.In.EP.Service.apvReserved[0] != NIL_RTR0PTR 3852 || pReq->u.In.EP.Service.apvReserved[1] != NIL_RTR0PTR 3853 || pReq->u.In.EP.Service.apvReserved[2] != NIL_RTR0PTR) 3854 { 3855 RTSemFastMutexRelease(pDevExt->mtxLdr); 3856 Log(("Out of range (%p LB %#x): apvReserved={%p,%p,%p} MBZ!\n", 3857 pImage->pvImage, pReq->u.In.cbImage, 3858 pReq->u.In.EP.Service.apvReserved[0], 3859 pReq->u.In.EP.Service.apvReserved[1], 3860 pReq->u.In.EP.Service.apvReserved[2])); 3861 return VERR_INVALID_PARAMETER; 3862 } 3863 break; 3864 3808 3865 default: 3809 3866 RTSemFastMutexRelease(pDevExt->mtxLdr); … … 3853 3910 rc = supdrvLdrSetR0EP(pDevExt, pReq->u.In.EP.VMMR0.pvVMMR0, pReq->u.In.EP.VMMR0.pvVMMR0EntryInt, 3854 3911 pReq->u.In.EP.VMMR0.pvVMMR0EntryFast, pReq->u.In.EP.VMMR0.pvVMMR0EntryEx); 3912 break; 3913 case SUPLDRLOADEP_SERVICE: 3914 pImage->pfnServiceReqHandler = pReq->u.In.EP.Service.pfnServiceReq; 3915 rc = VINF_SUCCESS; 3855 3916 break; 3856 3917 } … … 4349 4410 pImage->uState = SUP_IOCTL_LDR_FREE; 4350 4411 RTMemExecFree(pImage); 4412 } 4413 4414 4415 /** 4416 * Implements the service call request. 4417 * 4418 * @returns VBox status code. 4419 * @param pDevExt The device extension. 4420 * @param pSession The calling session. 4421 * @param pReq The request packet, valid. 4422 */ 4423 static int supdrvIOCtl_CallServiceModule(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPCALLSERVICE pReq) 4424 { 4425 #if !defined(RT_OS_WINDOWS) || defined(DEBUG) 4426 int rc; 4427 4428 /* 4429 * Find the module first in the module referenced by the calling session. 4430 */ 4431 rc = RTSemFastMutexRequest(pDevExt->mtxLdr); 4432 if (RT_SUCCESS(rc)) 4433 { 4434 PFNSUPR0SERVICEREQHANDLER pfnServiceReqHandler = NULL; 4435 PSUPDRVLDRUSAGE pUsage; 4436 4437 for (pUsage = pSession->pLdrUsage; pUsage; pUsage = pUsage->pNext) 4438 if ( pUsage->pImage->pfnServiceReqHandler 4439 && !strcmp(pUsage->pImage->szName, pReq->u.In.szName)) 4440 { 4441 pfnServiceReqHandler = pUsage->pImage->pfnServiceReqHandler; 4442 break; 4443 } 4444 RTSemFastMutexRelease(pDevExt->mtxLdr); 4445 4446 if (pfnServiceReqHandler) 4447 { 4448 /* 4449 * Call it. 4450 */ 4451 if (pReq->Hdr.cbIn == SUP_IOCTL_CALL_SERVICE_SIZE(0)) 4452 #ifdef RT_WITH_W64_UNWIND_HACK 4453 rc = supdrvNtWrapServiceReqHandler((PRNRT)pfnServiceReqHandler, pSession, pReq->u.In.uOperation, pReq->u.In.u64Arg, NULL); 4454 #else 4455 rc = pfnServiceReqHandler(pSession, pReq->u.In.uOperation, pReq->u.In.u64Arg, NULL); 4456 #endif 4457 else 4458 #ifdef RT_WITH_W64_UNWIND_HACK 4459 rc = supdrvNtWrapServiceReqHandler((PRNRT)pfnServiceReqHandler, pSession, pReq->u.In.uOperation, 4460 pReq->u.In.u64Arg, (PSUPR0SERVICEREQHDR)&pReq->abReqPkt[0]); 4461 #else 4462 rc = pfnServiceReqHandler(pSession, pReq->u.In.uOperation, pReq->u.In.u64Arg, (PSUPR0SERVICEREQHDR)&pReq->abReqPkt[0]); 4463 #endif 4464 } 4465 else 4466 rc = VERR_SUPDRV_SERVICE_NOT_FOUND; 4467 } 4468 4469 /* log it */ 4470 if ( RT_FAILURE(rc) 4471 && rc != VERR_INTERRUPTED 4472 && rc != VERR_TIMEOUT) 4473 Log(("SUP_IOCTL_CALL_SERVICE: rc=%Rrc op=%u out=%u arg=%RX64 p/t=%RTproc/%RTthrd\n", 4474 rc, pReq->u.In.uOperation, pReq->Hdr.cbOut, pReq->u.In.u64Arg, RTProcSelf(), RTThreadNativeSelf())); 4475 else 4476 Log4(("SUP_IOCTL_CALL_SERVICE: rc=%Rrc op=%u out=%u arg=%RX64 p/t=%RTproc/%RTthrd\n", 4477 rc, pReq->u.In.uOperation, pReq->Hdr.cbOut, pReq->u.In.u64Arg, RTProcSelf(), RTThreadNativeSelf())); 4478 return rc; 4479 #else /* RT_OS_WINDOWS && !DEBUG */ 4480 return VERR_NOT_IMPLEMENTED; 4481 #endif /* RT_OS_WINDOWS && !DEBUG */ 4351 4482 } 4352 4483 -
trunk/src/VBox/HostDrivers/Support/SUPDrvIOC.h
r13858 r14332 182 182 * The upper 16-bit is the major version, the the lower the minor version. 183 183 * When incompatible changes are made, the upper major number has to be changed. */ 184 #define SUPDRV_IOC_VERSION 0x000 A0000184 #define SUPDRV_IOC_VERSION 0x000a0001 185 185 186 186 /** SUP_IOCTL_COOKIE. */ … … 383 383 SUPLDRLOADEP_NOTHING = 0, 384 384 SUPLDRLOADEP_VMMR0, 385 SUPLDRLOADEP_SERVICE, 385 386 SUPLDRLOADEP_32BIT_HACK = 0x7fffffff 386 387 } SUPLDRLOADEP; … … 401 402 union 402 403 { 404 /** SUPLDRLOADEP_VMMR0. */ 403 405 struct 404 406 { 405 407 /** The module handle (i.e. address). */ 406 RTR0PTR pvVMMR0;408 RTR0PTR pvVMMR0; 407 409 /** Address of VMMR0EntryInt function. */ 408 RTR0PTR pvVMMR0EntryInt;410 RTR0PTR pvVMMR0EntryInt; 409 411 /** Address of VMMR0EntryFast function. */ 410 RTR0PTR pvVMMR0EntryFast;412 RTR0PTR pvVMMR0EntryFast; 411 413 /** Address of VMMR0EntryEx function. */ 412 RTR0PTR pvVMMR0EntryEx;414 RTR0PTR pvVMMR0EntryEx; 413 415 } VMMR0; 416 /** SUPLDRLOADEP_SERVICE. */ 417 struct 418 { 419 /** The service request handler. 420 * (PFNR0SERVICEREQHANDLER isn't defined yet.) */ 421 RTR0PTR pfnServiceReq; 422 /** Reserved, must be NIL. */ 423 RTR0PTR apvReserved[3]; 424 } Service; 414 425 } EP; 415 426 /** Address. */ … … 844 855 845 856 857 /** @name SUP_IOCTL_CALL_SERVICE 858 * Call the a ring-0 service. 859 * 860 * @todo Might have to convert this to a big request, just like 861 * SUP_IOCTL_CALL_VMMR0 862 * @{ 863 */ 864 #define SUP_IOCTL_CALL_SERVICE(cbReq) SUP_CTL_CODE_SIZE(22, SUP_IOCTL_CALL_SERVICE_SIZE(cbReq)) 865 #define SUP_IOCTL_CALL_SERVICE_SIZE(cbReq) RT_UOFFSETOF(SUPCALLSERVICE, abReqPkt[cbReq]) 866 #define SUP_IOCTL_CALL_SERVICE_SIZE_IN(cbReq) SUP_IOCTL_CALL_SERVICE_SIZE(cbReq) 867 #define SUP_IOCTL_CALL_SERVICE_SIZE_OUT(cbReq) SUP_IOCTL_CALL_SERVICE_SIZE(cbReq) 868 typedef struct SUPCALLSERVICE 869 { 870 /** The header. */ 871 SUPREQHDR Hdr; 872 union 873 { 874 struct 875 { 876 /** The service name. */ 877 char szName[28]; 878 /** Which operation to execute. */ 879 uint32_t uOperation; 880 /** Argument to use when no request packet is supplied. */ 881 uint64_t u64Arg; 882 } In; 883 } u; 884 /** The request packet passed to SUP. */ 885 uint8_t abReqPkt[1]; 886 } SUPCALLSERVICE, *PSUPCALLSERVICE; 887 /** @} */ 888 889 846 890 #pragma pack() /* paranoia */ 847 891 -
trunk/src/VBox/HostDrivers/Support/SUPDrvInternal.h
r13871 r14332 347 347 #define SUPDRV_PATCH_CODE_SIZE 0x50 348 348 /** Patch code. */ 349 uint8_t auCode[SUPDRV_PATCH_CODE_SIZE];349 uint8_t auCode[SUPDRV_PATCH_CODE_SIZE]; 350 350 /** Changed IDT entry (for parnoid UnpatchIdt()). */ 351 SUPDRVIDTE ChangedIdt;351 SUPDRVIDTE ChangedIdt; 352 352 /** Saved IDT entry. */ 353 SUPDRVIDTE SavedIdt;353 SUPDRVIDTE SavedIdt; 354 354 /** Pointer to the IDT. 355 355 * We ASSUME the IDT is not re(al)located after bootup and use this as key … … 360 360 * the(se) page(s), but we'll find that out soon enough in VBOX_STRICT mode. 361 361 */ 362 void *pvIdt;362 void *pvIdt; 363 363 /** Pointer to the IDT entry. */ 364 SUPDRVIDTE volatile *pIdtEntry;364 SUPDRVIDTE volatile *pIdtEntry; 365 365 /** Usage counter. */ 366 uint32_t volatile cUsage;366 uint32_t volatile cUsage; 367 367 /** The offset into auCode of the VMMR0Entry fixup. */ 368 uint16_t offVMMR0EntryFixup;368 uint16_t offVMMR0EntryFixup; 369 369 /** The offset into auCode of the stub function. */ 370 uint16_t offStub;370 uint16_t offStub; 371 371 /** Pointer to the next patch. */ 372 372 struct SUPDRVPATCH * volatile pNext; … … 381 381 struct SUPDRVPATCHUSAGE * volatile pNext; 382 382 /** The patch this usage applies to. */ 383 PSUPDRVPATCH pPatch;383 PSUPDRVPATCH pPatch; 384 384 /** Usage count. */ 385 uint32_t volatile cUsage;385 uint32_t volatile cUsage; 386 386 } SUPDRVPATCHUSAGE, *PSUPDRVPATCHUSAGE; 387 387 … … 418 418 { 419 419 /** The memory object handle. */ 420 RTR0MEMOBJ MemObj;420 RTR0MEMOBJ MemObj; 421 421 /** The ring-3 mapping memory object handle. */ 422 RTR0MEMOBJ MapObjR3;422 RTR0MEMOBJ MapObjR3; 423 423 /** Type of memory. */ 424 SUPDRVMEMREFTYPE eType;424 SUPDRVMEMREFTYPE eType; 425 425 } SUPDRVMEMREF, *PSUPDRVMEMREF; 426 426 … … 432 432 { 433 433 /** Pointer to the next bundle. */ 434 struct SUPDRVBUNDLE * volatile pNext;434 struct SUPDRVBUNDLE * volatile pNext; 435 435 /** Referenced memory. */ 436 SUPDRVMEMREF aMem[64];436 SUPDRVMEMREF aMem[64]; 437 437 /** Number of entries used. */ 438 438 uint32_t volatile cUsed; … … 448 448 struct SUPDRVLDRIMAGE * volatile pNext; 449 449 /** Pointer to the image. */ 450 void *pvImage;450 void *pvImage; 451 451 /** Pointer to the optional module initialization callback. */ 452 PFNR0MODULEINIT pfnModuleInit;452 PFNR0MODULEINIT pfnModuleInit; 453 453 /** Pointer to the optional module termination callback. */ 454 PFNR0MODULETERM pfnModuleTerm; 454 PFNR0MODULETERM pfnModuleTerm; 455 /** Service request handler. This is NULL for non-service modules. */ 456 PFNSUPR0SERVICEREQHANDLER pfnServiceReqHandler; 455 457 /** Size of the image. */ 456 uint32_t cbImage;458 uint32_t cbImage; 457 459 /** The offset of the symbol table. */ 458 uint32_t offSymbols;460 uint32_t offSymbols; 459 461 /** The number of entries in the symbol table. */ 460 uint32_t cSymbols;462 uint32_t cSymbols; 461 463 /** The offset of the string table. */ 462 uint32_t offStrTab;464 uint32_t offStrTab; 463 465 /** Size of the string table. */ 464 uint32_t cbStrTab;466 uint32_t cbStrTab; 465 467 /** The ldr image state. (IOCtl code of last opration.) */ 466 uint32_t uState;468 uint32_t uState; 467 469 /** Usage count. */ 468 uint32_t volatile cUsage;470 uint32_t volatile cUsage; 469 471 /** Image name. */ 470 char szName[32];472 char szName[32]; 471 473 } SUPDRVLDRIMAGE, *PSUPDRVLDRIMAGE; 472 474 … … 478 480 struct SUPDRVLDRUSAGE * volatile pNext; 479 481 /** The image. */ 480 PSUPDRVLDRIMAGE pImage;482 PSUPDRVLDRIMAGE pImage; 481 483 /** Load count. */ 482 uint32_t volatile cUsage;484 uint32_t volatile cUsage; 483 485 } SUPDRVLDRUSAGE, *PSUPDRVLDRUSAGE; 484 486 … … 490 492 { 491 493 /** Pointer to the next registration. */ 492 struct SUPDRVFACTORYREG *pNext;494 struct SUPDRVFACTORYREG *pNext; 493 495 /** Pointer to the registered factory. */ 494 PCSUPDRVFACTORY pFactory;496 PCSUPDRVFACTORY pFactory; 495 497 /** The session owning the factory. 496 498 * Used for deregistration and session cleanup. */ 497 PSUPDRVSESSION pSession;499 PSUPDRVSESSION pSession; 498 500 /** Length of the name. */ 499 size_t cchName;501 size_t cchName; 500 502 } SUPDRVFACTORYREG; 501 503 /** Pointer to a component factory registration record. */ … … 558 560 { 559 561 /** Pointer to the device extension. */ 560 PSUPDRVDEVEXT pDevExt;562 PSUPDRVDEVEXT pDevExt; 561 563 /** Session Cookie. */ 562 uint32_t u32Cookie;564 uint32_t u32Cookie; 563 565 564 566 /** Load usage records. (protected by SUPDRVDEVEXT::mtxLdr) */ 565 PSUPDRVLDRUSAGE volatile pLdrUsage;567 PSUPDRVLDRUSAGE volatile pLdrUsage; 566 568 #ifdef VBOX_WITH_IDT_PATCHING 567 569 /** Patch usage records. (protected by SUPDRVDEVEXT::SpinLock) */ 568 PSUPDRVPATCHUSAGE volatile pPatchUsage;570 PSUPDRVPATCHUSAGE volatile pPatchUsage; 569 571 #endif 570 572 /** The VM associated with the session. */ 571 PVM pVM;573 PVM pVM; 572 574 /** List of generic usage records. (protected by SUPDRVDEVEXT::SpinLock) */ 573 PSUPDRVUSAGE volatile pUsage;575 PSUPDRVUSAGE volatile pUsage; 574 576 575 577 /** Spinlock protecting the bundles and the GIP members. */ 576 RTSPINLOCK Spinlock;578 RTSPINLOCK Spinlock; 577 579 /** The ring-3 mapping of the GIP (readonly). */ 578 RTR0MEMOBJ GipMapObjR3;580 RTR0MEMOBJ GipMapObjR3; 579 581 /** Set if the session is using the GIP. */ 580 uint32_t fGipReferenced;582 uint32_t fGipReferenced; 581 583 /** Bundle of locked memory objects. */ 582 SUPDRVBUNDLE Bundle;584 SUPDRVBUNDLE Bundle; 583 585 584 586 /** The user id of the session. (Set by the OS part.) */ 585 RTUID Uid;587 RTUID Uid; 586 588 /** The group id of the session. (Set by the OS part.) */ 587 RTGID Gid;589 RTGID Gid; 588 590 /** The process (id) of the session. */ 589 RTPROCESS Process;591 RTPROCESS Process; 590 592 /** Which process this session is associated with. 591 593 * This is NIL_RTR0PROCESS for kernel sessions and valid for user ones. */ 592 RTR0PROCESS R0Process;594 RTR0PROCESS R0Process; 593 595 #if defined(RT_OS_DARWIN) 594 596 /** Pointer to the associated org_virtualbox_SupDrvClient object. */ 595 void *pvSupDrvClient;597 void *pvSupDrvClient; 596 598 /** Whether this session has been opened or not. */ 597 bool fOpened;599 bool fOpened; 598 600 #endif 599 601 #if defined(RT_OS_OS2) 600 602 /** The system file number of this session. */ 601 uint16_t sfn;602 uint16_t Alignment; /**< Alignment */603 uint16_t sfn; 604 uint16_t Alignment; /**< Alignment */ 603 605 #endif 604 606 #if defined(RT_OS_DARWIN) || defined(RT_OS_OS2) || defined(RT_OS_SOLARIS) 605 607 /** Pointer to the next session with the same hash. */ 606 PSUPDRVSESSION pNextHash;608 PSUPDRVSESSION pNextHash; 607 609 #endif 608 610 } SUPDRVSESSION; … … 616 618 /** Spinlock to serialize the initialization, 617 619 * usage counting and destruction of the IDT entry override and objects. */ 618 RTSPINLOCK Spinlock;620 RTSPINLOCK Spinlock; 619 621 620 622 #ifdef VBOX_WITH_IDT_PATCHING 621 623 /** List of patches. */ 622 PSUPDRVPATCH volatile pIdtPatches;624 PSUPDRVPATCH volatile pIdtPatches; 623 625 /** List of patches Free. */ 624 PSUPDRVPATCH volatile pIdtPatchesFree;626 PSUPDRVPATCH volatile pIdtPatchesFree; 625 627 #endif 626 628 627 629 /** List of registered objects. Protected by the spinlock. */ 628 PSUPDRVOBJ volatile pObjs;630 PSUPDRVOBJ volatile pObjs; 629 631 /** List of free object usage records. */ 630 PSUPDRVUSAGE volatile pUsageFree;632 PSUPDRVUSAGE volatile pUsageFree; 631 633 632 634 /** Global cookie. */ 633 uint32_t u32Cookie;635 uint32_t u32Cookie; 634 636 635 637 /** The IDT entry number. 636 638 * Only valid if pIdtPatches is set. */ 637 uint8_t volatile u8Idt;639 uint8_t volatile u8Idt; 638 640 639 641 /** Loader mutex. 640 642 * This protects pvVMMR0, pvVMMR0Entry, pImages and SUPDRVSESSION::pLdrUsage. */ 641 RTSEMFASTMUTEX mtxLdr;643 RTSEMFASTMUTEX mtxLdr; 642 644 643 645 /** VMM Module 'handle'. 644 646 * 0 if the code VMM isn't loaded and Idt are nops. */ 645 void * volatile pvVMMR0;647 void * volatile pvVMMR0; 646 648 /** VMMR0EntryInt() pointer. */ 647 DECLR0CALLBACKMEMBER(int, pfnVMMR0EntryInt, (PVM pVM, unsigned uOperation, void *pvArg));649 DECLR0CALLBACKMEMBER(int, pfnVMMR0EntryInt, (PVM pVM, unsigned uOperation, void *pvArg)); 648 650 /** VMMR0EntryFast() pointer. */ 649 DECLR0CALLBACKMEMBER(void, pfnVMMR0EntryFast, (PVM pVM, unsigned idCpu, unsigned uOperation));651 DECLR0CALLBACKMEMBER(void, pfnVMMR0EntryFast, (PVM pVM, unsigned idCpu, unsigned uOperation)); 650 652 /** VMMR0EntryEx() pointer. */ 651 DECLR0CALLBACKMEMBER(int, pfnVMMR0EntryEx, (PVM pVM, unsigned uOperation, PSUPVMMR0REQHDR pReq, uint64_t u64Arg, PSUPDRVSESSION pSession));653 DECLR0CALLBACKMEMBER(int, pfnVMMR0EntryEx, (PVM pVM, unsigned uOperation, PSUPVMMR0REQHDR pReq, uint64_t u64Arg, PSUPDRVSESSION pSession)); 652 654 653 655 /** Linked list of loaded code. */ 654 PSUPDRVLDRIMAGE volatile pLdrImages;656 PSUPDRVLDRIMAGE volatile pLdrImages; 655 657 656 658 /** GIP mutex. 657 659 * Any changes to any of the GIP members requires ownership of this mutex, 658 660 * except on driver init and termination. */ 659 RTSEMFASTMUTEX mtxGip;661 RTSEMFASTMUTEX mtxGip; 660 662 /** Pointer to the Global Info Page (GIP). */ 661 PSUPGLOBALINFOPAGE pGip;663 PSUPGLOBALINFOPAGE pGip; 662 664 /** The physical address of the GIP. */ 663 RTHCPHYS HCPhysGip;665 RTHCPHYS HCPhysGip; 664 666 /** Number of processes using the GIP. 665 667 * (The updates are suspend while cGipUsers is 0.)*/ 666 uint32_t volatile cGipUsers;668 uint32_t volatile cGipUsers; 667 669 /** The ring-0 memory object handle for the GIP page. */ 668 RTR0MEMOBJ GipMemObj;670 RTR0MEMOBJ GipMemObj; 669 671 /** The GIP timer handle. */ 670 PRTTIMER pGipTimer;672 PRTTIMER pGipTimer; 671 673 /** If non-zero we've successfully called RTTimerRequestSystemGranularity(). */ 672 uint32_t u32SystemTimerGranularityGrant;674 uint32_t u32SystemTimerGranularityGrant; 673 675 /** The CPU id of the GIP master. 674 676 * This CPU is responsible for the updating the common GIP data. */ 675 RTCPUID volatile idGipMaster;677 RTCPUID volatile idGipMaster; 676 678 677 679 #ifdef RT_OS_WINDOWS 678 680 /* Callback object returned by ExCreateCallback. */ 679 PCALLBACK_OBJECT pObjPowerCallback;681 PCALLBACK_OBJECT pObjPowerCallback; 680 682 /* Callback handle returned by ExRegisterCallback. */ 681 PVOID hPowerCallback;683 PVOID hPowerCallback; 682 684 #endif 683 685 684 686 /** Component factory mutex. 685 687 * This protects pComponentFactoryHead and component factory querying. */ 686 RTSEMFASTMUTEX mtxComponentFactory;688 RTSEMFASTMUTEX mtxComponentFactory; 687 689 /** The head of the list of registered component factories. */ 688 PSUPDRVFACTORYREG pComponentFactoryHead;690 PSUPDRVFACTORYREG pComponentFactoryHead; 689 691 } SUPDRVDEVEXT; 690 692 -
trunk/src/VBox/HostDrivers/Support/SUPLib.cpp
r13871 r14332 151 151 *******************************************************************************/ 152 152 static int supInitFake(PSUPDRVSESSION *ppSession); 153 static int supLoadModule(const char *pszFilename, const char *pszModule, void **ppvImageBase);153 static int supLoadModule(const char *pszFilename, const char *pszModule, const char *pszSrvReqHandler, void **ppvImageBase); 154 154 #ifdef VBOX_WITH_IDT_PATCHING 155 155 static int supInstallIDTE(void); … … 679 679 680 680 681 SUPR3DECL(int) SUPR3CallR0Service(const char *pszService, size_t cchService, uint32_t uOperation, uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr) 682 { 683 AssertReturn(cchService < RT_SIZEOFMEMB(SUPCALLSERVICE, u.In.szName), VERR_INVALID_PARAMETER); 684 Assert(strlen(pszService) == cchService); 685 686 /* fake */ 687 if (RT_UNLIKELY(g_u32FakeMode)) 688 return VERR_NOT_SUPPORTED; 689 690 int rc; 691 if (!pReqHdr) 692 { 693 /* no data. */ 694 SUPCALLSERVICE Req; 695 Req.Hdr.u32Cookie = g_u32Cookie; 696 Req.Hdr.u32SessionCookie = g_u32SessionCookie; 697 Req.Hdr.cbIn = SUP_IOCTL_CALL_SERVICE_SIZE_IN(0); 698 Req.Hdr.cbOut = SUP_IOCTL_CALL_SERVICE_SIZE_OUT(0); 699 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; 700 Req.Hdr.rc = VERR_INTERNAL_ERROR; 701 memcpy(Req.u.In.szName, pszService, cchService); 702 Req.u.In.szName[cchService] = '\0'; 703 Req.u.In.uOperation = uOperation; 704 Req.u.In.u64Arg = u64Arg; 705 rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_CALL_SERVICE(0), &Req, SUP_IOCTL_CALL_SERVICE_SIZE(0)); 706 if (RT_SUCCESS(rc)) 707 rc = Req.Hdr.rc; 708 } 709 else if (SUP_IOCTL_CALL_SERVICE_SIZE(pReqHdr->cbReq) < _4K) /* FreeBSD won't copy more than 4K. */ 710 { 711 AssertPtrReturn(pReqHdr, VERR_INVALID_POINTER); 712 AssertReturn(pReqHdr->u32Magic == SUPR0SERVICEREQHDR_MAGIC, VERR_INVALID_MAGIC); 713 const size_t cbReq = pReqHdr->cbReq; 714 715 PSUPCALLSERVICE pReq = (PSUPCALLSERVICE)alloca(SUP_IOCTL_CALL_SERVICE_SIZE(cbReq)); 716 pReq->Hdr.u32Cookie = g_u32Cookie; 717 pReq->Hdr.u32SessionCookie = g_u32SessionCookie; 718 pReq->Hdr.cbIn = SUP_IOCTL_CALL_SERVICE_SIZE_IN(cbReq); 719 pReq->Hdr.cbOut = SUP_IOCTL_CALL_SERVICE_SIZE_OUT(cbReq); 720 pReq->Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; 721 pReq->Hdr.rc = VERR_INTERNAL_ERROR; 722 memcpy(pReq->u.In.szName, pszService, cchService); 723 pReq->u.In.szName[cchService] = '\0'; 724 pReq->u.In.uOperation = uOperation; 725 pReq->u.In.u64Arg = u64Arg; 726 memcpy(&pReq->abReqPkt[0], pReqHdr, cbReq); 727 rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_CALL_SERVICE(cbReq), pReq, SUP_IOCTL_CALL_SERVICE_SIZE(cbReq)); 728 if (RT_SUCCESS(rc)) 729 rc = pReq->Hdr.rc; 730 memcpy(pReqHdr, &pReq->abReqPkt[0], cbReq); 731 } 732 else /** @todo may have to remove the size limits one this request... */ 733 AssertMsgFailedReturn(("cbReq=%#x\n", pReqHdr->cbReq), VERR_INTERNAL_ERROR); 734 return rc; 735 } 736 737 681 738 SUPR3DECL(int) SUPPageAlloc(size_t cPages, void **ppvPages) 682 739 { … … 1180 1237 * If it's VMMR0.r0 we need to install the IDTE. 1181 1238 */ 1182 rc = supLoadModule(pszFilename, pszModule, ppvImageBase);1239 rc = supLoadModule(pszFilename, pszModule, NULL, ppvImageBase); 1183 1240 #ifdef VBOX_WITH_IDT_PATCHING 1184 1241 if ( RT_SUCCESS(rc) … … 1193 1250 else 1194 1251 LogRel(("SUPLoadModule: Verification of \"%s\" failed, rc=%Rrc\n", rc)); 1252 return rc; 1253 } 1254 1255 1256 SUPR3DECL(int) SUPR3LoadServiceModule(const char *pszFilename, const char *pszModule, 1257 const char *pszSrvReqHandler, void **ppvImageBase) 1258 { 1259 int rc = VINF_SUCCESS; 1260 AssertPtrReturn(pszSrvReqHandler, VERR_INVALID_PARAMETER); 1261 1262 #ifdef VBOX_WITH_HARDENING 1263 /* 1264 * Check that the module can be trusted. 1265 */ 1266 rc = supR3HardenedVerifyFile(pszFilename, false /* fFatal */); 1267 #endif 1268 if (RT_SUCCESS(rc)) 1269 { 1270 /* 1271 * Load the module. 1272 * If it's VMMR0.r0 we need to install the IDTE. 1273 */ 1274 rc = supLoadModule(pszFilename, pszModule, pszSrvReqHandler, ppvImageBase); 1275 } 1276 else 1277 LogRel(("SUPR3LoadServiceModule: Verification of \"%s\" failed, rc=%Rrc\n", rc)); 1195 1278 return rc; 1196 1279 } … … 1569 1652 * @param pszFilename Name of the VMMR0 image file 1570 1653 */ 1571 static int supLoadModule(const char *pszFilename, const char *pszModule, void **ppvImageBase)1654 static int supLoadModule(const char *pszFilename, const char *pszModule, const char *pszSrvReqHandler, void **ppvImageBase) 1572 1655 { 1573 1656 /* … … 1580 1663 1581 1664 const bool fIsVMMR0 = !strcmp(pszModule, "VMMR0.r0"); 1665 AssertReturn(!pszSrvReqHandler || !fIsVMMR0, VERR_INTERNAL_ERROR); 1582 1666 *ppvImageBase = NULL; 1583 1667 … … 1649 1733 RTUINTPTR VMMR0EntryFast = 0; 1650 1734 RTUINTPTR VMMR0EntryEx = 0; 1735 RTUINTPTR SrvReqHandler = 0; 1651 1736 RTUINTPTR ModuleInit = 0; 1652 1737 RTUINTPTR ModuleTerm = 0; … … 1659 1744 rc = RTLdrGetSymbolEx(hLdrMod, &pLoadReq->u.In.achImage[0], (uintptr_t)OpenReq.u.Out.pvImageBase, "VMMR0EntryEx", &VMMR0EntryEx); 1660 1745 } 1746 else if (pszSrvReqHandler) 1747 rc = RTLdrGetSymbolEx(hLdrMod, &pLoadReq->u.In.achImage[0], (uintptr_t)OpenReq.u.Out.pvImageBase, pszSrvReqHandler, &SrvReqHandler); 1661 1748 if (RT_SUCCESS(rc)) 1662 1749 { … … 1704 1791 pLoadReq->u.In.EP.VMMR0.pvVMMR0EntryFast= (RTR0PTR)VMMR0EntryFast; 1705 1792 pLoadReq->u.In.EP.VMMR0.pvVMMR0EntryEx = (RTR0PTR)VMMR0EntryEx; 1793 } 1794 else if (pszSrvReqHandler) 1795 { 1796 pLoadReq->u.In.eEPType = SUPLDRLOADEP_SERVICE; 1797 pLoadReq->u.In.EP.Service.pfnServiceReq = (RTR0PTR)SrvReqHandler; 1798 pLoadReq->u.In.EP.Service.apvReserved[0] = NIL_RTR0PTR; 1799 pLoadReq->u.In.EP.Service.apvReserved[1] = NIL_RTR0PTR; 1800 pLoadReq->u.In.EP.Service.apvReserved[2] = NIL_RTR0PTR; 1706 1801 } 1707 1802 else -
trunk/src/VBox/HostDrivers/Support/win/SUPDrvA-win.asm
r13858 r14332 294 294 295 295 296 ;; 297 ; @cproto DECLASM(int) supdrvNtWrapServiceReqHandler(PFNRT pfnServiceReqHandler, PSUPDRVSESSION pSession, uint32_t uOperation, uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr); 298 ; 299 ; @param pfnSerivceReqHandler rcx 300 ; @param pSession rdx 301 ; @param uOperation r8 302 ; @param u64Arg r9 303 ; @param pReq [rsp + 28h] / [rbp + 30h] 304 ; 305 BEGINPROC supdrvNtWrapServiceReqHandler 306 NtWrapProlog supdrvNtWrapServiceReqHandler 307 NtWrapCreateMarker 308 309 mov rax, rcx 310 mov rcx, rdx 311 mov rdx, r8 312 mov r8, r9 313 mov r9, [rbp + 30h] 314 call rax 315 316 NtWrapDestroyMarker 317 NtWrapEpilog supdrvNtWrapServiceReqHandler 318 ENDPROC supdrvNtWrapServiceReqHandler 319 320 296 321 %endif ; RT_ARCH_AMD64 297 322 %endif ; RT_WITH_W64_UNWIND_HACK
Note:
See TracChangeset
for help on using the changeset viewer.