Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions Source/Windows/ARM64EC/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,21 @@ void InitSyscalls() {
PatchCallChecker();
}

void HandleImageMap(uint64_t Address, bool MainImage = false) {
bool HandleImageMap(uint64_t Address, bool MainImage = false) {
auto* Nt = RtlImageNtHeader(reinterpret_cast<HMODULE>(Address));
if (!Nt || Nt->Signature != IMAGE_NT_SIGNATURE) {
return false;
}

fextl::string ModulePath = FEX::Windows::GetSectionFilePath(Address);
fextl::string ModuleName = fextl::string {FEX::Windows::BaseName(ModulePath)};
InvalidationTracker->HandleImageMap(ModuleName, Address);
ImageTracker->HandleImageMap(ModulePath, Address, MainImage);
return true;
}

bool IsLikelyMapViewNotification(uint64_t Address, uint64_t Size, ULONG Prot) {
return Address && Size && !(Address + Size < Address) && Prot;
}

void HandleImageUnmap(uint64_t Address, uint64_t Size) {
Expand Down Expand Up @@ -838,7 +848,14 @@ NTSTATUS NotifyMapViewOfSection(void* Unk1, void* Address, void* Unk2, SIZE_T Si

{
std::scoped_lock Lock(ThreadCreationMutex);
HandleImageMap(reinterpret_cast<uint64_t>(Address));
const uint64_t GuestAddress = reinterpret_cast<uint64_t>(Address);
const uint64_t GuestSize = static_cast<uint64_t>(Size);

if (!HandleImageMap(GuestAddress) && IsLikelyMapViewNotification(GuestAddress, GuestSize, Prot)) {
LogMan::Msg::DFmt("[WOWNT] arm64ec.mapview.generic addr=0x{:X} size=0x{:X} prot=0x{:X} alloc=0x{:X}",
GuestAddress, GuestSize, Prot, AllocType);
InvalidationTracker->HandleMemoryProtectionNotification(GuestAddress, GuestSize, Prot);
}
}


Expand Down
21 changes: 19 additions & 2 deletions Source/Windows/WOW64/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,21 @@ bool IsAddressInJit(uint64_t Address) {
return Thread->CTX->IsAddressInCodeBuffer(Thread, Address);
}

void HandleImageMap(uint64_t Address, bool MainImage = false) {
bool HandleImageMap(uint64_t Address, bool MainImage = false) {
auto* Nt = RtlImageNtHeader(reinterpret_cast<HMODULE>(Address));
if (!Nt || Nt->Signature != IMAGE_NT_SIGNATURE) {
return false;
}

fextl::string ModulePath = FEX::Windows::GetSectionFilePath(Address);
fextl::string ModuleName = fextl::string {FEX::Windows::BaseName(ModulePath)};
InvalidationTracker->HandleImageMap(ModuleName, Address);
ImageTracker->HandleImageMap(ModulePath, Address, MainImage);
return true;
}

bool IsLikelyMapViewNotification(uint64_t Address, uint64_t Size, ULONG Prot) {
return Address && Size && !(Address + Size < Address) && Prot;
}

void HandleImageUnmap(uint64_t Address, uint64_t Size) {
Expand Down Expand Up @@ -1006,7 +1016,14 @@ void BTCpuNotifyMemoryFree(void* Address, SIZE_T Size, ULONG FreeType, BOOL Afte

NTSTATUS BTCpuNotifyMapViewOfSection(void* Unk1, void* Address, void* Unk2, SIZE_T Size, ULONG AllocType, ULONG Prot) {
std::scoped_lock Lock(ThreadCreationMutex);
HandleImageMap(reinterpret_cast<uint64_t>(Address));
const uint64_t GuestAddress = reinterpret_cast<uint64_t>(Address);
const uint64_t GuestSize = static_cast<uint64_t>(Size);

if (!HandleImageMap(GuestAddress) && IsLikelyMapViewNotification(GuestAddress, GuestSize, Prot)) {
LogMan::Msg::DFmt("[WOWNT] wow64.mapview.generic addr=0x{:X} size=0x{:X} prot=0x{:X} alloc=0x{:X}",
GuestAddress, GuestSize, Prot, AllocType);
InvalidationTracker->HandleMemoryProtectionNotification(GuestAddress, GuestSize, Prot);
}
return STATUS_SUCCESS;
}

Expand Down