Skip to content
Closed
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
3 changes: 3 additions & 0 deletions core/libs/prx/libSceAgcDriver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,9 @@ if(BUILD_TESTING)
if(WIN32)
set_tests_properties(agc_host_import_unmap PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
add_test(NAME agc_host_import_second_mapping COMMAND agc_driver_recorder_tests --host-import-second-mapping-only)
set_tests_properties(agc_host_import_second_mapping PROPERTIES SKIP_RETURN_CODE 77 ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
endif()
endif()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,10 @@ const HostImport* importAllocation(const Context& context, HostImports& state, s
throw std::runtime_error(text);
}
entry.alias = GuestArena::GuestArenaMapAlias_nid_postfix(static_cast<std::uintptr_t>(base), static_cast<std::size_t>(bytes));
if (entry.alias == nullptr) {
state.failed.insert(base);
return nullptr;
}
}
#else
if (!GuestMemory::Accessible(reinterpret_cast<const void*>(base), static_cast<std::size_t>(bytes), true)) {
Expand Down
45 changes: 45 additions & 0 deletions core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,42 @@ void remappedImportTests(const Device& device) {
HostImportFor(context, address, bytes);
}

#ifdef _WIN32
void secondMappingImportTests(const Device& device) {
const auto& context = device.GetContext();
if (context.hostImportAlignment == 0) {
std::cout << "host imports unavailable: imports after a second mapping not tested\n";
return;
}
constexpr std::size_t bytes = 65536;
constexpr std::size_t page = 16384;
struct Release {
void* mapping = nullptr;
void* alias = nullptr;
std::int64_t physical = -1;
~Release() {
if (alias != nullptr) sceKernelMunmap(alias, page);
if (mapping != nullptr) sceKernelMunmap(mapping, bytes);
if (physical >= 0) sceKernelReleaseDirectMemory(physical, bytes);
}
} release;
Require(sceKernelAllocateDirectMemory(0, 0x7fffffffffll, bytes, bytes, 0, &release.physical) == 0, "allocate the second mapping test backing");
Require(sceKernelMapDirectMemory(&release.mapping, bytes, 0x33, 0, release.physical, bytes) == 0, "map the second mapping test backing");
const auto address = reinterpret_cast<std::uint64_t>(release.mapping);
if (HostImportFor(context, address, bytes) == nullptr) {
std::cout << "host import of singly mapped direct memory refused: imports after a second mapping not tested\n";
return;
}
const auto first = HostImportSerial(context, address, bytes, true);
Require(first != 0 && HostImportSerial(context, address, bytes, true) == first, "singly mapped direct memory lost its import");
Require(sceKernelMapDirectMemory(&release.alias, page, 0x33, 0, release.physical, page) == 0, "map the first page a second time");
Require(HostImportFor(context, address, bytes) != nullptr, "direct memory was not imported again after a second mapping of its first page");
const auto second = HostImportSerial(context, address, bytes, true);
Require(second != 0 && second != first, "the import of direct memory whose pages were replaced was kept");
HostImportFor(context, address, bytes);
}
#endif

void movedMetadataTests(const Device& device, Recorder& recorder) {
const auto& base = device.GetContext();
if (base.hostImportAlignment == 0) {
Expand Down Expand Up @@ -4384,6 +4420,12 @@ int main(int argc, char** argv) {
hostImportUnmapTests(device, recorder);
return 0;
}
#ifdef _WIN32
if (argc == 2 && std::string_view(argv[1]) == "--host-import-second-mapping-only") {
secondMappingImportTests(device);
return 0;
}
#endif
readTrackingTests(device, recorder);
writeSettledTests(device, recorder);
completionCountTests(device, recorder);
Expand All @@ -4409,6 +4451,9 @@ int main(int argc, char** argv) {
storeRunTests(device, recorder);
queuedWriteGroupTests();
remappedImportTests(device);
#ifdef _WIN32
secondMappingImportTests(device);
#endif
movedMetadataTests(device, recorder);
viewPastLastMipTests(device, recorder);
keysFillTests(device, recorder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class GuestBlock {
const auto section = CreateFileMappingW(INVALID_HANDLE_VALUE, nullptr, PAGE_EXECUTE_READWRITE, 0, BlockBytes, nullptr);
Require(section != nullptr, "cannot create shared test memory");
GuestArena::GuestArenaMap_nid_postfix(block, BlockBytes, section, 0, PAGE_READWRITE);
twin = static_cast<std::uint8_t*>(GuestArena::GuestArenaAllocate_nid_postfix(BlockBytes, 65536));
Require(twin != nullptr, "cannot reserve the second mapping of shared test memory");
GuestArena::GuestArenaMap_nid_postfix(twin, BlockBytes, section, 0, PAGE_READWRITE);
CloseHandle(section);
} else if (block != nullptr) GuestArena::GuestArenaCommit_nid_postfix(block, BlockBytes, PAGE_READWRITE, BlockBytes);
} else {
Expand Down Expand Up @@ -110,6 +113,10 @@ class GuestBlock {
~GuestBlock() {
GuestAllocations::Mutation().Remove(block);
#ifdef _WIN32
if (twin != nullptr) {
GuestArena::GuestArenaReset_nid_postfix(twin, BlockBytes);
GuestArena::GuestArenaRelease_nid_postfix(twin, BlockBytes);
}
if (watched) {
GuestArena::GuestArenaReset_nid_postfix(block, BlockBytes);
GuestArena::GuestArenaRelease_nid_postfix(block, BlockBytes);
Expand All @@ -134,6 +141,7 @@ class GuestBlock {
private:
bool watched;
std::uint8_t* block = nullptr;
std::uint8_t* twin = nullptr;
};

std::array<std::uint32_t, 8> TextureDescriptor(const std::uint8_t* texels, const std::uint8_t* keys) {
Expand Down
3 changes: 3 additions & 0 deletions core/libs/prx/libc/include/GuestArena.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void GuestArenaCommit_nid_postfix(void* pointer, std::size_t bytes, std::uint32_
void GuestArenaReset_nid_postfix(void* pointer, std::size_t bytes);
#ifdef _WIN32
bool GuestArenaHandleWrite_nid_postfix(std::uintptr_t address);
bool GuestArenaHandleRead_nid_postfix(std::uintptr_t address);
void GuestArenaPinWritable_nid_postfix(const void* pointer, std::size_t bytes);
void GuestArenaUnpinWritable_nid_postfix(const void* pointer, std::size_t bytes);
bool GuestArenaProtection_nid_postfix(std::uintptr_t address, std::uint32_t* protection);
Expand All @@ -39,6 +40,8 @@ void GuestArenaSetPrivateMappingObserver_nid_postfix(void (*callback)(std::uintp
void GuestArenaMap_nid_postfix(void* pointer, std::size_t bytes, void* section, std::uint64_t offset, std::uint32_t protection);
void* GuestArenaMapAlias_nid_postfix(std::uintptr_t address, std::size_t bytes);
void GuestArenaUnmapAlias_nid_postfix(void* alias);
bool GuestArenaResidentSpan_nid_postfix(std::uintptr_t address, std::size_t bytes, std::uintptr_t* start, std::uintptr_t* end);
void GuestArenaForgetSection_nid_postfix(void* section);
#else
void GuestArenaSetSharedBacking_nid_postfix(SharedBackingResolver resolver);
void GuestArenaSetSharedBackingWriter_nid_no_patch(SharedBackingWriter writer);
Expand Down
Loading
Loading