Skip to content

Commit

Permalink
Wine: Add support for magic fex+wine shm path
Browse files Browse the repository at this point in the history
Fallback to the previous path if it doesn't exist.
  • Loading branch information
Sonicadvance1 committed Jan 23, 2025
1 parent 832f9c2 commit a9b28f9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
35 changes: 34 additions & 1 deletion Source/Windows/Common/Profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,44 @@ __attribute__((naked)) uint64_t linux_getpid() {
}

uint32_t StatAlloc::FrontendAllocateSlots(uint32_t NewSize) {
LogMan::Msg::DFmt("Ran out of slots. Can't allocate more");
if (CurrentSize == MAX_STATS_SIZE || !UsingNTQueryPath) {
LogMan::Msg::DFmt("Ran out of slots. Can't allocate more");
return CurrentSize;
}

MEMORY_FEX_STATS_SHM_INFORMATION Info {
.shm_base = nullptr,
.map_size = std::min(CurrentSize * 2, MAX_STATS_SIZE),
.max_size = MAX_STATS_SIZE,
};
size_t Length {};
auto Result = NtQueryVirtualMemory(NtCurrentProcess(), nullptr, MemoryFexStatsShm, &Info, sizeof(Info), &Length);
if (!Result) {
CurrentSize = Info.map_size;
}

return CurrentSize;
}

StatAlloc::StatAlloc(FEXCore::Profiler::AppType AppType) {
// Try wine+fex magic path.

{
MEMORY_FEX_STATS_SHM_INFORMATION Info {
.shm_base = nullptr,
.map_size = 4096,
.max_size = MAX_STATS_SIZE,
};
size_t Length {};
auto Result = NtQueryVirtualMemory(NtCurrentProcess(), nullptr, MemoryFexStatsShm, &Info, sizeof(Info), &Length);
if (!Result) {
UsingNTQueryPath = true;
CurrentSize = Info.map_size;
Base = Info.shm_base;
SaveHeader(AppType);
return;
}
}
CurrentSize = MAX_STATS_SIZE;

auto handle = CreateFile(fextl::fmt::format("/dev/shm/fex-{}-stats", linux_getpid()).c_str(), GENERIC_READ | GENERIC_WRITE,
Expand Down
1 change: 1 addition & 0 deletions Source/Windows/Common/Profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class StatAlloc final : public FEX::Profiler::StatAllocBase {

private:
uint32_t FrontendAllocateSlots(uint32_t NewSize) override;
bool UsingNTQueryPath {};
};

} // namespace FEX::Windows
7 changes: 7 additions & 0 deletions Source/Windows/include/winternl.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ typedef enum _MEMORY_INFORMATION_CLASS {
MemoryWineUnixFuncs = 1000,
MemoryWineUnixWow64Funcs,
#endif
MemoryFexStatsShm = 2000,
} MEMORY_INFORMATION_CLASS;

typedef enum _KEY_VALUE_INFORMATION_CLASS {
Expand All @@ -452,6 +453,12 @@ typedef struct _KEY_VALUE_PARTIAL_INFORMATION {
UCHAR Data[1];
} KEY_VALUE_PARTIAL_INFORMATION, *PKEY_VALUE_PARTIAL_INFORMATION;

typedef struct _MEMORY_FEX_STATS_SHM_INFORMATION {
void* shm_base;
DWORD map_size;
DWORD max_size;
} MEMORY_FEX_STATS_SHM_INFORMATION, *PMEMORY_FEX_STATS_SHM_INFORMATION;

NTSTATUS WINAPIV DbgPrint(LPCSTR fmt, ...);
NTSTATUS WINAPI LdrDisableThreadCalloutsForDll(HMODULE);
NTSTATUS WINAPI LdrGetDllFullName(HMODULE, UNICODE_STRING*);
Expand Down

0 comments on commit a9b28f9

Please sign in to comment.