Darwin: Don't pass MAP_ANON to mmap when file mapping and mmap ret -1.

This appeared to work under x86, but on ARM this (rightfully) fails.
This commit is contained in:
Ty 2025-03-19 18:12:40 -04:00
parent a572c80896
commit e6c6cd82bf
No known key found for this signature in database
GPG Key ID: A0C3085FE2160BCF
2 changed files with 51 additions and 34 deletions

View File

@ -364,7 +364,7 @@ void* HostSys::MapMapping(void* handle, size_t size, const PageProtectionMode& m
{
const u32 mmap_prot = (mode.CanWrite() ? (PROT_READ | PROT_WRITE) : (PROT_READ)) | (mode.CanExecute() ? PROT_EXEC : 0);
return mmap(nullptr, size, mmap_prot, MAP_PRIVATE | MAP_ANON, static_cast<int>(reinterpret_cast<intptr_t>(handle)), 0);
return mmap(nullptr, size, mmap_prot, MAP_PRIVATE, static_cast<int>(reinterpret_cast<intptr_t>(handle)), 0);
}
void HostSys::DestroyMapping(void* handle)

View File

@ -338,43 +338,60 @@ void FileMemoryCard::Open()
}
if (!m_file[slot])
goto memoryCardOpenFailed;
m_fileSize[slot] = FileSystem::FSize64(m_file[slot]);
m_mapping_handles[slot] = HostSys::CreateMappingFromFile(m_file[slot]);
if (!m_mapping_handles[slot])
{
Host::ReportErrorAsync(TRANSLATE_SV("MemoryCard", "Memory Card Read Failed"),
fmt::format(TRANSLATE_FS("MemoryCard", "Unable to access memory card:\n\n{}\n\n"
"Another instance of PCSX2 may be using this memory card "
"or the memory card is stored in a write-protected folder.\n"
"Close any other instances of PCSX2, or restart your computer.\n"),
fname));
Console.Warning("MemoryCardFile: CreateMappingFromFile failed!");
goto memoryCardOpenFailed;
}
else // Load memory map and checksum
m_mappings[slot] = static_cast<u8*>(HostSys::MapMapping(m_mapping_handles[slot], m_fileSize[slot], PageAccess_ReadWrite()));
if (!m_mappings[slot] || reinterpret_cast<intptr_t>(m_mappings[slot]) < 0)
{
m_fileSize[slot] = FileSystem::FSize64(m_file[slot]);
m_mapping_handles[slot] = HostSys::CreateMappingFromFile(m_file[slot]);
if (!m_mapping_handles[slot])
{
Console.Warning("CreateMappingFromFile failed!");
}
m_mappings[slot] = static_cast<u8*>(HostSys::MapMapping(m_mapping_handles[slot], m_fileSize[slot], PageAccess_ReadWrite()));
if (!m_mappings[slot])
{
Console.Warning("MapSharedMemory failed! %d. %s", errno, strerror(errno));
}
Console.WriteLnFmt(Color_Green, "McdSlot {} [File]: {} [{} MB, {}]", slot, Path::GetFileName(fname),
(m_fileSize[slot] + (MCD_SIZE + 1)) / MC2_MBSIZE,
FileMcd_IsMemoryCardFormatted(m_file[slot]) ? "Formatted" : "UNFORMATTED");
m_filenames[slot] = std::move(fname);
m_ispsx[slot] = m_fileSize[slot] == 0x20000;
m_chkaddr = 0x210;
if (!m_ispsx[slot])
{
std::memcpy(&m_chksum[slot], m_mappings[slot] + m_chkaddr, sizeof(m_chksum[slot]));
}
Console.Warning("MemoryCardFile: MapSharedMemory failed! %d. %s", errno, strerror(errno));
goto memoryCardOpenFailed;
}
Console.WriteLnFmt(Color_Green, "McdSlot {} [File]: {} [{} MB, {}]", slot, Path::GetFileName(fname),
(m_fileSize[slot] + (MCD_SIZE + 1)) / MC2_MBSIZE,
FileMcd_IsMemoryCardFormatted(m_file[slot]) ? "Formatted" : "UNFORMATTED");
m_filenames[slot] = std::move(fname);
m_ispsx[slot] = m_fileSize[slot] == 0x20000;
m_chkaddr = 0x210;
if (!m_ispsx[slot])
{
std::memcpy(&m_chksum[slot], m_mappings[slot] + m_chkaddr, sizeof(m_chksum[slot]));
}
continue;
memoryCardOpenFailed:
Host::ReportErrorAsync(TRANSLATE_SV("MemoryCard", "Memory Card Read Failed"),
fmt::format(TRANSLATE_FS("MemoryCard", "Unable to access memory card:\n\n{}\n\n"
"Another instance of PCSX2 may be using this memory card "
"or the memory card is stored in a write-protected folder.\n"
"Close any other instances of PCSX2, or restart your computer.\n"),
fname));
if(m_mapping_handles[slot])
{
HostSys::DestroyMapping(m_mapping_handles[slot]);
}
if(m_file[slot])
{
std::fclose(m_file[slot]);
m_file[slot] = nullptr;
}
m_filenames[slot] = {};
m_fileSize[slot] = -1;
}
}