Windows tests: a start-up thread stack can land on the AGC driver memory at 0xfe0000000, so driver start-up fails with "replace guest placeholder with private memory" #18252

Closed
opened 2026-11-11 00:21:31 +00:00 by angrysandhill · 0 comments
angrysandhill commented 2026-11-11 00:21:31 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by angrysandhill on 2026-11-11T00:21:31Z.


What happens

On Windows, a test that starts the AGC driver occasionally stops at start-up with replace guest placeholder with private memory: Attempt to access invalid address (exit code 0xc0000409). This happens when a host thread stack, created before libc reserves the guest arena, sits on the driver memory at 0xfe0000000.

Title, test or build step

Any test that starts the AGC driver. Seen here as agc_driver_draw_cache_reuse_entry_verify, once in a parallel full-suite run while testing #15555, which this does not come from. #15564 records the same message on a Radeon iGPU in a parallel full-suite run.

AnyPS5 commit

The occurrence was on main c5488026ab with #15555 merged on top, which changes neither the driver start-up nor libc. The reproduction below was on main 41b9e25.

System

Windows 10 Home 22H2 (10.0.19045), AMD Radeon RX 6750 XT, AMD Software Adrenalin 26.10.1 (driver 32.0.21045.16010), WinLibs GCC 15.2.0 r7 UCRT, Release, BUILD_TESTING=ON.

Steps to reproduce

The natural rate is about once in tens of thousands of test processes, so the reproduction places the stack deliberately. It starts the test suspended and, before its loader runs, places a region shaped like a start-up thread stack at 0xfe0000000: 2 MiB reserved, with the top 0x6000 bytes committed and the lower half of those as guard pages. Then it resumes the test. Run with the test's ctest environment:

set ANYPS5_REQUIRE_VULKAN=1
set ANYPS5_NO_SHADER_CACHE=1
set APS5_VERIFY_DRAW_ENTRIES=1
set APS5_NO_PIPELINE_JOURNAL=1
inject.exe FE0000000 200000 stack build\tests\agc_driver_draw_cache_reuse_tests.exe

It stops within about a second with exactly this message, 3 of 3 times. inject.cpp is below.

inject.cpp (g++ -O2 -municode -static -o inject.exe inject.cpp)
#include <windows.h>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <string>

int wmain(int argc, wchar_t** argv) {
    if (argc < 5) return 2;
    const auto address = static_cast<std::uintptr_t>(std::wcstoull(argv[1], nullptr, 16));
    const auto bytes = static_cast<std::size_t>(std::wcstoull(argv[2], nullptr, 16));
    const std::wstring kind = argv[3];
    std::wstring command = L"\"" + std::wstring(argv[4]) + L"\"";
    for (int i = 5; i < argc; ++i) command += L" \"" + std::wstring(argv[i]) + L"\"";
    STARTUPINFOW startup{};
    startup.cb = sizeof(startup);
    PROCESS_INFORMATION process{};
    if (!CreateProcessW(nullptr, command.data(), nullptr, nullptr, TRUE, CREATE_SUSPENDED, nullptr, nullptr, &startup, &process)) return 2;
    bool placed = true;
    if (kind == L"stack") {
        char* base = static_cast<char*>(VirtualAllocEx(process.hProcess, reinterpret_cast<void*>(address), bytes, MEM_RESERVE, PAGE_READWRITE));
        placed = base != nullptr
            && VirtualAllocEx(process.hProcess, base + bytes - 0x3000, 0x3000, MEM_COMMIT, PAGE_READWRITE) != nullptr
            && VirtualAllocEx(process.hProcess, base + bytes - 0x6000, 0x3000, MEM_COMMIT, PAGE_READWRITE | PAGE_GUARD) != nullptr;
    } else if (kind != L"none") {
        const DWORD type = kind == L"commit" ? (MEM_RESERVE | MEM_COMMIT) : MEM_RESERVE;
        placed = VirtualAllocEx(process.hProcess, reinterpret_cast<void*>(address), bytes, type, PAGE_READWRITE) != nullptr;
    }
    if (!placed) {
        TerminateProcess(process.hProcess, 99);
        return 2;
    }
    ResumeThread(process.hThread);
    WaitForSingleObject(process.hProcess, INFINITE);
    DWORD code = 0;
    GetExitCodeProcess(process.hProcess, &code);
    std::fprintf(stderr, "inject: child exit code %#lx\n", code);
    return code == 0 ? 0 : 1;
}

