| 496 | void clearJitBlock(const std::vector<void*>& jitOps); |
| 497 | |
| 498 | void KMemory::removeCodeBlock(U32 address, DecodedOp* op, bool clearOps) { |
| 499 | DecodedOp* blockOp = op->blockStart; |
| 500 | U32 blockLen = blockOp->blockLen; |
| 501 | U32 blockOpCount = blockOp->blockOpCount; |
| 502 | DecodedOp* nextOp = blockOp; |
| 503 | KThread* thread = KThread::currentThread(); |
| 504 | DecodedOp* currentOp = thread->memory->getDecodedOp(thread->cpu->getEipAddress()); |
| 505 | void* pMem = (void*)blockOp->pfnJitCode; |
| 506 | U32 jitLen = 0; |
| 507 | |
| 508 | std::vector<void*> jitOps; |
| 509 | for (U32 i = 0; i < blockOpCount; i++) { |
| 510 | if (nextOp->blockStart != blockOp && nextOp->inst != Done) { |
| 511 | kpanic("KMemory::removeCodeBlock nextOp->blockStart"); |
| 512 | } |
| 513 | nextOp->blockStart = nullptr; |
| 514 | nextOp->blockOpCount = 0; |
| 515 | nextOp->blockLen = 0; |
| 516 | nextOp->runCount = 0; |
| 517 | nextOp->pfn = NormalCPU::getFunctionForOp(nextOp); |
| 518 | nextOp->flags &= ~OP_FLAG_JIT; |
| 519 | if (nextOp->pfnJitCode) { |
| 520 | jitOps.push_back(nextOp->pfnJitCode); |
| 521 | } |
| 522 | jitLen += nextOp->jitLen; |
| 523 | nextOp->pfnJitCode = nullptr; |
| 524 | nextOp->jitLen = 0; |
| 525 | nextOp = nextOp->next; |
| 526 | } |
| 527 | if (jitOps.size()) { |
| 528 | clearJitBlock(jitOps); |
| 529 | } |
| 530 | if (clearOps) { |
| 531 | data->opCache.remove(address, blockLen, false); |
| 532 | } |
| 533 | if (pMem) { |
| 534 | data->codeMemory.free(pMem); |
| 535 | } |
| 536 | #ifdef _DEBUG1 |
| 537 | klog_fmt("removed active code block eip = %x - %x host %llx - %llx", thread->cpu->getEipAddress(), thread->cpu->getEipAddress() + blockLen, (U64)pMem, (U64)pMem + jitLen); |
| 538 | #endif |
| 539 | } |
| 540 | #endif |
| 541 | |
| 542 | #if defined(BOXEDWINE_JIT) |
no test coverage detected