Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,8 @@ struct PageStates {
void initialize();

PageSpan* spanOf(std::uintptr_t address) {
if (arena.covers(address)) return &arena;
if (image.covers(address)) return ℑ
if (arena.covers(address)) return &arena;
return nullptr;
}

Expand All @@ -800,6 +800,9 @@ struct PageStates {
const std::uint8_t value = readable ? static_cast<std::uint8_t>(PageReadable | (writable ? PageWritable : 0u)) : PageInaccessible;
const auto first = std::max(base, span->base);
const auto last = std::min(regionEnd, span->base + span->size);
#ifdef _WIN32
if (span == &arena && GuestArena::GuestArenaHostRegionOverlaps_nid_postfix(first, static_cast<std::size_t>(last - first))) continue;
#endif
span->store(first, last, value);
if (GuestAllocations::GuestAllocationsGeneration_nid_postfix() != generation || accessSerial.load(std::memory_order_acquire) != access) span->forget(first, static_cast<std::size_t>(last - first));
}
Expand Down
30 changes: 30 additions & 0 deletions core/libs/prx/libSceAgcDriver/tests/PageStates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,41 @@ void CheckRuns() {
Require(!DescribeCommitted(edgeFirst, edgePages * page + Unit, true).whole && CommittedRanges(edgeFirst, edgePages * page + Unit, true) == edgeRun, "a run into an unallocated chunk was reported past its committed pages");
std::puts("page-state block scans across 64-page, 512-page and sparse-chunk boundaries passed");
}

int CheckHostRegion() {
constexpr std::size_t page = 4096;
auto* block = static_cast<std::byte*>(HeapAlloc(GetProcessHeap(), 0, 4 * page));
Require(block != nullptr, "cannot allocate a host-region fixture");
auto* readable = reinterpret_cast<std::byte*>((reinterpret_cast<std::uintptr_t>(block) + page - 1) & ~static_cast<std::uintptr_t>(page - 1));
auto* reserved = readable + page;
if (!GuestArena::GuestArenaHostRegionOverlaps_nid_postfix(reinterpret_cast<std::uintptr_t>(readable), 2 * page)) {
HeapFree(GetProcessHeap(), 0, block);
std::puts("the process heap is outside the guest arena's host regions");
return 77;
}
Require(VirtualFree(reserved, page, MEM_DECOMMIT) != FALSE, "cannot decommit the host-region fixture");
const bool accessible = Accessible(readable, page, true);
const bool decommitted = !Accessible(reserved, page);
Require(VirtualAlloc(reserved, page, MEM_COMMIT, PAGE_READWRITE) == reserved, "cannot commit the host-region fixture");
const bool committed = Accessible(reserved, page, true);
DWORD original = 0;
Require(VirtualProtect(readable, page, PAGE_NOACCESS, &original) != FALSE, "cannot protect the host-region fixture");
const bool hidden = !Accessible(readable, page);
Require(VirtualProtect(readable, page, original, &original) != FALSE, "cannot restore the host-region fixture");
HeapFree(GetProcessHeap(), 0, block);
Require(accessible, "a committed host-region page was inaccessible");
Require(decommitted, "a decommitted host-region page was accessible");
Require(committed, "a host-region page committed again kept its inaccessible state");
Require(hidden, "a host-region page made no-access kept its accessible state");
std::puts("page states of host regions in the guest arena follow protection changes");
return 0;
}
}

int main(int argc, char** argv) {
try {
Require(GuestArena::GuestArenaAvailable_nid_postfix(), "page-state fixture needs the guest arena");
if (argc == 2 && std::string_view(argv[1]) == "--host-region") return CheckHostRegion();
if (argc == 2 && std::string_view(argv[1]) == "--metadata") CheckMetadata();
else if (argc == 2 && std::string_view(argv[1]) == "--runs") CheckRuns();
else CheckBoundaries();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ if(BUILD_TESTING AND WIN32)
add_test(NAME agc_page_states COMMAND agc_page_state_tests)
add_test(NAME agc_page_state_metadata COMMAND agc_page_state_tests --metadata)
add_test(NAME agc_page_state_runs COMMAND agc_page_state_tests --runs)
set_tests_properties(agc_page_states agc_page_state_metadata agc_page_state_runs PROPERTIES
add_test(NAME agc_page_state_host_region COMMAND agc_page_state_tests --host-region)
set_tests_properties(agc_page_states agc_page_state_metadata agc_page_state_runs agc_page_state_host_region PROPERTIES
TIMEOUT 30 ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
set_tests_properties(agc_page_state_host_region PROPERTIES SKIP_RETURN_CODE 77)
endif()
Loading