From 01cafc042d6256648c84a8fd6886f01b62330709 Mon Sep 17 00:00:00 2001 From: Eladash Date: Fri, 20 Mar 2020 20:34:44 +0200 Subject: [PATCH] cellSaveData: Ensure savedata_context members are 16-byte aligned I saw stvx v128{0} (aligned 16-bytes store) usage on the first 16-bytes of CellSaveDataCBResult before funcStat in fw. Also I saw 4 stw of u32{0} on it as well before funcFile, funcFixed and funcList. So just add the resets for result before all callbacks, and make all members of savedata_ontext 16 -byte aligned in case there are more members guaranteed to be aligned. --- rpcs3/Emu/Cell/Modules/cellSaveData.cpp | 26 ++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellSaveData.cpp b/rpcs3/Emu/Cell/Modules/cellSaveData.cpp index 52edb367c2..f7770ac2f9 100644 --- a/rpcs3/Emu/Cell/Modules/cellSaveData.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSaveData.cpp @@ -77,15 +77,15 @@ namespace { struct savedata_context { - CellSaveDataCBResult result; - CellSaveDataListGet listGet; - CellSaveDataListSet listSet; - CellSaveDataFixedSet fixedSet; - CellSaveDataStatGet statGet; - CellSaveDataStatSet statSet; - CellSaveDataFileGet fileGet; - CellSaveDataFileSet fileSet; - CellSaveDataDoneGet doneGet; + alignas(16) CellSaveDataCBResult result; + alignas(16) CellSaveDataListGet listGet; + alignas(16) CellSaveDataListSet listSet; + alignas(16) CellSaveDataFixedSet fixedSet; + alignas(16) CellSaveDataStatGet statGet; + alignas(16) CellSaveDataStatSet statSet; + alignas(16) CellSaveDataFileGet fileGet; + alignas(16) CellSaveDataFileSet fileSet; + alignas(16) CellSaveDataDoneGet doneGet; }; } @@ -704,6 +704,8 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v { listSet->focusPosition = CELL_SAVEDATA_FOCUSPOS_LISTHEAD; + std::memset(result.get_ptr(), 0, ::offset32(&CellSaveDataCBResult::userdata)); + // List Callback funcList(ppu, result, listGet, listSet); @@ -962,6 +964,7 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v doneGet->excResult = CELL_SAVEDATA_ERROR_NODATA; } + std::memset(result.get_ptr(), 0, ::offset32(&CellSaveDataCBResult::userdata)); funcDone(ppu, result, doneGet); }; @@ -1060,6 +1063,8 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v { lv2_sleep(ppu, 250); + std::memset(result.get_ptr(), 0, ::offset32(&CellSaveDataCBResult::userdata)); + // Fixed Callback funcFixed(ppu, result, listGet, fixedSet); @@ -1358,6 +1363,8 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v statGet->sysSizeKB = 35; // always reported as 35 regardless of actual file sizes statGet->sizeKB = !save_entry.isNew ? ::narrow((size_bytes / 1024) + statGet->sysSizeKB) : 0; + std::memset(result.get_ptr(), 0, ::offset32(&CellSaveDataCBResult::userdata)); + // Stat Callback funcStat(ppu, result, statGet, statSet); @@ -1516,6 +1523,7 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v { std::memset(fileSet.get_ptr(), 0, fileSet.size()); std::memset(fileGet->reserved, 0, sizeof(fileGet->reserved)); + std::memset(result.get_ptr(), 0, ::offset32(&CellSaveDataCBResult::userdata)); funcFile(ppu, result, fileGet, fileSet);