upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/xmem_test.cpp
diff options
context:
space:
mode:
authorVonsek <45567075+Vonsek@users.noreply.github.com>2026-11-23 00:19:13 +0100
committerVonsek <45567075+Vonsek@users.noreply.github.com>2026-11-23 00:19:13 +0100
commitfcda84bb0d2c6abb99e42409f413025d00ddb4be (patch)
tree27a5ee092be10547ffa5b4447ee050c623c62850 /runtime/test/xmem_test.cpp
parent3a1ed28bebf374321149bc4bbffc005ea6f691c4 (diff)
parent3986b50821272791333c00df80bdb8526a8fdb9c (diff)
Merge hw4-ps-oracle into hw4-ps-formats (#3499)
docs/shader_validation.md tools/ps_oracle.py AI-assisted.
Diffstat (limited to 'runtime/test/xmem_test.cpp')
-rw-r--r--runtime/test/xmem_test.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/runtime/test/xmem_test.cpp b/runtime/test/xmem_test.cpp
index 7e4948f1f..1ad4080f7 100644
--- a/runtime/test/xmem_test.cpp
+++ b/runtime/test/xmem_test.cpp
@@ -204,6 +204,34 @@ void test_virtual_alloc(XMemVirtualAllocFn virtual_alloc, XMemGetWriteWatchFn ge
204 "nonzero XMem allocation attributes are rejected before host allocation"); 204 "nonzero XMem allocation attributes are rejected before host allocation");
205} 205}
206 206
207using HostVirtualAllocFn = void*(WINAPI*)(void*, SIZE_T, DWORD, DWORD);
208
209// RT-217: a title's kernel32!VirtualAlloc carries the console's MEM_GRAPHICS / MEM_TITLE type bits, which the host
210// rejects. The registered shim has to drop them and still allocate.
211void test_title_virtual_alloc() {
212 constexpr DWORD kMemGraphics = 0x10000000;
213 constexpr DWORD kMemTitle = 0x40000000;
214 const char* const dlls[] = {"kernel32.dll", "kernelbase.dll", "api-ms-win-core-memory-l1-1-0.dll"};
215 for (const char* dll : dlls) {
216 const auto alloc = reinterpret_cast<HostVirtualAllocFn>(rt::shims::find(dll, "VirtualAlloc"));
217 char what[160];
218 std::snprintf(what, sizeof what, "registry exposes %s!VirtualAlloc", dll);
219 check(alloc != nullptr, what);
220 if (!alloc) continue;
221
222 for (const DWORD bits : {kMemGraphics, kMemTitle, kMemGraphics | kMemTitle, DWORD{0}}) {
223 void* const p = alloc(nullptr, 0x10000, MEM_RESERVE | MEM_COMMIT | bits, PAGE_READWRITE);
224 std::snprintf(what, sizeof what, "%s!VirtualAlloc with type bits %#lx returns memory", dll,
225 static_cast<unsigned long>(bits));
226 check(p != nullptr, what);
227 if (!p) continue;
228 static_cast<volatile uint8_t*>(p)[0] = 0x5a;
229 check(static_cast<volatile uint8_t*>(p)[0] == 0x5a, "the allocation is committed and writable");
230 check(VirtualFree(p, 0, MEM_RELEASE), "release the allocation");
231 }
232 }
233}
234
207void print_result() { 235void print_result() {
208 if (g_failures == 0) { 236 if (g_failures == 0) {
209 std::printf("xmem_test: OK (%d checks)\n", g_checks); 237 std::printf("xmem_test: OK (%d checks)\n", g_checks);
@@ -250,6 +278,8 @@ int main() {
250 test_virtual_alloc(virtual_alloc, get_write_watch, reset_write_watch); 278 test_virtual_alloc(virtual_alloc, get_write_watch, reset_write_watch);
251 } 279 }
252 280
281 test_title_virtual_alloc();
282
253 print_result(); 283 print_result();
254 return g_failures ? 1 : 0; 284 return g_failures ? 1 : 0;
255} 285}