Skip to content

Commit ca01528

Browse files
WeiN76LQhWeiN76LQh
authored andcommitted
[SharedCache] Add a section for an image header
Similar to what is discussed in PR Vector35#6513 its useful to be able to see where an image header is as sometimes you want to inspect the load commands. Without a section its not very obvious where the header is. The naming scheme of `${imageName}::__header` was chosen based on the naming choice of the DSC header.
1 parent eeb1402 commit ca01528

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

view/sharedcache/core/SharedCache.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,8 +2422,28 @@ void SharedCache::InitializeHeader(
24222422
if (settings && settings->Contains("loader.dsc.processFunctionStarts"))
24232423
applyFunctionStarts = settings->Get<bool>("loader.dsc.processFunctionStarts", view);
24242424

2425+
// For identifying the span of memory containing the image header if it
2426+
// hasn't already been initialized
2427+
uint64_t headerRegionEnd = 0;
2428+
MemoryRegion const* headerRegion = nullptr;
2429+
for (const auto& region : regionsToLoad)
2430+
{
2431+
if (region->start != header.textBase)
2432+
continue;
2433+
2434+
if (!MemoryRegionIsHeaderInitialized(lock, *region))
2435+
{
2436+
headerRegion = region;
2437+
headerRegionEnd = region->start + region->size;
2438+
}
2439+
break;
2440+
}
2441+
24252442
for (size_t i = 0; i < header.sections.size(); i++)
24262443
{
2444+
if (headerRegion && header.sections[i].addr < headerRegionEnd)
2445+
headerRegionEnd = header.sections[i].addr;
2446+
24272447
bool skip = false;
24282448
for (const auto& region : regionsToLoad)
24292449
{
@@ -2549,6 +2569,22 @@ void SharedCache::InitializeHeader(
25492569
type, header.sections[i].align);
25502570
}
25512571

2572+
// If the memory region containing the header is not initialized and was
2573+
// found then add a section for it
2574+
if (headerRegion && headerRegionEnd > headerRegion->start)
2575+
{
2576+
for (const auto& region : regionsToLoad)
2577+
{
2578+
if (region->start != header.textBase)
2579+
continue;
2580+
2581+
const auto headerSectionName = fmt::format("{}::__header", header.identifierPrefix);
2582+
view->AddUserSection(headerSectionName, region->start, headerRegionEnd - region->start,
2583+
SectionSemanticsForRegion(*region));
2584+
break;
2585+
}
2586+
}
2587+
25522588
auto typeLib = view->GetTypeLibrary(header.installName);
25532589

25542590
BinaryReader virtualReader(view);

0 commit comments

Comments
 (0)