diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 17:01:52 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 17:01:52 -0500 |
| commit | cf82fc26fd0b013638833b16bd5507d3cd2de42a (patch) | |
| tree | 102510b93ffc1f82099bca0a95cec728a4021d15 /runtime/shims/xmem.cpp | |
| parent | f38f5fdeb7b038eb0640ae739c2b47a07333f3ec (diff) | |
| parent | c2ac1ea34f58b94419fcc4943a6c62754b95d270 (diff) | |
Merge pull request #3401 from 0xTehuti
Diffstat (limited to 'runtime/shims/xmem.cpp')
| -rw-r--r-- | runtime/shims/xmem.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/runtime/shims/xmem.cpp b/runtime/shims/xmem.cpp index c539a0cb5..98c05d433 100644 --- a/runtime/shims/xmem.cpp +++ b/runtime/shims/xmem.cpp | |||
| @@ -95,8 +95,10 @@ SIZE_T __stdcall XMemVirtualQuery(HANDLE process, const void* address, void* out | |||
| 95 | // 0x75b1): ECX is the constant 0x20000001 (its meaning is not known) and RDX points at a stack buffer (0x80 bytes | 95 | // 0x75b1): ECX is the constant 0x20000001 (its meaning is not known) and RDX points at a stack buffer (0x80 bytes |
| 96 | // where the frame shows it). The caller reads a 64-bit size at +8 and treats a zero return as "no data". Taking the | 96 | // where the frame shows it). The caller reads a 64-bit size at +8 and treats a zero return as "no data". Taking the |
| 97 | // pointer from the first argument wrote to address 0x20000001. | 97 | // pointer from the first argument wrote to address 0x20000001. |
| 98 | // Only the first 16 bytes are touched: zero at +0 (unknown) and the process working set at +8. Do not claim more of | 98 | // The measured FSR sites establish argument shape, kind and the 64-bit working-set read at +8; +0's title-total memory |
| 99 | // the struct than is measured. | 99 | // limit interpretation is inferred from other Series implementations (xcl, xbox-emulator) and title engine telemetry |
| 100 | // sizing memory pools (RT-220). Note that if GlobalMemoryStatusEx reports 0 physical memory, XMem falls back to the | ||
| 101 | // 12 GiB title limit, whereas XSystemGetAppMemoryUsageLimit remains 0. | ||
| 100 | BOOL __stdcall XMemGetWorkingSetStatistics(uint32_t /*kind*/, void* stats) { | 102 | BOOL __stdcall XMemGetWorkingSetStatistics(uint32_t /*kind*/, void* stats) { |
| 101 | if (!stats) { | 103 | if (!stats) { |
| 102 | static std::atomic<bool> warned{false}; | 104 | static std::atomic<bool> warned{false}; |
| @@ -109,8 +111,15 @@ BOOL __stdcall XMemGetWorkingSetStatistics(uint32_t /*kind*/, void* stats) { | |||
| 109 | PROCESS_MEMORY_COUNTERS pmc{}; | 111 | PROCESS_MEMORY_COUNTERS pmc{}; |
| 110 | if (!GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) return FALSE; | 112 | if (!GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) return FALSE; |
| 111 | 113 | ||
| 114 | MEMORYSTATUSEX ms{sizeof(ms)}; | ||
| 115 | uint64_t total_memory = 12ULL * 1024 * 1024 * 1024; | ||
| 116 | if (GlobalMemoryStatusEx(&ms) && ms.ullTotalPhys != 0) { | ||
| 117 | total_memory = ms.ullTotalPhys; | ||
| 118 | } | ||
| 119 | |||
| 112 | uint8_t* bytes = static_cast<uint8_t*>(stats); | 120 | uint8_t* bytes = static_cast<uint8_t*>(stats); |
| 113 | std::memset(bytes, 0, 16); | 121 | std::memset(bytes, 0, 16); |
| 122 | std::memcpy(bytes + 0, &total_memory, sizeof(total_memory)); | ||
| 114 | uint64_t working_set = pmc.WorkingSetSize; | 123 | uint64_t working_set = pmc.WorkingSetSize; |
| 115 | std::memcpy(bytes + 8, &working_set, sizeof(working_set)); | 124 | std::memcpy(bytes + 8, &working_set, sizeof(working_set)); |
| 116 | return TRUE; | 125 | return TRUE; |