Skip to content

Commit 180a554

Browse files
committed
RTTI: Add background task back and make it cancellable
If the background task gets stuck, this is the commit to ponder at
1 parent 2a23d37 commit 180a554

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

plugins/rtti/itanium.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,13 +659,16 @@ ItaniumRTTIProcessor::ItaniumRTTIProcessor(const Ref<BinaryView> &view, bool use
659659

660660
void ItaniumRTTIProcessor::ProcessRTTI()
661661
{
662+
auto bgTask = new BackgroundTask("Scanning for Itanium RTTI...", true);
662663
auto start_time = std::chrono::high_resolution_clock::now();
663664
auto addrSize = m_view->GetAddressSize();
664665
uint64_t maxTypeInfoSize = TypeInfoSize(m_view);
665666

666667
auto scan = [&](const Ref<Section> &section) {
667668
for (uint64_t currAddr = section->GetStart(); currAddr <= section->GetEnd() - maxTypeInfoSize; currAddr += addrSize)
668669
{
670+
if (bgTask->IsCancelled())
671+
break;
669672
try
670673
{
671674
if (auto classInfo = ProcessRTTI(currAddr))
@@ -732,6 +735,7 @@ void ItaniumRTTIProcessor::ProcessRTTI()
732735
);
733736
}
734737

738+
bgTask->Finish();
735739
auto end_time = std::chrono::high_resolution_clock::now();
736740
std::chrono::duration<double> elapsed_time = end_time - start_time;
737741
m_logger->LogDebug("ProcessRTTI took %f seconds", elapsed_time.count());
@@ -740,6 +744,7 @@ void ItaniumRTTIProcessor::ProcessRTTI()
740744

741745
void ItaniumRTTIProcessor::ProcessVFT()
742746
{
747+
auto bgTask = new BackgroundTask("Scanning for Itanium VFTs...", true);
743748
BinaryReader optReader = BinaryReader(m_view);
744749
std::map<uint64_t, std::set<uint64_t>> vftMap = {};
745750
std::map<uint64_t, std::optional<VirtualFunctionTableInfo>> vftFinishedMap = {};
@@ -811,12 +816,15 @@ void ItaniumRTTIProcessor::ProcessVFT()
811816

812817
for (const auto &[coLocatorAddr, vftAddrs]: vftMap)
813818
{
819+
if (bgTask->IsCancelled())
820+
break;
814821
for (const auto& vftAddr: vftAddrs)
815822
{
816823
populateVftEntries(coLocatorAddr, vftAddr);
817824
}
818825
}
819826

827+
bgTask->Finish();
820828
auto end_time = std::chrono::high_resolution_clock::now();
821829
std::chrono::duration<double> elapsed_time = end_time - start_time;
822830
m_logger->LogDebug("ProcessVFT took %f seconds", elapsed_time.count());

plugins/rtti/microsoft.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ MicrosoftRTTIProcessor::MicrosoftRTTIProcessor(const Ref<BinaryView> &view, bool
620620

621621
void MicrosoftRTTIProcessor::ProcessRTTI()
622622
{
623+
auto bgTask = new BackgroundTask("Scanning for Microsoft RTTI...", true);
623624
auto start_time = std::chrono::high_resolution_clock::now();
624625
uint64_t startAddr = m_view->GetOriginalImageBase();
625626
uint64_t endAddr = m_view->GetEnd();
@@ -630,6 +631,8 @@ void MicrosoftRTTIProcessor::ProcessRTTI()
630631
for (uint64_t coLocatorAddr = segment->GetStart(); coLocatorAddr < segment->GetEnd() - 0x18;
631632
coLocatorAddr += addrSize)
632633
{
634+
if (bgTask->IsCancelled())
635+
break;
633636
optReader.Seek(coLocatorAddr);
634637
uint32_t sigVal = optReader.Read32();
635638
if (sigVal == COL_SIG_REV1)
@@ -683,6 +686,7 @@ void MicrosoftRTTIProcessor::ProcessRTTI()
683686
}
684687
}
685688

689+
bgTask->Finish();
686690
auto end_time = std::chrono::high_resolution_clock::now();
687691
std::chrono::duration<double> elapsed_time = end_time - start_time;
688692
m_logger->LogDebug("ProcessRTTI took %f seconds", elapsed_time.count());
@@ -691,6 +695,7 @@ void MicrosoftRTTIProcessor::ProcessRTTI()
691695

692696
void MicrosoftRTTIProcessor::ProcessVFT()
693697
{
698+
auto bgTask = new BackgroundTask("Scanning for Microsoft RTTI...", true);
694699
std::map<uint64_t, uint64_t> vftMap = {};
695700
std::map<uint64_t, std::optional<VirtualFunctionTableInfo>> vftFinishedMap = {};
696701
auto start_time = std::chrono::high_resolution_clock::now();
@@ -712,6 +717,8 @@ void MicrosoftRTTIProcessor::ProcessVFT()
712717
uint64_t endAddr = segment->GetEnd();
713718
for (uint64_t vtableAddr = startAddr; vtableAddr < endAddr - 0x18; vtableAddr += addrSize)
714719
{
720+
if (bgTask->IsCancelled())
721+
break;
715722
optReader.Seek(vtableAddr);
716723
uint64_t coLocatorAddr = optReader.ReadPointer();
717724
auto coLocator = m_classInfo.find(coLocatorAddr);
@@ -806,6 +813,7 @@ void MicrosoftRTTIProcessor::ProcessVFT()
806813
for (const auto &[coLocatorAddr, _]: vftMap)
807814
ProcessClassAndBases(coLocatorAddr);
808815

816+
bgTask->Finish();
809817
auto end_time = std::chrono::high_resolution_clock::now();
810818
std::chrono::duration<double> elapsed_time = end_time - start_time;
811819
m_logger->LogDebug("ProcessVFT took %f seconds", elapsed_time.count());

0 commit comments

Comments
 (0)