diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 22:09:51 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 22:12:50 -0500 |
| commit | be8570ace18d3144d6cbfc2d57c60e736a1c1465 (patch) | |
| tree | 2aa5c100fb9b4ec22b819333194baeea5d3b7906 /runtime/test/xmem_test.cpp | |
| parent | f99ff6cbdd23a2417af5494497f2f23da67c144a (diff) | |
| parent | d0835dd9f9ec0a88faee510126436f2427854c2e (diff) | |
Merge remote-tracking branch 'origin/main' into triage-r43
# Conflicts:
# docs/runtime_imports.md
# runtime/CMakeLists.txt
# runtime/shims/xgameruntime.cpp
# runtime/test/xmem_test.cpp
# tools/rdna2spirv.py
Diffstat (limited to 'runtime/test/xmem_test.cpp')
| -rw-r--r-- | runtime/test/xmem_test.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/runtime/test/xmem_test.cpp b/runtime/test/xmem_test.cpp index c40cae8fa..bd38cab39 100644 --- a/runtime/test/xmem_test.cpp +++ b/runtime/test/xmem_test.cpp | |||
| @@ -266,6 +266,34 @@ void test_attribute_trace(XMemAllocFn alloc, XMemFreeFn free_mem) { | |||
| 266 | DeleteFileW(path.c_str()); | 266 | DeleteFileW(path.c_str()); |
| 267 | } | 267 | } |
| 268 | 268 | ||
| 269 | using HostVirtualAllocFn = void*(WINAPI*)(void*, SIZE_T, DWORD, DWORD); | ||
| 270 | |||
| 271 | // RT-217: a title's kernel32!VirtualAlloc carries the console's MEM_GRAPHICS / MEM_TITLE type bits, which the host | ||
| 272 | // rejects. The registered shim has to drop them and still allocate. | ||
| 273 | void test_title_virtual_alloc() { | ||
| 274 | constexpr DWORD kMemGraphics = 0x10000000; | ||
| 275 | constexpr DWORD kMemTitle = 0x40000000; | ||
| 276 | const char* const dlls[] = {"kernel32.dll", "kernelbase.dll", "api-ms-win-core-memory-l1-1-0.dll"}; | ||
| 277 | for (const char* dll : dlls) { | ||
| 278 | const auto alloc = reinterpret_cast<HostVirtualAllocFn>(rt::shims::find(dll, "VirtualAlloc")); | ||
| 279 | char what[160]; | ||
| 280 | std::snprintf(what, sizeof what, "registry exposes %s!VirtualAlloc", dll); | ||
| 281 | check(alloc != nullptr, what); | ||
| 282 | if (!alloc) continue; | ||
| 283 | |||
| 284 | for (const DWORD bits : {kMemGraphics, kMemTitle, kMemGraphics | kMemTitle, DWORD{0}}) { | ||
| 285 | void* const p = alloc(nullptr, 0x10000, MEM_RESERVE | MEM_COMMIT | bits, PAGE_READWRITE); | ||
| 286 | std::snprintf(what, sizeof what, "%s!VirtualAlloc with type bits %#lx returns memory", dll, | ||
| 287 | static_cast<unsigned long>(bits)); | ||
| 288 | check(p != nullptr, what); | ||
| 289 | if (!p) continue; | ||
| 290 | static_cast<volatile uint8_t*>(p)[0] = 0x5a; | ||
| 291 | check(static_cast<volatile uint8_t*>(p)[0] == 0x5a, "the allocation is committed and writable"); | ||
| 292 | check(VirtualFree(p, 0, MEM_RELEASE), "release the allocation"); | ||
| 293 | } | ||
| 294 | } | ||
| 295 | } | ||
| 296 | |||
| 269 | void print_result() { | 297 | void print_result() { |
| 270 | if (g_failures == 0) { | 298 | if (g_failures == 0) { |
| 271 | std::printf("xmem_test: OK (%d checks)\n", g_checks); | 299 | std::printf("xmem_test: OK (%d checks)\n", g_checks); |
| @@ -313,6 +341,8 @@ int main() { | |||
| 313 | } | 341 | } |
| 314 | test_attribute_trace(alloc, free_mem); | 342 | test_attribute_trace(alloc, free_mem); |
| 315 | 343 | ||
| 344 | test_title_virtual_alloc(); | ||
| 345 | |||
| 316 | print_result(); | 346 | print_result(); |
| 317 | return g_failures ? 1 : 0; | 347 | return g_failures ? 1 : 0; |
| 318 | } | 348 | } |