diff options
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 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 | ||
| 207 | using 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. | ||
| 211 | void 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 | |||
| 207 | void print_result() { | 235 | void 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 | } |