Changeset 6796 in vbox for trunk/src/VBox/VMM/PDMLdr.cpp
- Timestamp:
- Feb 4, 2008 6:19:58 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 27892
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/PDMLdr.cpp
r5999 r6796 27 27 #include <VBox/vmm.h> 28 28 #include <VBox/vm.h> 29 #include <VBox/uvm.h> 29 30 #include <VBox/sup.h> 30 31 #include <VBox/param.h> … … 59 60 * Internal Functions * 60 61 *******************************************************************************/ 61 static DECLCALLBACK(int) pdm r3GetImportGC(RTLDRMOD hLdrMod, const char *pszModule, const char *pszSymbol, unsigned uSymbol, RTUINTPTR *pValue, void *pvUser);62 static int pdmR3LoadR0 (PVM pVM, const char *pszFilename, const char *pszName);62 static DECLCALLBACK(int) pdmR3GetImportGC(RTLDRMOD hLdrMod, const char *pszModule, const char *pszSymbol, unsigned uSymbol, RTUINTPTR *pValue, void *pvUser); 63 static int pdmR3LoadR0U(PUVM pUVM, const char *pszFilename, const char *pszName); 63 64 static char * pdmR3FileGC(const char *pszFile); 64 65 static char * pdmR3FileR0(const char *pszFile); … … 69 70 70 71 /** 71 * Loads the VMMR0.r0 module before the VM is created. 72 * 73 * The opqaue VMMR0 module pointer is passed on to PDMR3Init later in 74 * the init process or PDMR3LdrUnloadVMMR0 in case of some init failure before PDMR3Init. 72 * Loads the VMMR0.r0 module early in the init process. 75 73 * 76 74 * @returns VBox status code. 77 * @param ppvOpaque Where to return the opaque VMMR0.r0 module handle one success. 78 * 79 * @remarks Yes, this is a kind of hacky and should go away. See @todo in VMR3Create. 80 */ 81 PDMR3DECL(int) PDMR3LdrLoadVMMR0(void **ppvOpaque) 82 { 83 *ppvOpaque = NULL; 84 85 /* 86 * Resolve the filename and allocate the module list node. 87 */ 88 char *pszFilename = pdmR3FileR0(VMMR0_MAIN_MODULE_NAME); 89 PPDMMOD pModule = (PPDMMOD)RTMemAllocZ(sizeof(*pModule) + strlen(pszFilename)); 90 if (!pModule) 91 { 92 RTMemTmpFree(pszFilename); 93 return VERR_NO_MEMORY; 94 } 95 strcpy(pModule->szName, VMMR0_MAIN_MODULE_NAME); 96 pModule->eType = PDMMOD_TYPE_R0; 97 strcpy(pModule->szFilename, pszFilename); 98 RTMemTmpFree(pszFilename); 99 100 /* 101 * Ask the support library to load it. 102 */ 103 void *pvImageBase; 104 int rc = SUPLoadModule(pModule->szFilename, pModule->szName, &pvImageBase); 105 if (RT_SUCCESS(rc)) 106 { 107 pModule->hLdrMod = NIL_RTLDRMOD; 108 pModule->ImageBase = (uintptr_t)pvImageBase; 109 *ppvOpaque = pModule; 110 111 Log(("PDMR3LdrLoadVMMR0: Loaded %s at %VGvx (%s)\n", pModule->szName, (RTGCPTR)pModule->ImageBase, pModule->szFilename)); 112 return VINF_SUCCESS; 113 } 114 115 LogRel(("PDMR3LdrLoadVMMR0: rc=%Vrc szName=%s szFilename=%s\n", rc, pModule->szName, pModule->szFilename)); 116 RTMemFree(pModule); 117 return rc; 118 } 119 120 121 /** 122 * Register the VMMR0.r0 module with the created VM or unload it if 123 * we failed to create the VM (pVM == NULL). 124 * 125 * @param pVM The VM pointer. NULL if we failed to create the VM and 126 * the module should be unloaded and freed. 127 * @param pvOpaque The value returned by PDMR3LDrLoadVMMR0(). 128 * 129 * @remarks Yes, this is a kind of hacky and should go away. See @todo in VMR3Create. 130 */ 131 PDMR3DECL(void) PDMR3LdrLoadVMMR0Part2(PVM pVM, void *pvOpaque) 132 { 133 PPDMMOD pModule = (PPDMMOD)pvOpaque; 134 AssertPtrReturnVoid(pModule); 135 136 if (pVM) 137 { 138 /* 139 * Register the R0 module loaded by PDMR3LdrLoadVMMR0 140 */ 141 Assert(!pVM->pdm.s.pModules); 142 pModule->pNext = pVM->pdm.s.pModules; 143 pVM->pdm.s.pModules = pModule; 144 } 145 else 146 { 147 /* 148 * Failed, unload the module. 149 */ 150 int rc2 = SUPFreeModule((void *)(uintptr_t)pModule->ImageBase); 151 AssertRC(rc2); 152 pModule->ImageBase = 0; 153 RTMemFree(pvOpaque); 154 } 75 * @param pUVM Pointer to the user mode VM structure. 76 */ 77 PDMR3DECL(int) PDMR3LdrLoadVMMR0U(PUVM pUVM) 78 { 79 return pdmR3LoadR0U(pUVM, NULL, VMMR0_MAIN_MODULE_NAME); 155 80 } 156 81 … … 163 88 * 164 89 * @returns VBox stutus code. 165 * @param p VM VM handle.90 * @param pUVM Pointer to the user mode VM structure. 166 91 * @param pvVMMR0Mod The opqaue returned by PDMR3LdrLoadVMMR0. 167 92 */ 168 int pdmR3LdrInit (PVM pVM)93 int pdmR3LdrInitU(PUVM pUVM) 169 94 { 170 95 #ifdef PDMLDR_FAKE_MODE … … 176 101 * Load the mandatory GC module, the VMMR0.r0 is loaded before VM creation. 177 102 */ 178 return PDMR3LoadGC(p VM, NULL, VMMGC_MAIN_MODULE_NAME);103 return PDMR3LoadGC(pUVM->pVM, NULL, VMMGC_MAIN_MODULE_NAME); 179 104 #endif 180 105 } … … 187 112 * 188 113 * @param pVM The VM handle. 189 */ 190 void pdmR3LdrTerm(PVM pVM) 114 * 115 * @remarks This is normally called twice during termination. 116 */ 117 void pdmR3LdrTermU(PUVM pUVM) 191 118 { 192 119 /* 193 120 * Free the modules. 194 121 */ 195 PPDMMOD pModule = pVM->pdm.s.pModules; 122 PPDMMOD pModule = pUVM->pdm.s.pModules; 123 pUVM->pdm.s.pModules = NULL; 196 124 while (pModule) 197 125 { … … 240 168 * process so that components can resolve GC symbols during relocation. 241 169 * 242 * @param p VM VM handle.170 * @param pUVM Pointer to the user mode VM structure. 243 171 * @param offDelta Relocation delta relative to old location. 244 172 */ 245 PDMR3DECL(void) PDMR3LdrRelocate (PVM pVM, RTGCINTPTR offDelta)173 PDMR3DECL(void) PDMR3LdrRelocateU(PUVM pUVM, RTGCINTPTR offDelta) 246 174 { 247 175 LogFlow(("PDMR3LdrRelocate: offDelta=%VGv\n", offDelta)); … … 250 178 * GC Modules. 251 179 */ 252 if (p VM->pdm.s.pModules)180 if (pUVM->pdm.s.pModules) 253 181 { 254 182 /* … … 260 188 /* pass 1 */ 261 189 PPDMMOD pCur; 262 for (pCur = p VM->pdm.s.pModules; pCur; pCur = pCur->pNext)190 for (pCur = pUVM->pdm.s.pModules; pCur; pCur = pCur->pNext) 263 191 { 264 192 if (pCur->eType == PDMMOD_TYPE_GC) 265 193 { 266 194 pCur->OldImageBase = pCur->ImageBase; 267 pCur->ImageBase = MMHyperHC2GC(p VM, pCur->pvBits);195 pCur->ImageBase = MMHyperHC2GC(pUVM->pVM, pCur->pvBits); 268 196 } 269 197 } 270 198 271 199 /* pass 2 */ 272 for (pCur = p VM->pdm.s.pModules; pCur; pCur = pCur->pNext)200 for (pCur = pUVM->pdm.s.pModules; pCur; pCur = pCur->pNext) 273 201 { 274 202 if (pCur->eType == PDMMOD_TYPE_GC) 275 203 { 276 204 PDMGETIMPORTARGS Args; 277 Args.pVM = p VM;205 Args.pVM = pUVM->pVM; 278 206 Args.pModule = pCur; 279 207 int rc = RTLdrRelocate(pCur->hLdrMod, pCur->pvBits, pCur->ImageBase, pCur->OldImageBase, 280 pdm r3GetImportGC, &Args);208 pdmR3GetImportGC, &Args); 281 209 AssertFatalMsgRC(rc, ("RTLdrRelocate failed, rc=%d\n", rc)); 282 DBGFR3ModuleRelocate(p VM, pCur->OldImageBase, pCur->ImageBase, RTLdrSize(pCur->hLdrMod),210 DBGFR3ModuleRelocate(pUVM->pVM, pCur->OldImageBase, pCur->ImageBase, RTLdrSize(pCur->hLdrMod), 283 211 pCur->szFilename, pCur->szName); 284 212 } … … 301 229 * 302 230 * @returns VBox status code. 303 * @param p VM The VM to load it into.231 * @param pUVM Pointer to the user mode VM structure. 304 232 * @param pszFilename Filename of the module binary. 305 233 * @param pszName Module name. Case sensitive and the length is limited! 306 234 */ 307 int pdmR3LoadR3 (PVM pVM, const char *pszFilename, const char *pszName)235 int pdmR3LoadR3U(PUVM pUVM, const char *pszFilename, const char *pszName) 308 236 { 309 237 /* 310 238 * Validate input. 311 239 */ 312 AssertMsg(p VM->pdm.s.offVM, ("bad init order!\n"));240 AssertMsg(pUVM->pVM->pdm.s.offVM, ("bad init order!\n")); 313 241 Assert(pszFilename); 314 242 size_t cchFilename = strlen(pszFilename); … … 325 253 * Try lookup the name and see if the module exists. 326 254 */ 327 for (pCur = p VM->pdm.s.pModules; pCur; pCur = pCur->pNext)255 for (pCur = pUVM->pdm.s.pModules; pCur; pCur = pCur->pNext) 328 256 { 329 257 if (!strcmp(pCur->szName, pszName)) … … 353 281 if (VBOX_SUCCESS(rc)) 354 282 { 355 pModule->pNext = p VM->pdm.s.pModules;356 p VM->pdm.s.pModules = pModule;283 pModule->pNext = pUVM->pdm.s.pModules; 284 pUVM->pdm.s.pModules = pModule; 357 285 return rc; 358 286 } … … 360 288 /* Something went wrong, most likely module not found. Don't consider other unlikely errors */ 361 289 RTMemFree(pModule); 362 return VMSetError(p VM, rc, RT_SRC_POS, N_("Unable to load R3 module %s"), pszFilename);290 return VMSetError(pUVM->pVM, rc, RT_SRC_POS, N_("Unable to load R3 module %s"), pszFilename); 363 291 } 364 292 … … 375 303 * @param pvUser User argument. 376 304 */ 377 static DECLCALLBACK(int) pdm r3GetImportGC(RTLDRMOD hLdrMod, const char *pszModule, const char *pszSymbol, unsigned uSymbol, RTUINTPTR *pValue, void *pvUser)305 static DECLCALLBACK(int) pdmR3GetImportGC(RTLDRMOD hLdrMod, const char *pszModule, const char *pszSymbol, unsigned uSymbol, RTUINTPTR *pValue, void *pvUser) 378 306 { 379 307 PVM pVM = ((PPDMGETIMPORTARGS)pvUser)->pVM; … … 427 355 * Search for module. 428 356 */ 429 PPDMMOD pCur = pVM->p dm.s.pModules;357 PPDMMOD pCur = pVM->pUVM->pdm.s.pModules; 430 358 while (pCur) 431 359 { … … 478 406 */ 479 407 AssertMsg(pVM->pdm.s.offVM, ("bad init order!\n")); 480 PPDMMOD pCur = pVM->p dm.s.pModules;408 PPDMMOD pCur = pVM->pUVM->pdm.s.pModules; 481 409 while (pCur) 482 410 { … … 541 469 Args.pVM = pVM; 542 470 Args.pModule = pModule; 543 rc = RTLdrGetBits(pModule->hLdrMod, pModule->pvBits, pModule->ImageBase, pdm r3GetImportGC, &Args);471 rc = RTLdrGetBits(pModule->hLdrMod, pModule->pvBits, pModule->ImageBase, pdmR3GetImportGC, &Args); 544 472 if (VBOX_SUCCESS(rc)) 545 473 { … … 547 475 * Insert the module. 548 476 */ 549 if (pVM->pdm.s.pModules) 477 PUVM pUVM = pVM->pUVM; 478 if (pUVM->pdm.s.pModules) 550 479 { 551 480 /* we don't expect this list to be very long, so rather save the tail pointer. */ 552 PPDMMOD pCur = p VM->pdm.s.pModules;481 PPDMMOD pCur = pUVM->pdm.s.pModules; 553 482 while (pCur->pNext) 554 483 pCur = pCur->pNext; … … 556 485 } 557 486 else 558 p VM->pdm.s.pModules = pModule; /* (pNext is zeroed by alloc) */487 pUVM->pdm.s.pModules = pModule; /* (pNext is zeroed by alloc) */ 559 488 Log(("PDM: GC Module at %VGvx %s (%s)\n", (RTGCPTR)pModule->ImageBase, pszName, pszFilename)); 560 489 RTMemTmpFree(pszFile); … … 587 516 * 588 517 * @returns VBox status code. 589 * @param p VM The VM to load it into.518 * @param pUVM Pointer to the user mode VM structure. 590 519 * @param pszFilename Filename of the module binary. 591 520 * @param pszName Module name. Case sensitive and the length is limited! 592 521 */ 593 static int pdmR3LoadR0 (PVM pVM, const char *pszFilename, const char *pszName)522 static int pdmR3LoadR0U(PUVM pUVM, const char *pszFilename, const char *pszName) 594 523 { 595 524 /* 596 525 * Validate input. 597 526 */ 598 AssertMsg(pVM->pdm.s.offVM, ("bad init order!\n")); 599 PPDMMOD pCur = pVM->pdm.s.pModules; 527 PPDMMOD pCur = pUVM->pdm.s.pModules; 600 528 while (pCur) 601 529 { … … 608 536 pCur = pCur->pNext; 609 537 } 610 AssertReturn(strcmp(pszName, VMMR0_MAIN_MODULE_NAME), VERR_INTERNAL_ERROR);611 538 612 539 /* … … 645 572 * Insert the module. 646 573 */ 647 if (p VM->pdm.s.pModules)574 if (pUVM->pdm.s.pModules) 648 575 { 649 576 /* we don't expect this list to be very long, so rather save the tail pointer. */ 650 PPDMMOD pCur = p VM->pdm.s.pModules;577 PPDMMOD pCur = pUVM->pdm.s.pModules; 651 578 while (pCur->pNext) 652 579 pCur = pCur->pNext; … … 654 581 } 655 582 else 656 p VM->pdm.s.pModules = pModule; /* (pNext is zeroed by alloc) */583 pUVM->pdm.s.pModules = pModule; /* (pNext is zeroed by alloc) */ 657 584 Log(("PDM: GC Module at %VGvx %s (%s)\n", (RTGCPTR)pModule->ImageBase, pszName, pszFilename)); 658 585 RTMemTmpFree(pszFile); … … 662 589 RTMemFree(pModule); 663 590 RTMemTmpFree(pszFile); 664 LogRel(("pdmR3LoadR0 : pszName=\"%s\" rc=%Vrc\n", pszName, rc));591 LogRel(("pdmR3LoadR0U: pszName=\"%s\" rc=%Vrc\n", pszName, rc)); 665 592 666 593 /* Don't consider VERR_PDM_MODULE_NAME_CLASH and VERR_NO_MEMORY above as these are very unlikely. */ 667 if (VBOX_FAILURE(rc) )668 return VMSetError(p VM, rc, RT_SRC_POS, N_("Cannot load R0 module %s"), pszFilename);594 if (VBOX_FAILURE(rc) && pUVM->pVM) /** @todo VMR3SetErrorU. */ 595 return VMSetError(pUVM->pVM, rc, RT_SRC_POS, N_("Cannot load R0 module %s"), pszFilename); 669 596 return rc; 670 597 } … … 692 619 * Find the module. 693 620 */ 694 for (PPDMMOD pModule = pVM->p dm.s.pModules; pModule; pModule = pModule->pNext)621 for (PPDMMOD pModule = pVM->pUVM->pdm.s.pModules; pModule; pModule = pModule->pNext) 695 622 { 696 623 if ( pModule->eType == PDMMOD_TYPE_R3 … … 747 674 * Find the module. 748 675 */ 749 for (PPDMMOD pModule = pVM->p dm.s.pModules; pModule; pModule = pModule->pNext)676 for (PPDMMOD pModule = pVM->pUVM->pdm.s.pModules; pModule; pModule = pModule->pNext) 750 677 { 751 678 if ( pModule->eType == PDMMOD_TYPE_R0 … … 794 721 AssertMsgReturn(!strpbrk(pszModule, "/\\:\n\r\t"), ("pszModule=%s\n", pszModule), VERR_INVALID_PARAMETER); 795 722 PPDMMOD pModule; 796 for (pModule = pVM->p dm.s.pModules; pModule; pModule = pModule->pNext)723 for (pModule = pVM->pUVM->pdm.s.pModules; pModule; pModule = pModule->pNext) 797 724 if ( pModule->eType == PDMMOD_TYPE_R0 798 725 && !strcmp(pModule->szName, pszModule)) … … 800 727 if (!pModule) 801 728 { 802 int rc = pdmR3LoadR0 (pVM, NULL, pszModule);729 int rc = pdmR3LoadR0U(pVM->pUVM, NULL, pszModule); 803 730 AssertMsgRCReturn(rc, ("pszModule=%s rc=%Vrc\n", pszModule, rc), VERR_MODULE_NOT_FOUND); 804 731 } … … 836 763 * Find the module. 837 764 */ 838 for (PPDMMOD pModule = pVM->p dm.s.pModules; pModule; pModule = pModule->pNext)765 for (PPDMMOD pModule = pVM->pUVM->pdm.s.pModules; pModule; pModule = pModule->pNext) 839 766 { 840 767 if ( pModule->eType == PDMMOD_TYPE_GC … … 891 818 AssertMsgReturn(!strpbrk(pszModule, "/\\:\n\r\t"), ("pszModule=%s\n", pszModule), VERR_INVALID_PARAMETER); 892 819 PPDMMOD pModule; 893 for (pModule = pVM->p dm.s.pModules; pModule; pModule = pModule->pNext)820 for (pModule = pVM->pUVM->pdm.s.pModules; pModule; pModule = pModule->pNext) 894 821 if ( pModule->eType == PDMMOD_TYPE_GC 895 822 && !strcmp(pModule->szName, pszModule)) … … 1078 1005 int rc = VERR_MODULE_NOT_FOUND; 1079 1006 PPDMMOD pCur; 1080 for (pCur = pVM->p dm.s.pModules; pCur; pCur = pCur->pNext)1007 for (pCur = pVM->pUVM->pdm.s.pModules; pCur; pCur = pCur->pNext) 1081 1008 { 1082 1009 /* Skip anything which isn't in GC. */ … … 1195 1122 { 1196 1123 PPDMMOD pCur; 1197 for (pCur = pVM->p dm.s.pModules; pCur; pCur = pCur->pNext)1124 for (pCur = pVM->pUVM->pdm.s.pModules; pCur; pCur = pCur->pNext) 1198 1125 { 1199 1126 int rc = pfnCallback(pVM,
Note:
See TracChangeset
for help on using the changeset viewer.