Skip to content

Commit 842e8e4

Browse files
committed
Windows/ImageTracker: Wire up LoadCache and EnableLoadedSection
The lazy code loading refactor replaced LoadData with the new LoadCache/EnableLoadedSection API but left the Windows path as TODOs. Implement the wiring: LoadAOTImages now calls LoadCache + RegisterMappedCodeBuffer for each mapped cache file, and HandleImageMap calls EnableLoadedSection (with nullptr thread since lazy mapping is not yet implemented on Windows).
1 parent 9fed892 commit 842e8e4

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

Source/Windows/Common/ImageTracker.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ FEXCore::ExecutableFileSectionInfo ImageTracker::HandleImageMap(std::string_view
171171
}
172172

173173
auto AOTImage = AOTImages.find(ID);
174-
if (AOTImage != AOTImages.end()) {
175-
// TODO: CodeCache::EnableLoadedSection
174+
if (AOTImage != AOTImages.end() && AOTImage->second.CacheFile) {
175+
CTX.GetCodeCache().EnableLoadedSection(nullptr, *AOTImage->second.CacheFile, ImageInfo->SectionInfo);
176176
}
177177
}
178178

@@ -276,9 +276,16 @@ void ImageTracker::LoadAOTImages(MappedImageInfo& ImageInfo) {
276276
UniqueId.resize(AnsiLength);
277277
RtlUnicodeToMultiByteN(UniqueId.data(), AnsiLength, NULL, Info->FileName, Info->FileNameLength);
278278

279-
AOTImages[UniqueId] = {.Data = static_cast<std::byte*>(LoadAddress)};
280-
// TODO: CodeCache::LoadCache, CodeCache::RegisterMappedCodeBuffer
281-
LogMan::Msg::IFmt("Loaded cache: {}", UniqueId);
279+
auto CacheSpan = std::span {static_cast<std::byte*>(LoadAddress), MappedSize};
280+
auto MappedCache = CTX.GetCodeCache().LoadCache(CacheSpan, ImageInfo.Info, ImageInfo.SectionInfo.FileStartVA);
281+
if (MappedCache) {
282+
CTX.GetCodeCache().RegisterMappedCodeBuffer(*MappedCache);
283+
AOTImages[UniqueId] = {.CacheFile = std::move(MappedCache)};
284+
LogMan::Msg::IFmt("Loaded cache: {}", UniqueId);
285+
} else {
286+
NtUnmapViewOfSection(NtCurrentProcess(), LoadAddress);
287+
LogMan::Msg::EFmt("Failed to load cache: {}", UniqueId);
288+
}
282289
}
283290
}
284291
}

Source/Windows/Common/ImageTracker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class ImageTracker : public FEXCore::CodeMapOpener {
5656
};
5757

5858
struct AOTImageInfo {
59-
std::byte* Data;
59+
fextl::unique_ptr<FEXCore::MappedCodeCacheFile> CacheFile;
6060
};
6161

6262
void LoadAOTImages(MappedImageInfo& Info);

0 commit comments

Comments
 (0)