Log

The natural occurrence:

replace guest placeholder with private memory: Attempt to access invalid address
[libc] unhandled exception 'St12system_error' thrown from 00007ff80447d20f
terminate called after throwing an instance of 'std::system_error'
  what():  replace guest placeholder with private memory: Attempt to access invalid address
FATAL: abort() (SIGABRT) on thread 29960

Its return addresses, resolved against that build's symbols and checked against the call before each one:

libc.prx+0x14d20f             GuestArena::WindowsMappings::fail(char const*)+0x5f   after call __cxa_throw
libc.prx+0x9feaf              GuestArenaCommit_nid_postfix+0x9f                      after call WindowsMappings::Commit
libSceAgcDriver.prx+0x8c480   AgcDriver::DriverDetail::Driver::Driver()+0xcf0        after movabs $0xfe0000000,%rcx; call GuestArenaCommit_nid_postfix
libSceAgcDriver.prx+0x8c655   AgcDriver::DriverDetail::Driver::Get()+0x55            after call Driver::Driver()

The only driver call that commits 0xfe0000000 is MapDriverMemory() (Execution/src/Driver/Lifecycle.cpp:85).

What was checked

Why the address can be taken.

  • On Windows, the guest arena reserves [0x10000, 0xFC00000000) when libc loads. Host memory already in that range stays a hole.
  • WindowsMappings::Commit takes any MEM_RESERVE region as a guest placeholder.
  • The test executables link with MinGW's default HIGH_ENTROPY_VA. With it, Windows places the stacks of the start-up threads anywhere from 4 GiB to past 1 TiB. These are the main thread and the loader's worker threads, each a 2 MiB reservation.

How often stacks land in the arena. A local libc build printed the arena's host holes and exited. Running agc_driver_draw_cache_reuse_tests.exe with it 4,000 times gave:

  • The stacks were inside the arena range in 3,940 of 4,000 runs, spread evenly from 4 GiB to 1,008 GiB.
  • In all 3,940, the lowest stack started on a 2 MiB boundary.
  • In 139 runs they were in the system-reserved range [0x7FFFFC000, 0x1000000000), which holds the driver memory.
  • None were in the 2 MiB window itself. For a cluster of about 10 MiB placed this way, that chance is about 1 in 90,000 processes.
  • A 2 MiB stack on a 2 MiB boundary that lands on the window covers it exactly. That is why the message is always this one and not the partial-overlap variants below.

Injected host memory, each placed before the loader ran (agc_driver_draw_cache_reuse_tests.exe, main 41b9e25):

Placed Result
nothing passes
stack-shaped, 2 MiB at 0xfe0000000 replace guest placeholder with private memory: Attempt to access invalid address
reserve 2 MiB at 0xfe0000000 replace guest placeholder with private memory: Attempt to access invalid address
reserve 1 MiB at 0xfe0100000 coalesce guest placeholders: Attempt to access invalid address
reserve 4 MiB at 0xfdff00000 split guest placeholder prefix: Attempt to access invalid address
commit 1 MiB at 0xfe0100000 passes, and the second half of the driver's 2 MiB is the host's allocation
reserve 1 MiB at 0xff0000000 passes

Titles are not affected.

  • #679 made the relinker write title executables without HIGH_ENTROPY_VA for this same reason: 0x140 or 0x100 in WindowsPeWriter.cpp. The test executables were left with it.
  • test_windows_address_space.py checks that a title's main thread stack stays below 0x200000000.
  • agc_driver_frame_replay_relaunch_tests already links with --disable-high-entropy-va, so that its stack is an arena host region in every process.

With the high-entropy bit cleared. On the same executable with HIGH_ENTROPY_VA cleared, all 1,000 runs had every host region below 0.053 GiB.

