mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-09-11 03:56:02 +00:00
DiscIO: Improve IVolume::Read32 error handling
Callers can now check whether reads fail, either by checking the return value or by setting the buffer to a known bad value and seeing if it stays untouched. I've added error checks to FileSystemGCWii and Boot_BS2Emu, but not to Boot since it doesn't check any of its other reads either.
This commit is contained in:
parent
2b60eb0e22
commit
c7e747d775
6 changed files with 90 additions and 62 deletions
|
@ -60,17 +60,18 @@ void CBoot::Load_FST(bool _bIsWii)
|
|||
if (_bIsWii)
|
||||
shift = 2;
|
||||
|
||||
u32 fstOffset = volume.Read32(0x0424, _bIsWii) << shift;
|
||||
u32 fstSize = volume.Read32(0x0428, _bIsWii) << shift;
|
||||
u32 maxFstSize = volume.Read32(0x042c, _bIsWii) << shift;
|
||||
u32 fst_offset, fst_size, max_fst_size;
|
||||
volume.ReadSwapped(0x0424, &fst_offset, _bIsWii);
|
||||
volume.ReadSwapped(0x0428, &fst_size, _bIsWii);
|
||||
volume.ReadSwapped(0x042c, &max_fst_size, _bIsWii);
|
||||
|
||||
u32 arenaHigh = ROUND_DOWN(0x817FFFFF - maxFstSize, 0x20);
|
||||
Memory::Write_U32(arenaHigh, 0x00000034);
|
||||
u32 arena_high = ROUND_DOWN(0x817FFFFF - (max_fst_size << shift), 0x20);
|
||||
Memory::Write_U32(arena_high, 0x00000034);
|
||||
|
||||
// load FST
|
||||
DVDRead(fstOffset, arenaHigh, fstSize, _bIsWii);
|
||||
Memory::Write_U32(arenaHigh, 0x00000038);
|
||||
Memory::Write_U32(maxFstSize, 0x0000003c);
|
||||
DVDRead(fst_offset << shift, arena_high, fst_size << shift, _bIsWii);
|
||||
Memory::Write_U32(arena_high, 0x00000038);
|
||||
Memory::Write_U32(max_fst_size << shift, 0x0000003c);
|
||||
}
|
||||
|
||||
void CBoot::UpdateDebugger_MapLoaded()
|
||||
|
|
|
@ -90,15 +90,18 @@ bool CBoot::EmulatedBS2_GC(bool skipAppLoader)
|
|||
// Load Apploader to Memory - The apploader is hardcoded to begin at 0x2440 on the disc,
|
||||
// but the size can differ between discs. Compare with YAGCD chap 13.
|
||||
const DiscIO::IVolume& volume = DVDInterface::GetVolume();
|
||||
u32 iAppLoaderOffset = 0x2440;
|
||||
u32 iAppLoaderEntry = volume.Read32(iAppLoaderOffset + 0x10, false);
|
||||
u32 iAppLoaderSize = volume.Read32(iAppLoaderOffset + 0x14, false) + volume.Read32(iAppLoaderOffset + 0x18, false);
|
||||
if ((iAppLoaderEntry == (u32)-1) || (iAppLoaderSize == (u32)-1) || skipAppLoader)
|
||||
const u32 apploader_offset = 0x2440;
|
||||
u32 apploader_entry, apploader_size, apploader_trailer;
|
||||
if (skipAppLoader ||
|
||||
!volume.ReadSwapped(apploader_offset + 0x10, &apploader_entry, false) ||
|
||||
!volume.ReadSwapped(apploader_offset + 0x14, &apploader_size, false) ||
|
||||
!volume.ReadSwapped(apploader_offset + 0x18, &apploader_trailer, false) ||
|
||||
apploader_entry == (u32)-1 || apploader_size + apploader_trailer == (u32)-1)
|
||||
{
|
||||
INFO_LOG(BOOT, "GC BS2: Not running apploader!");
|
||||
return false;
|
||||
}
|
||||
DVDRead(iAppLoaderOffset + 0x20, 0x01200000, iAppLoaderSize, false);
|
||||
DVDRead(apploader_offset + 0x20, 0x01200000, apploader_size + apploader_trailer, false);
|
||||
|
||||
// Setup pointers like real BS2 does
|
||||
if (SConfig::GetInstance().bNTSC)
|
||||
|
@ -122,7 +125,7 @@ bool CBoot::EmulatedBS2_GC(bool skipAppLoader)
|
|||
PowerPC::ppcState.gpr[3] = iAppLoaderFuncAddr + 0;
|
||||
PowerPC::ppcState.gpr[4] = iAppLoaderFuncAddr + 4;
|
||||
PowerPC::ppcState.gpr[5] = iAppLoaderFuncAddr + 8;
|
||||
RunFunction(iAppLoaderEntry);
|
||||
RunFunction(apploader_entry);
|
||||
u32 iAppLoaderInit = PowerPC::Read_U32(iAppLoaderFuncAddr + 0);
|
||||
u32 iAppLoaderMain = PowerPC::Read_U32(iAppLoaderFuncAddr + 4);
|
||||
u32 iAppLoaderClose = PowerPC::Read_U32(iAppLoaderFuncAddr + 8);
|
||||
|
@ -365,18 +368,19 @@ bool CBoot::EmulatedBS2_Wii()
|
|||
|
||||
PowerPC::ppcState.gpr[1] = 0x816ffff0; // StackPointer
|
||||
|
||||
u32 iAppLoaderOffset = 0x2440; // 0x1c40;
|
||||
const u32 apploader_offset = 0x2440; // 0x1c40;
|
||||
|
||||
// Load Apploader to Memory
|
||||
const DiscIO::IVolume& volume = DVDInterface::GetVolume();
|
||||
u32 iAppLoaderEntry = volume.Read32(iAppLoaderOffset + 0x10, true);
|
||||
u32 iAppLoaderSize = volume.Read32(iAppLoaderOffset + 0x14, true);
|
||||
if ((iAppLoaderEntry == (u32)-1) || (iAppLoaderSize == (u32)-1))
|
||||
u32 apploader_entry, apploader_size;
|
||||
if (!volume.ReadSwapped(apploader_offset + 0x10, &apploader_entry, true) ||
|
||||
!volume.ReadSwapped(apploader_offset + 0x14, &apploader_size, true) ||
|
||||
apploader_entry == (u32)-1 || apploader_size == (u32)-1)
|
||||
{
|
||||
ERROR_LOG(BOOT, "Invalid apploader. Probably your image is corrupted.");
|
||||
return false;
|
||||
}
|
||||
DVDRead(iAppLoaderOffset + 0x20, 0x01200000, iAppLoaderSize, true);
|
||||
DVDRead(apploader_offset + 0x20, 0x01200000, apploader_size, true);
|
||||
|
||||
//call iAppLoaderEntry
|
||||
DEBUG_LOG(BOOT, "Call iAppLoaderEntry");
|
||||
|
@ -385,7 +389,7 @@ bool CBoot::EmulatedBS2_Wii()
|
|||
PowerPC::ppcState.gpr[3] = iAppLoaderFuncAddr + 0;
|
||||
PowerPC::ppcState.gpr[4] = iAppLoaderFuncAddr + 4;
|
||||
PowerPC::ppcState.gpr[5] = iAppLoaderFuncAddr + 8;
|
||||
RunFunction(iAppLoaderEntry);
|
||||
RunFunction(apploader_entry);
|
||||
u32 iAppLoaderInit = PowerPC::Read_U32(iAppLoaderFuncAddr + 0);
|
||||
u32 iAppLoaderMain = PowerPC::Read_U32(iAppLoaderFuncAddr + 4);
|
||||
u32 iAppLoaderClose = PowerPC::Read_U32(iAppLoaderFuncAddr + 8);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue