mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-19 18:36:53 +02:00
memory: copy sparse backing in one traversal
This commit is contained in:
@@ -258,28 +258,18 @@ public:
|
|||||||
g_test_backing_read(vaddr, size);
|
g_test_backing_read(vaddr, size);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
const auto end = vaddr + size;
|
const auto end = vaddr + size;
|
||||||
auto first = m_maps.lower_bound(vaddr);
|
auto mapping = m_maps.lower_bound(vaddr);
|
||||||
if (first != m_maps.begin()) {
|
if (mapping != m_maps.begin()) {
|
||||||
auto previous = std::prev(first);
|
auto previous = std::prev(mapping);
|
||||||
if (previous->second.vaddr + previous->second.size > vaddr) {
|
if (previous->second.vaddr + previous->second.size > vaddr) {
|
||||||
first = previous;
|
mapping = previous;
|
||||||
}
|
|
||||||
}
|
|
||||||
for (auto mapping = first; mapping != m_maps.end() && mapping->second.vaddr < end;
|
|
||||||
++mapping) {
|
|
||||||
const auto& entry = mapping->second;
|
|
||||||
const auto start = std::max(vaddr, entry.vaddr);
|
|
||||||
const auto bytes = std::min(end, entry.vaddr + entry.size) - start;
|
|
||||||
if (!RangeOk(entry.backing_offset + start - entry.vaddr, bytes)) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* destination = static_cast<uint8_t*>(data);
|
auto* destination = static_cast<uint8_t*>(data);
|
||||||
auto cursor = vaddr;
|
auto cursor = vaddr;
|
||||||
for (auto mapping = first; mapping != m_maps.end() && mapping->second.vaddr < end;
|
for (; mapping != m_maps.end() && mapping->second.vaddr < end; ++mapping) {
|
||||||
++mapping) {
|
|
||||||
const auto& entry = mapping->second;
|
const auto& entry = mapping->second;
|
||||||
const auto start = std::max(vaddr, entry.vaddr);
|
const auto start = std::max(vaddr, entry.vaddr);
|
||||||
const auto bytes = std::min(end, entry.vaddr + entry.size) - start;
|
const auto bytes = std::min(end, entry.vaddr + entry.size) - start;
|
||||||
|
|||||||
@@ -465,6 +465,24 @@ void TestSparseBackingReadPreservesResidency() {
|
|||||||
std::all_of(bytes.begin() + commit_size * 2, bytes.end(),
|
std::all_of(bytes.begin() + commit_size * 2, bytes.end(),
|
||||||
[](uint8_t value) { return value == 0xa7; }),
|
[](uint8_t value) { return value == 0xa7; }),
|
||||||
"sparse backing read did not copy resident pages and zero nonresident pages");
|
"sparse backing read did not copy resident pages and zero nonresident pages");
|
||||||
|
constexpr size_t prefix = 37, suffix = 53;
|
||||||
|
constexpr size_t clipped_size = prefix + commit_size + suffix;
|
||||||
|
std::fill(bytes.begin(), bytes.end(), 0x5a);
|
||||||
|
Check(test,
|
||||||
|
Libs::LibKernel::Memory::TryReadSparseBacking(
|
||||||
|
base + commit_size - prefix, bytes.data() + 1, clipped_size),
|
||||||
|
"sparse backing read rejected unaligned resident edges around a hole");
|
||||||
|
Check(test, bytes.front() == 0x5a && bytes[clipped_size + 1] == 0x5a,
|
||||||
|
"clipped sparse backing read overwrote destination canaries");
|
||||||
|
Check(test,
|
||||||
|
std::all_of(bytes.begin() + 1, bytes.begin() + 1 + prefix,
|
||||||
|
[](uint8_t value) { return value == 0x3c; }) &&
|
||||||
|
std::all_of(bytes.begin() + 1 + prefix, bytes.begin() + 1 + prefix + commit_size,
|
||||||
|
[](uint8_t value) { return value == 0; }) &&
|
||||||
|
std::all_of(bytes.begin() + 1 + prefix + commit_size,
|
||||||
|
bytes.begin() + 1 + clipped_size,
|
||||||
|
[](uint8_t value) { return value == 0xa7; }),
|
||||||
|
"clipped sparse backing read misplaced resident bytes or the intervening hole");
|
||||||
std::fill(bytes.begin(), bytes.end(), 0x5a);
|
std::fill(bytes.begin(), bytes.end(), 0x5a);
|
||||||
Check(test, Libs::LibKernel::Memory::TryReadSparseBacking(base + commit_size, bytes.data(),
|
Check(test, Libs::LibKernel::Memory::TryReadSparseBacking(base + commit_size, bytes.data(),
|
||||||
bytes.size()),
|
bytes.size()),
|
||||||
|
|||||||
Reference in New Issue
Block a user