diff options
| author | 0xTehuti <xtehuti@agentmail.to> | 2026-11-22 21:25:23 +0100 |
|---|---|---|
| committer | 0xTehuti <xtehuti@agentmail.to> | 2026-11-22 21:25:23 +0100 |
| commit | 77eb9cd726fa8d9f1151fa8b1d53e0f170545fdd (patch) | |
| tree | 4039d19fc1fe9d3954d12ee67d388b029dff3d0f /runtime/shims/xmem.cpp | |
| parent | f847748cc76bd3777f9c070c4034eb2fc1c04e64 (diff) | |
xmem: write title memory limit at +0 in XMemGetWorkingSetStatistics (RT-220)
Diffstat (limited to 'runtime/shims/xmem.cpp')
| -rw-r--r-- | runtime/shims/xmem.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/runtime/shims/xmem.cpp b/runtime/shims/xmem.cpp index 7d4a1bcfd..939aaaee3 100644 --- a/runtime/shims/xmem.cpp +++ b/runtime/shims/xmem.cpp | |||
| @@ -64,8 +64,8 @@ SIZE_T __stdcall XMemVirtualQuery(HANDLE process, const void* address, void* out | |||
| 64 | // 0x75b1): ECX is the constant 0x20000001 (its meaning is not known) and RDX points at a stack buffer (0x80 bytes | 64 | // 0x75b1): ECX is the constant 0x20000001 (its meaning is not known) and RDX points at a stack buffer (0x80 bytes |
| 65 | // where the frame shows it). The caller reads a 64-bit size at +8 and treats a zero return as "no data". Taking the | 65 | // where the frame shows it). The caller reads a 64-bit size at +8 and treats a zero return as "no data". Taking the |
| 66 | // pointer from the first argument wrote to address 0x20000001. | 66 | // pointer from the first argument wrote to address 0x20000001. |
| 67 | // Only the first 16 bytes are touched: zero at +0 (unknown) and the process working set at +8. Do not claim more of | 67 | // Other Series layers (xcl, xbox-emulator) and title engine telemetry write the title's memory limit at +0 and |
| 68 | // the struct than is measured. | 68 | // working set at +8 (RT-220). |
| 69 | BOOL __stdcall XMemGetWorkingSetStatistics(uint32_t /*kind*/, void* stats) { | 69 | BOOL __stdcall XMemGetWorkingSetStatistics(uint32_t /*kind*/, void* stats) { |
| 70 | if (!stats) { | 70 | if (!stats) { |
| 71 | static std::atomic<bool> warned{false}; | 71 | static std::atomic<bool> warned{false}; |
| @@ -78,8 +78,15 @@ BOOL __stdcall XMemGetWorkingSetStatistics(uint32_t /*kind*/, void* stats) { | |||
| 78 | PROCESS_MEMORY_COUNTERS pmc{}; | 78 | PROCESS_MEMORY_COUNTERS pmc{}; |
| 79 | if (!GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) return FALSE; | 79 | if (!GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) return FALSE; |
| 80 | 80 | ||
| 81 | MEMORYSTATUSEX ms{sizeof(ms)}; | ||
| 82 | uint64_t total_memory = 12ULL * 1024 * 1024 * 1024; | ||
| 83 | if (GlobalMemoryStatusEx(&ms) && ms.ullTotalPhys != 0) { | ||
| 84 | total_memory = ms.ullTotalPhys; | ||
| 85 | } | ||
| 86 | |||
| 81 | uint8_t* bytes = static_cast<uint8_t*>(stats); | 87 | uint8_t* bytes = static_cast<uint8_t*>(stats); |
| 82 | std::memset(bytes, 0, 16); | 88 | std::memset(bytes, 0, 16); |
| 89 | std::memcpy(bytes + 0, &total_memory, sizeof(total_memory)); | ||
| 83 | uint64_t working_set = pmc.WorkingSetSize; | 90 | uint64_t working_set = pmc.WorkingSetSize; |
| 84 | std::memcpy(bytes + 8, &working_set, sizeof(working_set)); | 91 | std::memcpy(bytes + 8, &working_set, sizeof(working_set)); |
| 85 | return TRUE; | 92 | return TRUE; |