test(libc): require resident direct memory in the resident run tests

CheckBreakingAResidentRunKeepsConcurrentAccesses and
CheckRemappedDirectMemoryIsChargedOnce passed on main, where a singly
mapped direct memory page is a shared view and no resident run exists.
Both now require their first mapping to be private committed memory, so
on main they fail there instead of passing without exercising a run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V1W4jdNSKTV7xwuS6xQPJV
This commit is contained in:
thibaut 2026-10-14 00:24:09 +02:00
parent 71da166a18
commit f32a9407e4
1 changed files with 10 additions and 0 deletions

View File

@ -1403,6 +1403,14 @@ static void CheckSecondDirectMappingWaitsForLeases() {
#endif
}
#ifdef _WIN32
static void RequireResidentMapping(const void* address) {
MEMORY_BASIC_INFORMATION info{};
Require(VirtualQuery(address, &info, sizeof(info)) == sizeof(info));
Require(info.State == MEM_COMMIT && info.Type == MEM_PRIVATE);
}
#endif
static void CheckBreakingAResidentRunKeepsConcurrentAccesses() {
#ifdef _WIN32
constexpr std::size_t page = 0x4000;
@ -1414,6 +1422,7 @@ static void CheckBreakingAResidentRunKeepsConcurrentAccesses() {
Require(sceKernelAllocateDirectMemory(0, 0x7fffffffffll, chunk * chunks, 0, 0, &phys) == 0);
void* mapped = nullptr;
Require(sceKernelMapDirectMemory(&mapped, chunk * chunks, 3, 0, phys, 0) == 0);
RequireResidentMapping(mapped);
auto* memory = static_cast<volatile unsigned char*>(mapped);
const auto value = [&](std::size_t at) { return static_cast<unsigned char>((at * 31 + static_cast<std::size_t>(round)) | 1); };
const auto skipped = [&](std::size_t offset) { return unmap && offset >= page && offset < page * 2; };
@ -1487,6 +1496,7 @@ static void CheckRemappedDirectMemoryIsChargedOnce() {
Require(sceKernelAllocateDirectMemory(0, 0x7fffffffffll, bytes, 0, 0, &phys) == 0);
void* mapped = nullptr;
Require(sceKernelMapDirectMemory(&mapped, bytes, 3, 0, phys, 0) == 0);
RequireResidentMapping(mapped);
std::memset(mapped, 0xa5, bytes);
Require(sceKernelMunmap(mapped, bytes) == 0);
void* again = nullptr;