- Timestamp:
- Mar 13, 2015 3:53:54 PM (10 years ago)
- Location:
- trunk/src/VBox/VMM/VMMR3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMR3/PATM.cpp
r54728 r54746 4584 4584 /* Full breakdown for the GUI. */ 4585 4585 STAMR3RegisterF(pVM, &pVM->patm.s.pStatsHC[pPatchRec->patch.uPatchIdx], STAMTYPE_RATIO_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_GOOD_BAD, PATMPatchType(pVM, &pPatchRec->patch), 4586 "/PATM/Stats/PatchBD/0x%RRv", pPatchRec->patch.pPrivInstrGC); 4587 STAMR3RegisterF(pVM, &pPatchRec->patch.cbPatchBlockSize,STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, NULL, "/PATM/Stats/PatchBD/0x%RRv/cbPatchBlockSize", pPatchRec->patch.pPrivInstrGC); 4588 STAMR3RegisterF(pVM, &pPatchRec->patch.cbPatchJump, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, NULL, "/PATM/Stats/PatchBD/0x%RRv/cbPatchJump", pPatchRec->patch.pPrivInstrGC); 4589 STAMR3RegisterF(pVM, &pPatchRec->patch.cbPrivInstr, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, NULL, "/PATM/Stats/PatchBD/0x%RRv/cbPrivInstr", pPatchRec->patch.pPrivInstrGC); 4590 STAMR3RegisterF(pVM, &pPatchRec->patch.cCodeWrites, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PATM/Stats/PatchBD/0x%RRv/cCodeWrites", pPatchRec->patch.pPrivInstrGC); 4591 STAMR3RegisterF(pVM, &pPatchRec->patch.cInvalidWrites, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PATM/Stats/PatchBD/0x%RRv/cInvalidWrites", pPatchRec->patch.pPrivInstrGC); 4592 STAMR3RegisterF(pVM, &pPatchRec->patch.cTraps, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PATM/Stats/PatchBD/0x%RRv/cTraps", pPatchRec->patch.pPrivInstrGC); 4593 STAMR3RegisterF(pVM, &pPatchRec->patch.flags, STAMTYPE_X32, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE, NULL, "/PATM/Stats/PatchBD/0x%RRv/flags", pPatchRec->patch.pPrivInstrGC); 4594 STAMR3RegisterF(pVM, &pPatchRec->patch.nrJumpRecs, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PATM/Stats/PatchBD/0x%RRv/nrJumpRecs", pPatchRec->patch.pPrivInstrGC); 4595 STAMR3RegisterF(pVM, &pPatchRec->patch.nrFixups, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PATM/Stats/PatchBD/0x%RRv/nrFixups", pPatchRec->patch.pPrivInstrGC); 4596 STAMR3RegisterF(pVM, &pPatchRec->patch.opcode, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PATM/Stats/PatchBD/0x%RRv/opcode", pPatchRec->patch.pPrivInstrGC); 4597 STAMR3RegisterF(pVM, &pPatchRec->patch.uOldState, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE, NULL, "/PATM/Stats/PatchBD/0x%RRv/uOldState", pPatchRec->patch.pPrivInstrGC); 4598 STAMR3RegisterF(pVM, &pPatchRec->patch.uOpMode, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE, NULL, "/PATM/Stats/PatchBD/0x%RRv/uOpMode", pPatchRec->patch.pPrivInstrGC); 4586 "/PATM/PatchBD/0x%RRv", pPatchRec->patch.pPrivInstrGC); 4587 STAMR3RegisterF(pVM, &pPatchRec->patch.pPatchBlockOffset,STAMTYPE_X32, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, NULL, "/PATM/PatchBD/0x%RRv/offPatchBlock", pPatchRec->patch.pPrivInstrGC); 4588 STAMR3RegisterF(pVM, &pPatchRec->patch.cbPatchBlockSize,STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, NULL, "/PATM/PatchBD/0x%RRv/cbPatchBlockSize", pPatchRec->patch.pPrivInstrGC); 4589 STAMR3RegisterF(pVM, &pPatchRec->patch.cbPatchJump, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, NULL, "/PATM/PatchBD/0x%RRv/cbPatchJump", pPatchRec->patch.pPrivInstrGC); 4590 STAMR3RegisterF(pVM, &pPatchRec->patch.cbPrivInstr, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, NULL, "/PATM/PatchBD/0x%RRv/cbPrivInstr", pPatchRec->patch.pPrivInstrGC); 4591 STAMR3RegisterF(pVM, &pPatchRec->patch.cCodeWrites, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PATM/PatchBD/0x%RRv/cCodeWrites", pPatchRec->patch.pPrivInstrGC); 4592 STAMR3RegisterF(pVM, &pPatchRec->patch.cInvalidWrites, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PATM/PatchBD/0x%RRv/cInvalidWrites", pPatchRec->patch.pPrivInstrGC); 4593 STAMR3RegisterF(pVM, &pPatchRec->patch.cTraps, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PATM/PatchBD/0x%RRv/cTraps", pPatchRec->patch.pPrivInstrGC); 4594 STAMR3RegisterF(pVM, &pPatchRec->patch.flags, STAMTYPE_X64, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE, NULL, "/PATM/PatchBD/0x%RRv/flags", pPatchRec->patch.pPrivInstrGC); 4595 STAMR3RegisterF(pVM, &pPatchRec->patch.nrJumpRecs, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PATM/PatchBD/0x%RRv/nrJumpRecs", pPatchRec->patch.pPrivInstrGC); 4596 STAMR3RegisterF(pVM, &pPatchRec->patch.nrFixups, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PATM/PatchBD/0x%RRv/nrFixups", pPatchRec->patch.pPrivInstrGC); 4597 STAMR3RegisterF(pVM, &pPatchRec->patch.opcode, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PATM/PatchBD/0x%RRv/opcode", pPatchRec->patch.pPrivInstrGC); 4598 STAMR3RegisterF(pVM, &pPatchRec->patch.uOldState, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE, NULL, "/PATM/PatchBD/0x%RRv/uOldState", pPatchRec->patch.pPrivInstrGC); 4599 STAMR3RegisterF(pVM, &pPatchRec->patch.uOpMode, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE, NULL, "/PATM/PatchBD/0x%RRv/uOpMode", pPatchRec->patch.pPrivInstrGC); 4599 4600 /// @todo change the state to be a callback so we can get a state mnemonic instead. 4600 STAMR3RegisterF(pVM, &pPatchRec->patch.uState, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE, NULL, "/PATM/ Stats/PatchBD/0x%RRv/uState", pPatchRec->patch.pPrivInstrGC);4601 STAMR3RegisterF(pVM, &pPatchRec->patch.uState, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE, NULL, "/PATM/PatchBD/0x%RRv/uState", pPatchRec->patch.pPrivInstrGC); 4601 4602 #endif 4602 4603 } … … 5637 5638 { 5638 5639 STAMR3DeregisterF(pVM->pUVM, "/PATM/Stats/Patch/0x%RRv", pPatchRec->patch.pPrivInstrGC); 5639 STAMR3DeregisterF(pVM->pUVM, "/PATM/ Stats/PatchBD/0x%RRv*", pPatchRec->patch.pPrivInstrGC);5640 STAMR3DeregisterF(pVM->pUVM, "/PATM/PatchBD/0x%RRv*", pPatchRec->patch.pPrivInstrGC); 5640 5641 } 5641 5642 #endif … … 5750 5751 { 5751 5752 STAMR3DeregisterF(pVM->pUVM, "/PATM/Stats/Patch/0x%RRv", pPatchRec->patch.pPrivInstrGC); 5752 STAMR3DeregisterF(pVM->pUVM, "/PATM/ Stats/PatchBD/0x%RRv*", pPatchRec->patch.pPrivInstrGC);5753 STAMR3DeregisterF(pVM->pUVM, "/PATM/PatchBD/0x%RRv*", pPatchRec->patch.pPrivInstrGC); 5753 5754 } 5754 5755 #endif -
trunk/src/VBox/VMM/VMMR3/PATMPatch.cpp
r54714 r54746 7 7 8 8 /* 9 * Copyright (C) 2006-201 3Oracle Corporation9 * Copyright (C) 2006-2015 Oracle Corporation 10 10 * 11 11 * This file is part of VirtualBox Open Source Edition (OSE), as … … 65 65 * Defined Constants And Macros * 66 66 *******************************************************************************/ 67 #define PATCHGEN_PROLOG_NODEF(pVM, pPatch) \ 67 /** Value to use when not sure about the patch size. */ 68 #define PATCHGEN_DEF_SIZE 256 69 70 #define PATCHGEN_PROLOG_NODEF(pVM, pPatch, a_cbMaxEmit) \ 68 71 do { \ 69 pPB = PATCHCODE_PTR_HC(pPatch) + pPatch->uCurPatchOffset; \ 70 if (pPB + 256 >= pVM->patm.s.pPatchMemHC + pVM->patm.s.cbPatchMem) \ 72 cbGivenPatchSize = (a_cbMaxEmit) + 16U /*jmp++*/; \ 73 if (RT_LIKELY((pPatch)->pPatchBlockOffset + pPatch->uCurPatchOffset + cbGivenPatchSize < pVM->patm.s.cbPatchMem)) \ 74 pPB = PATCHCODE_PTR_HC(pPatch) + pPatch->uCurPatchOffset; \ 75 else \ 71 76 { \ 72 77 pVM->patm.s.fOutOfMemory = true; \ 73 Assert(pPB + 256 >= pVM->patm.s.pPatchMemHC + pVM->patm.s.cbPatchMem); \ 78 AssertMsgFailed(("offPatch=%#x + offEmit=%#x + a_cbMaxEmit=%#x + jmp --> cbTotalWithFudge=%#x >= cbPatchMem=%#x", \ 79 (pPatch)->pPatchBlockOffset, pPatch->uCurPatchOffset, a_cbMaxEmit, \ 80 (pPatch)->pPatchBlockOffset + pPatch->uCurPatchOffset + cbGivenPatchSize, pVM->patm.s.cbPatchMem)); \ 74 81 return VERR_NO_MEMORY; \ 75 82 } \ 76 83 } while (0) 77 84 78 #define PATCHGEN_PROLOG(pVM, pPatch ) \85 #define PATCHGEN_PROLOG(pVM, pPatch, a_cbMaxEmit) \ 79 86 uint8_t *pPB; \ 80 PATCHGEN_PROLOG_NODEF(pVM, pPatch) 81 82 #define PATCHGEN_EPILOG(pPatch, size) \ 87 uint32_t cbGivenPatchSize; \ 88 PATCHGEN_PROLOG_NODEF(pVM, pPatch, a_cbMaxEmit) 89 90 #define PATCHGEN_EPILOG(pPatch, a_cbActual) \ 83 91 do { \ 84 Assert(size <= 640); \ 85 pPatch->uCurPatchOffset += size; \ 92 AssertMsg((a_cbActual) <= cbGivenPatchSize, ("a_cbActual=%#x cbGivenPatchSize=%#x\n", a_cbActual, cbGivenPatchSize)); \ 93 Assert((a_cbActual) <= 640); \ 94 pPatch->uCurPatchOffset += (a_cbActual); \ 86 95 } while (0) 87 96 … … 441 450 int patmPatchGenDuplicate(PVM pVM, PPATCHINFO pPatch, DISCPUSTATE *pCpu, RCPTRTYPE(uint8_t *) pCurInstrGC) 442 451 { 443 int rc = VINF_SUCCESS;444 PATCHGEN_PROLOG(pVM, pPatch);445 446 452 uint32_t const cbInstrShutUpGcc = pCpu->cbInstr; 447 rc = patmPatchReadBytes(pVM, pPB, pCurInstrGC, cbInstrShutUpGcc); 453 PATCHGEN_PROLOG(pVM, pPatch, cbInstrShutUpGcc); 454 455 int rc = patmPatchReadBytes(pVM, pPB, pCurInstrGC, cbInstrShutUpGcc); 448 456 AssertRC(rc); 449 457 PATCHGEN_EPILOG(pPatch, cbInstrShutUpGcc); … … 455 463 uint32_t size; 456 464 PATMCALLINFO callInfo; 457 458 PATCHGEN_PROLOG(pVM, pPatch); 465 PCPATCHASMRECORD pPatchAsmRec = EMIsRawRing1Enabled(pVM) ? &g_patmIretRing1Record : &g_patmIretRecord; 466 467 PATCHGEN_PROLOG(pVM, pPatch, pPatchAsmRec->cbFunction); 459 468 460 469 AssertMsg(fSizeOverride == false, ("operand size override!!\n")); 461 470 callInfo.pCurInstrGC = pCurInstrGC; 462 471 463 if (EMIsRawRing1Enabled(pVM)) 464 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmIretRing1Record, 0, false, &callInfo); 465 else 466 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmIretRecord, 0, false, &callInfo); 472 size = patmPatchGenCode(pVM, pPatch, pPB, pPatchAsmRec, 0, false, &callInfo); 467 473 468 474 PATCHGEN_EPILOG(pPatch, size); … … 473 479 { 474 480 uint32_t size; 475 PATCHGEN_PROLOG(pVM, pPatch );481 PATCHGEN_PROLOG(pVM, pPatch, g_patmCliRecord.cbFunction); 476 482 477 483 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmCliRecord, 0, false); … … 490 496 491 497 Log(("patmPatchGenSti at %RRv; next %RRv\n", pCurInstrGC, pNextInstrGC)); 492 PATCHGEN_PROLOG(pVM, pPatch );498 PATCHGEN_PROLOG(pVM, pPatch, g_patmStiRecord.cbFunction); 493 499 callInfo.pNextInstrGC = pNextInstrGC; 494 500 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmStiRecord, 0, false, &callInfo); … … 503 509 uint32_t size; 504 510 PATMCALLINFO callInfo; 505 506 PATCHGEN_PROLOG(pVM, pPatch); 511 PCPATCHASMRECORD pPatchAsmRec; 512 if (fSizeOverride == true) 513 pPatchAsmRec = fGenJumpBack ? &g_patmPopf16Record : &g_patmPopf16Record_NoExit; 514 else 515 pPatchAsmRec = fGenJumpBack ? &g_patmPopf32Record : &g_patmPopf32Record_NoExit; 516 517 PATCHGEN_PROLOG(pVM, pPatch, pPatchAsmRec->cbFunction); 507 518 508 519 callInfo.pNextInstrGC = pReturnAddrGC; … … 512 523 /* Note: keep IOPL in mind when changing any of this!! (see comments in PATMA.asm, PATMPopf32Replacement) */ 513 524 if (fSizeOverride == true) 514 {515 525 Log(("operand size override!!\n")); 516 size = patmPatchGenCode(pVM, pPatch, pPB, (fGenJumpBack) ? &g_patmPopf16Record : &g_patmPopf16Record_NoExit , pReturnAddrGC, fGenJumpBack, &callInfo); 517 } 518 else 519 { 520 size = patmPatchGenCode(pVM, pPatch, pPB, (fGenJumpBack) ? &g_patmPopf32Record : &g_patmPopf32Record_NoExit, pReturnAddrGC, fGenJumpBack, &callInfo); 521 } 526 size = patmPatchGenCode(pVM, pPatch, pPB, pPatchAsmRec, pReturnAddrGC, fGenJumpBack, &callInfo); 522 527 523 528 PATCHGEN_EPILOG(pPatch, size); … … 529 534 { 530 535 uint32_t size; 531 PATCHGEN_PROLOG(pVM, pPatch); 532 533 if (fSizeOverride == true) 534 { 535 Log(("operand size override!!\n")); 536 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmPushf16Record, 0, false); 537 } 538 else 539 { 540 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmPushf32Record, 0, false); 541 } 536 PCPATCHASMRECORD pPatchAsmRec = fSizeOverride == true ? &g_patmPushf16Record : &g_patmPushf32Record; 537 PATCHGEN_PROLOG(pVM, pPatch, pPatchAsmRec->cbFunction); 538 539 size = patmPatchGenCode(pVM, pPatch, pPB, pPatchAsmRec, 0, false); 542 540 543 541 PATCHGEN_EPILOG(pPatch, size); … … 548 546 { 549 547 uint32_t size; 550 PATCHGEN_PROLOG(pVM, pPatch );548 PATCHGEN_PROLOG(pVM, pPatch, g_patmPushCSRecord.cbFunction); 551 549 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmPushCSRecord, 0, false); 552 550 PATCHGEN_EPILOG(pPatch, size); … … 558 556 uint32_t size = 0; 559 557 PCPATCHASMRECORD pPatchAsmRec; 560 561 PATCHGEN_PROLOG(pVM, pPatch);562 563 558 switch (opcode) 564 559 { … … 581 576 Assert(pPatchAsmRec->offSizeOverride && pPatchAsmRec->offRelJump); 582 577 578 PATCHGEN_PROLOG(pVM, pPatch, pPatchAsmRec->cbFunction); 583 579 Log(("PatchGenLoop %d jump %d to %08x offrel=%d\n", opcode, pPatch->nrJumpRecs, pTargetGC, pPatchAsmRec->offRelJump)); 584 580 … … 602 598 { 603 599 uint32_t offset = 0; 604 PATCHGEN_PROLOG(pVM, pPatch );600 PATCHGEN_PROLOG(pVM, pPatch, PATCHGEN_DEF_SIZE); 605 601 606 602 // internal relative jumps from patch code to patch code; no relocation record required … … 713 709 AssertRCReturn(rc, rc); 714 710 715 PATCHGEN_PROLOG(pVM, pPatch );711 PATCHGEN_PROLOG(pVM, pPatch, PATCHGEN_DEF_SIZE); 716 712 /* 2: We must push the target address onto the stack before appending the indirect call code. */ 717 713 … … 773 769 774 770 /* 3: Generate code to lookup address in our local cache; call hypervisor PATM code if it can't be located. */ 775 PATCHGEN_PROLOG_NODEF(pVM, pPatch); 771 PCPATCHASMRECORD pPatchAsmRec = fIndirect ? &g_patmCallIndirectRecord : &g_patmCallRecord; 772 PATCHGEN_PROLOG_NODEF(pVM, pPatch, pPatchAsmRec->cbFunction); 776 773 callInfo.pReturnGC = pCurInstrGC + pCpu->cbInstr; 777 774 callInfo.pTargetGC = (fIndirect) ? 0xDEADBEEF : pTargetGC; 778 size = patmPatchGenCode(pVM, pPatch, pPB, (fIndirect) ? &g_patmCallIndirectRecord : &g_patmCallRecord, 0, false, &callInfo);775 size = patmPatchGenCode(pVM, pPatch, pPB, pPatchAsmRec, 0, false, &callInfo); 779 776 PATCHGEN_EPILOG(pPatch, size); 780 777 … … 811 808 AssertRCReturn(rc, rc); 812 809 813 PATCHGEN_PROLOG(pVM, pPatch );810 PATCHGEN_PROLOG(pVM, pPatch, PATCHGEN_DEF_SIZE); 814 811 /* 2: We must push the target address onto the stack before appending the indirect call code. */ 815 812 … … 850 847 851 848 /* 3: Generate code to lookup address in our local cache; call hypervisor PATM code if it can't be located. */ 852 PATCHGEN_PROLOG_NODEF(pVM, pPatch );849 PATCHGEN_PROLOG_NODEF(pVM, pPatch, g_patmJumpIndirectRecord.cbFunction); 853 850 callInfo.pReturnGC = pCurInstrGC + pCpu->cbInstr; 854 851 callInfo.pTargetGC = 0xDEADBEEF; … … 872 869 int patmPatchGenRet(PVM pVM, PPATCHINFO pPatch, DISCPUSTATE *pCpu, RCPTRTYPE(uint8_t *) pCurInstrGC) 873 870 { 874 int size = 0, rc;875 871 RTRCPTR pPatchRetInstrGC; 876 872 … … 892 888 /* Jump back to the original instruction if IF is set again. */ 893 889 Assert(!patmFindActivePatchByEntrypoint(pVM, pCurInstrGC)); 894 rc = patmPatchGenCheckIF(pVM, pPatch, pCurInstrGC);890 int rc = patmPatchGenCheckIF(pVM, pPatch, pCurInstrGC); 895 891 AssertRCReturn(rc, rc); 896 892 897 893 /* align this block properly to make sure the jump table will not be misaligned. */ 898 PATCHGEN_PROLOG(pVM, pPatch );899 size = (RTHCUINTPTR)pPB & 3;894 PATCHGEN_PROLOG(pVM, pPatch, 4); 895 uint32_t size = (RTHCUINTPTR)pPB & 3; 900 896 if (size) 901 897 size = 4 - size; 902 898 903 for ( int i=0;i<size;i++)899 for (uint32_t i = 0; i < size; i++) 904 900 pPB[i] = 0x90; /* nop */ 905 901 PATCHGEN_EPILOG(pPatch, size); 906 902 907 PATCHGEN_PROLOG_NODEF(pVM, pPatch );903 PATCHGEN_PROLOG_NODEF(pVM, pPatch, g_patmRetRecord.cbFunction); 908 904 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmRetRecord, 0, false); 909 905 PATCHGEN_EPILOG(pPatch, size); … … 931 927 int patmPatchGenGlobalFunctions(PVM pVM, PPATCHINFO pPatch) 932 928 { 933 int size = 0;934 935 929 pVM->patm.s.pfnHelperCallGC = PATCHCODE_PTR_GC(pPatch) + pPatch->uCurPatchOffset; 936 PATCHGEN_PROLOG(pVM, pPatch );937 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmLookupAndCallRecord, 0, false);930 PATCHGEN_PROLOG(pVM, pPatch, g_patmLookupAndCallRecord.cbFunction); 931 uint32_t size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmLookupAndCallRecord, 0, false); 938 932 PATCHGEN_EPILOG(pPatch, size); 939 933 … … 942 936 943 937 pVM->patm.s.pfnHelperRetGC = PATCHCODE_PTR_GC(pPatch) + pPatch->uCurPatchOffset; 944 PATCHGEN_PROLOG_NODEF(pVM, pPatch );938 PATCHGEN_PROLOG_NODEF(pVM, pPatch, g_patmRetFunctionRecord.cbFunction); 945 939 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmRetFunctionRecord, 0, false); 946 940 PATCHGEN_EPILOG(pPatch, size); … … 950 944 951 945 pVM->patm.s.pfnHelperJumpGC = PATCHCODE_PTR_GC(pPatch) + pPatch->uCurPatchOffset; 952 PATCHGEN_PROLOG_NODEF(pVM, pPatch );946 PATCHGEN_PROLOG_NODEF(pVM, pPatch, g_patmLookupAndJumpRecord.cbFunction); 953 947 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmLookupAndJumpRecord, 0, false); 954 948 PATCHGEN_EPILOG(pPatch, size); … … 958 952 959 953 pVM->patm.s.pfnHelperIretGC = PATCHCODE_PTR_GC(pPatch) + pPatch->uCurPatchOffset; 960 PATCHGEN_PROLOG_NODEF(pVM, pPatch );954 PATCHGEN_PROLOG_NODEF(pVM, pPatch, g_patmIretFunctionRecord.cbFunction); 961 955 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmIretFunctionRecord, 0, false); 962 956 PATCHGEN_EPILOG(pPatch, size); … … 980 974 int patmPatchGenIllegalInstr(PVM pVM, PPATCHINFO pPatch) 981 975 { 982 PATCHGEN_PROLOG(pVM, pPatch );976 PATCHGEN_PROLOG(pVM, pPatch, 1); 983 977 984 978 pPB[0] = 0xCC; … … 1001 995 uint32_t size; 1002 996 1003 PATCHGEN_PROLOG(pVM, pPatch );997 PATCHGEN_PROLOG(pVM, pPatch, g_patmCheckIFRecord.cbFunction); 1004 998 1005 999 /* Add lookup record for patch to guest address translation */ … … 1024 1018 int patmPatchGenSetPIF(PVM pVM, PPATCHINFO pPatch, RTRCPTR pInstrGC) 1025 1019 { 1026 PATCHGEN_PROLOG(pVM, pPatch );1020 PATCHGEN_PROLOG(pVM, pPatch, g_patmSetPIFRecord.cbFunction); 1027 1021 1028 1022 /* Add lookup record for patch to guest address translation */ 1029 1023 patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pInstrGC, PATM_LOOKUP_PATCH2GUEST); 1030 1024 1031 int size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmSetPIFRecord, 0, false);1025 uint32_t size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmSetPIFRecord, 0, false); 1032 1026 PATCHGEN_EPILOG(pPatch, size); 1033 1027 return VINF_SUCCESS; … … 1045 1039 int patmPatchGenClearPIF(PVM pVM, PPATCHINFO pPatch, RTRCPTR pInstrGC) 1046 1040 { 1047 PATCHGEN_PROLOG(pVM, pPatch );1041 PATCHGEN_PROLOG(pVM, pPatch, g_patmSetPIFRecord.cbFunction); 1048 1042 1049 1043 /* Add lookup record for patch to guest address translation */ 1050 1044 patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pInstrGC, PATM_LOOKUP_PATCH2GUEST); 1051 1045 1052 int size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmClearPIFRecord, 0, false);1046 uint32_t size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmClearPIFRecord, 0, false); 1053 1047 PATCHGEN_EPILOG(pPatch, size); 1054 1048 return VINF_SUCCESS; … … 1066 1060 int patmPatchGenClearInhibitIRQ(PVM pVM, PPATCHINFO pPatch, RTRCPTR pNextInstrGC) 1067 1061 { 1068 int size;1069 1062 PATMCALLINFO callInfo; 1070 1071 PATCHGEN_PROLOG(pVM, pPatch); 1063 PCPATCHASMRECORD pPatchAsmRec = pPatch->flags & PATMFL_DUPLICATE_FUNCTION 1064 ? &g_patmClearInhibitIRQContIF0Record : &g_patmClearInhibitIRQFaultIF0Record; 1065 PATCHGEN_PROLOG(pVM, pPatch, pPatchAsmRec->cbFunction); 1072 1066 1073 1067 Assert((pPatch->flags & (PATMFL_GENERATE_JUMPTOGUEST|PATMFL_DUPLICATE_FUNCTION)) != (PATMFL_GENERATE_JUMPTOGUEST|PATMFL_DUPLICATE_FUNCTION)); … … 1078 1072 callInfo.pNextInstrGC = pNextInstrGC; 1079 1073 1080 if (pPatch->flags & PATMFL_DUPLICATE_FUNCTION) 1081 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmClearInhibitIRQContIF0Record, 0, false, &callInfo); 1082 else 1083 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmClearInhibitIRQFaultIF0Record, 0, false, &callInfo); 1074 uint32_t size = patmPatchGenCode(pVM, pPatch, pPB, pPatchAsmRec, 0, false, &callInfo); 1084 1075 1085 1076 PATCHGEN_EPILOG(pPatch, size); … … 1106 1097 { 1107 1098 uint32_t size; 1108 PATCHGEN_PROLOG(pVM, pPatch); 1099 PCPATCHASMRECORD pPatchAsmRec = pPatch->flags & PATMFL_INTHANDLER_WITH_ERRORCODE 1100 ? &g_patmIntEntryRecordErrorCode : &g_patmIntEntryRecord; 1101 PATCHGEN_PROLOG(pVM, pPatch, pPatchAsmRec->cbFunction); 1109 1102 1110 1103 /* Add lookup record for patch to guest address translation */ … … 1112 1105 1113 1106 /* Generate entrypoint for the interrupt handler (correcting CS in the interrupt stack frame) */ 1114 size = patmPatchGenCode(pVM, pPatch, pPB, 1115 (pPatch->flags & PATMFL_INTHANDLER_WITH_ERRORCODE) ? &g_patmIntEntryRecordErrorCode : &g_patmIntEntryRecord, 1116 0, false); 1107 size = patmPatchGenCode(pVM, pPatch, pPB, pPatchAsmRec, 0, false); 1117 1108 1118 1109 PATCHGEN_EPILOG(pPatch, size); … … 1137 1128 { 1138 1129 uint32_t size; 1130 PCPATCHASMRECORD pPatchAsmRec = (pPatch->flags & PATMFL_TRAPHANDLER_WITH_ERRORCODE) 1131 ? &g_patmTrapEntryRecordErrorCode : &g_patmTrapEntryRecord; 1139 1132 1140 1133 Assert(!EMIsRawRing1Enabled(pVM)); 1141 1134 1142 PATCHGEN_PROLOG(pVM, pPatch );1135 PATCHGEN_PROLOG(pVM, pPatch, pPatchAsmRec->cbFunction); 1143 1136 1144 1137 /* Add lookup record for patch to guest address translation */ … … 1146 1139 1147 1140 /* Generate entrypoint for the trap handler (correcting CS in the interrupt stack frame) */ 1148 size = patmPatchGenCode(pVM, pPatch, pPB, 1149 (pPatch->flags & PATMFL_TRAPHANDLER_WITH_ERRORCODE) ? &g_patmTrapEntryRecordErrorCode : &g_patmTrapEntryRecord, 1150 pTrapHandlerGC, true); 1141 size = patmPatchGenCode(pVM, pPatch, pPB, pPatchAsmRec, pTrapHandlerGC, true); 1151 1142 PATCHGEN_EPILOG(pPatch, size); 1152 1143 … … 1159 1150 uint32_t size; 1160 1151 1161 PATCHGEN_PROLOG(pVM, pPatch );1152 PATCHGEN_PROLOG(pVM, pPatch, g_patmStatsRecord.cbFunction); 1162 1153 1163 1154 /* Add lookup record for stats code -> guest handler. */ … … 1186 1177 uint32_t offset; 1187 1178 1188 PATCHGEN_PROLOG(pVM, pPatch );1179 PATCHGEN_PROLOG(pVM, pPatch, PATCHGEN_DEF_SIZE); 1189 1180 1190 1181 mod = 0; //effective address (only) … … 1236 1227 uint32_t offset; 1237 1228 1238 PATCHGEN_PROLOG(pVM, pPatch );1229 PATCHGEN_PROLOG(pVM, pPatch, PATCHGEN_DEF_SIZE); 1239 1230 1240 1231 mod = 0; //effective address (only) … … 1302 1293 Assert(pPatch->flags & PATMFL_CODE32); 1303 1294 1304 PATCHGEN_PROLOG(pVM, pPatch );1295 PATCHGEN_PROLOG(pVM, pPatch, g_patmClearPIFRecord.cbFunction + 2 + g_patmMovFromSSRecord.cbFunction + 2 + g_patmSetPIFRecord.cbFunction); 1305 1296 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmClearPIFRecord, 0, false); 1306 1297 PATCHGEN_EPILOG(pPatch, size); 1307 1298 1308 1299 /* push ss */ 1309 PATCHGEN_PROLOG_NODEF(pVM, pPatch );1300 PATCHGEN_PROLOG_NODEF(pVM, pPatch, 2); 1310 1301 offset = 0; 1311 1302 if (pCpu->fPrefix & DISPREFIX_OPSIZE) … … 1315 1306 1316 1307 /* checks and corrects RPL of pushed ss*/ 1317 PATCHGEN_PROLOG_NODEF(pVM, pPatch );1308 PATCHGEN_PROLOG_NODEF(pVM, pPatch, g_patmMovFromSSRecord.cbFunction); 1318 1309 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmMovFromSSRecord, 0, false); 1319 1310 PATCHGEN_EPILOG(pPatch, size); 1320 1311 1321 1312 /* pop general purpose register */ 1322 PATCHGEN_PROLOG_NODEF(pVM, pPatch );1313 PATCHGEN_PROLOG_NODEF(pVM, pPatch, 2); 1323 1314 offset = 0; 1324 1315 if (pCpu->fPrefix & DISPREFIX_OPSIZE) … … 1328 1319 1329 1320 1330 PATCHGEN_PROLOG_NODEF(pVM, pPatch );1321 PATCHGEN_PROLOG_NODEF(pVM, pPatch, g_patmSetPIFRecord.cbFunction); 1331 1322 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmSetPIFRecord, 0, false); 1332 1323 PATCHGEN_EPILOG(pPatch, size); … … 1355 1346 Assert(pCpu->fPrefix == DISPREFIX_NONE || pCpu->fPrefix == DISPREFIX_OPSIZE); 1356 1347 1357 PATCHGEN_PROLOG(pVM, pPatch );1348 PATCHGEN_PROLOG(pVM, pPatch, PATCHGEN_DEF_SIZE); 1358 1349 1359 1350 if (pCpu->Param1.fUse == DISUSE_REG_GEN32 || pCpu->Param1.fUse == DISUSE_REG_GEN16) … … 1484 1475 //58 pop eax 1485 1476 1486 PATCHGEN_PROLOG(pVM, pPatch );1477 PATCHGEN_PROLOG(pVM, pPatch, PATCHGEN_DEF_SIZE); 1487 1478 pPB[offset++] = 0x50; // push eax 1488 1479 pPB[offset++] = 0x52; // push edx … … 1543 1534 { 1544 1535 uint32_t size; 1545 PATCHGEN_PROLOG(pVM, pPatch );1536 PATCHGEN_PROLOG(pVM, pPatch, g_patmCpuidRecord.cbFunction); 1546 1537 1547 1538 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmCpuidRecord, 0, false); … … 1574 1565 } 1575 1566 1576 PATCHGEN_PROLOG(pVM, pPatch );1567 PATCHGEN_PROLOG(pVM, pPatch, PATMJumpToGuest_IF1Record.cbFunction); 1577 1568 1578 1569 /* Add lookup record for patch to guest address translation */ … … 1595 1586 1596 1587 Assert(PATMIsPatchGCAddr(pVM, pPatchAddrGC)); 1597 PATCHGEN_PROLOG(pVM, pPatch );1588 PATCHGEN_PROLOG(pVM, pPatch, SIZEOF_NEARJUMP32); 1598 1589 1599 1590 if (fAddLookupRecord)
Note:
See TracChangeset
for help on using the changeset viewer.