Proposed fix. Link the test executables with --disable-high-entropy-va, the layout titles get. I have a pull request for that. A check in Commit that refuses host holes with a clear message could be added separately.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6318706700 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/18252). Originally posted by [angrysandhill](https://github.com/angrysandhill) on 2026-11-11T00:21:31Z. --- ### What happens On Windows, a test that starts the AGC driver occasionally stops at start-up with `replace guest placeholder with private memory: Attempt to access invalid address` (exit code `0xc0000409`). This happens when a host thread stack, created before libc reserves the guest arena, sits on the driver memory at `0xfe0000000`. ### Title, test or build step Any test that starts the AGC driver. Seen here as `agc_driver_draw_cache_reuse_entry_verify`, once in a parallel full-suite run while testing #15555, which this does not come from. #15564 records the same message on a Radeon iGPU in a parallel full-suite run. ### AnyPS5 commit The occurrence was on `main` `c5488026ab` with #15555 merged on top, which changes neither the driver start-up nor libc. The reproduction below was on `main` `41b9e25`. ### System Windows 10 Home 22H2 (10.0.19045), AMD Radeon RX 6750 XT, AMD Software Adrenalin 26.10.1 (driver 32.0.21045.16010), WinLibs GCC 15.2.0 r7 UCRT, Release, `BUILD_TESTING=ON`. ### Steps to reproduce The natural rate is about once in tens of thousands of test processes, so the reproduction places the stack deliberately. It starts the test suspended and, before its loader runs, places a region shaped like a start-up thread stack at `0xfe0000000`: 2 MiB reserved, with the top `0x6000` bytes committed and the lower half of those as guard pages. Then it resumes the test. Run with the test's ctest environment: ``` set ANYPS5_REQUIRE_VULKAN=1 set ANYPS5_NO_SHADER_CACHE=1 set APS5_VERIFY_DRAW_ENTRIES=1 set APS5_NO_PIPELINE_JOURNAL=1 inject.exe FE0000000 200000 stack build\tests\agc_driver_draw_cache_reuse_tests.exe ``` It stops within about a second with exactly this message, 3 of 3 times. `inject.cpp` is below. <details><summary>inject.cpp (g++ -O2 -municode -static -o inject.exe inject.cpp)</summary> ```cpp #include <windows.h> #include <cstdint> #include <cstdio> #include <cstdlib> #include <string> int wmain(int argc, wchar_t** argv) { if (argc < 5) return 2; const auto address = static_cast<std::uintptr_t>(std::wcstoull(argv[1], nullptr, 16)); const auto bytes = static_cast<std::size_t>(std::wcstoull(argv[2], nullptr, 16)); const std::wstring kind = argv[3]; std::wstring command = L"\"" + std::wstring(argv[4]) + L"\""; for (int i = 5; i < argc; ++i) command += L" \"" + std::wstring(argv[i]) + L"\""; STARTUPINFOW startup{}; startup.cb = sizeof(startup); PROCESS_INFORMATION process{}; if (!CreateProcessW(nullptr, command.data(), nullptr, nullptr, TRUE, CREATE_SUSPENDED, nullptr, nullptr, &startup, &process)) return 2; bool placed = true; if (kind == L"stack") { char* base = static_cast<char*>(VirtualAllocEx(process.hProcess, reinterpret_cast<void*>(address), bytes, MEM_RESERVE, PAGE_READWRITE)); placed = base != nullptr && VirtualAllocEx(process.hProcess, base + bytes - 0x3000, 0x3000, MEM_COMMIT, PAGE_READWRITE) != nullptr && VirtualAllocEx(process.hProcess, base + bytes - 0x6000, 0x3000, MEM_COMMIT, PAGE_READWRITE | PAGE_GUARD) != nullptr; } else if (kind != L"none") { const DWORD type = kind == L"commit" ? (MEM_RESERVE | MEM_COMMIT) : MEM_RESERVE; placed = VirtualAllocEx(process.hProcess, reinterpret_cast<void*>(address), bytes, type, PAGE_READWRITE) != nullptr; } if (!placed) { TerminateProcess(process.hProcess, 99); return 2; } ResumeThread(process.hThread); WaitForSingleObject(process.hProcess, INFINITE); DWORD code = 0; GetExitCodeProcess(process.hProcess, &code); std::fprintf(stderr, "inject: child exit code %#lx\n", code); return code == 0 ? 0 : 1; } ``` </details> ### Log The natural occurrence: ``` replace guest placeholder with private memory: Attempt to access invalid address [libc] unhandled exception 'St12system_error' thrown from 00007ff80447d20f terminate called after throwing an instance of 'std::system_error' what(): replace guest placeholder with private memory: Attempt to access invalid address FATAL: abort() (SIGABRT) on thread 29960 ``` Its return addresses, resolved against that build's symbols and checked against the call before each one: ``` libc.prx+0x14d20f GuestArena::WindowsMappings::fail(char const*)+0x5f after call __cxa_throw libc.prx+0x9feaf GuestArenaCommit_nid_postfix+0x9f after call WindowsMappings::Commit libSceAgcDriver.prx+0x8c480 AgcDriver::DriverDetail::Driver::Driver()+0xcf0 after movabs $0xfe0000000,%rcx; call GuestArenaCommit_nid_postfix libSceAgcDriver.prx+0x8c655 AgcDriver::DriverDetail::Driver::Get()+0x55 after call Driver::Driver() ``` The only driver call that commits `0xfe0000000` is `MapDriverMemory()` (`Execution/src/Driver/Lifecycle.cpp:85`). ### What was checked **Why the address can be taken.** - On Windows, the guest arena reserves `[0x10000, 0xFC00000000)` when libc loads. Host memory already in that range stays a hole. - `WindowsMappings::Commit` takes any `MEM_RESERVE` region as a guest placeholder. - The test executables link with MinGW's default `HIGH_ENTROPY_VA`. With it, Windows places the stacks of the start-up threads anywhere from 4 GiB to past 1 TiB. These are the main thread and the loader's worker threads, each a 2 MiB reservation. **How often stacks land in the arena.** A local libc build printed the arena's host holes and exited. Running `agc_driver_draw_cache_reuse_tests.exe` with it 4,000 times gave: - The stacks were inside the arena range in 3,940 of 4,000 runs, spread evenly from 4 GiB to 1,008 GiB. - In all 3,940, the lowest stack started on a 2 MiB boundary. - In 139 runs they were in the system-reserved range `[0x7FFFFC000, 0x1000000000)`, which holds the driver memory. - None were in the 2 MiB window itself. For a cluster of about 10 MiB placed this way, that chance is about 1 in 90,000 processes. - A 2 MiB stack on a 2 MiB boundary that lands on the window covers it exactly. That is why the message is always this one and not the partial-overlap variants below. **Injected host memory, each placed before the loader ran** (`agc_driver_draw_cache_reuse_tests.exe`, `main` `41b9e25`): | Placed | Result | |---|---| | nothing | passes | | stack-shaped, 2 MiB at `0xfe0000000` | `replace guest placeholder with private memory: Attempt to access invalid address` | | reserve 2 MiB at `0xfe0000000` | `replace guest placeholder with private memory: Attempt to access invalid address` | | reserve 1 MiB at `0xfe0100000` | `coalesce guest placeholders: Attempt to access invalid address` | | reserve 4 MiB at `0xfdff00000` | `split guest placeholder prefix: Attempt to access invalid address` | | commit 1 MiB at `0xfe0100000` | passes, and the second half of the driver's 2 MiB is the host's allocation | | reserve 1 MiB at `0xff0000000` | passes | **Titles are not affected.** - #679 made the relinker write title executables without `HIGH_ENTROPY_VA` for this same reason: `0x140` or `0x100` in `WindowsPeWriter.cpp`. The test executables were left with it. - `test_windows_address_space.py` checks that a title's main thread stack stays below `0x200000000`. - `agc_driver_frame_replay_relaunch_tests` already links with `--disable-high-entropy-va`, so that its stack is an arena host region in every process. **With the high-entropy bit cleared.** On the same executable with `HIGH_ENTROPY_VA` cleared, all 1,000 runs had every host region below 0.053 GiB. **Proposed fix.** Link the test executables with `--disable-high-entropy-va`, the layout titles get. I have a pull request for that. A check in `Commit` that refuses host holes with a clear message could be added separately. AI-assisted: yes.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#18252
No description provided.