From f9a67fbf6fd72987133d841a710ab6f417f264cb Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Tue, 25 Apr 2017 17:29:49 -0700 Subject: [PATCH 1/3] FifoFileStruct: replace unions with explicit padding --- Source/Core/Core/FifoPlayer/FifoFileStruct.h | 61 +++++++++----------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/Source/Core/Core/FifoPlayer/FifoFileStruct.h b/Source/Core/Core/FifoPlayer/FifoFileStruct.h index bfe6bdb741..d40f8f6a1f 100644 --- a/Source/Core/Core/FifoPlayer/FifoFileStruct.h +++ b/Source/Core/Core/FifoPlayer/FifoFileStruct.h @@ -15,44 +15,38 @@ enum MIN_LOADER_VERSION = 1, }; -#pragma pack(push, 4) +#pragma pack(push, 1) -union FileHeader +struct FileHeader { - struct - { - u32 fileId; - u32 file_version; - u32 min_loader_version; - u64 bpMemOffset; - u32 bpMemSize; - u64 cpMemOffset; - u32 cpMemSize; - u64 xfMemOffset; - u32 xfMemSize; - u64 xfRegsOffset; - u32 xfRegsSize; - u64 frameListOffset; - u32 frameCount; - u32 flags; - u64 texMemOffset; - u32 texMemSize; - }; - u32 rawData[32]; + u32 fileId; + u32 file_version; + u32 min_loader_version; + u64 bpMemOffset; + u32 bpMemSize; + u64 cpMemOffset; + u32 cpMemSize; + u64 xfMemOffset; + u32 xfMemSize; + u64 xfRegsOffset; + u32 xfRegsSize; + u64 frameListOffset; + u32 frameCount; + u32 flags; + u64 texMemOffset; + u32 texMemSize; + u8 reserved[40]; }; -union FileFrameInfo +struct FileFrameInfo { - struct - { - u64 fifoDataOffset; - u32 fifoDataSize; - u32 fifoStart; - u32 fifoEnd; - u64 memoryUpdatesOffset; - u32 numMemoryUpdates; - }; - u32 rawData[16]; + u64 fifoDataOffset; + u32 fifoDataSize; + u32 fifoStart; + u32 fifoEnd; + u64 memoryUpdatesOffset; + u32 numMemoryUpdates; + u8 reserved[32]; }; struct FileMemoryUpdate @@ -62,6 +56,7 @@ struct FileMemoryUpdate u64 dataOffset; u32 dataSize; u8 type; + u8 reserved[3]; }; #pragma pack(pop) From 6a6bfa0dbb15b73cdf6c50ae3888f98d85f489a7 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Tue, 25 Apr 2017 17:32:54 -0700 Subject: [PATCH 2/3] FifoPlayer: subsume FifoFileStruct.h into FifoDataFile.cpp There's no reason for it to be in its own file, and it's confusing. --- Source/Core/Core/Core.vcxproj | 1 - Source/Core/Core/Core.vcxproj.filters | 3 - Source/Core/Core/FifoPlayer/FifoDataFile.cpp | 54 ++++++++++++++++- Source/Core/Core/FifoPlayer/FifoFileStruct.h | 63 -------------------- 4 files changed, 52 insertions(+), 69 deletions(-) delete mode 100644 Source/Core/Core/FifoPlayer/FifoFileStruct.h diff --git a/Source/Core/Core/Core.vcxproj b/Source/Core/Core/Core.vcxproj index 50f452c4a3..db5b6fcaa2 100644 --- a/Source/Core/Core/Core.vcxproj +++ b/Source/Core/Core/Core.vcxproj @@ -339,7 +339,6 @@ - diff --git a/Source/Core/Core/Core.vcxproj.filters b/Source/Core/Core/Core.vcxproj.filters index e61dae56fa..2c4ecbe798 100644 --- a/Source/Core/Core/Core.vcxproj.filters +++ b/Source/Core/Core/Core.vcxproj.filters @@ -958,9 +958,6 @@ FifoPlayer - - FifoPlayer - FifoPlayer diff --git a/Source/Core/Core/FifoPlayer/FifoDataFile.cpp b/Source/Core/Core/FifoPlayer/FifoDataFile.cpp index 5a1fd476a3..dd90da5da7 100644 --- a/Source/Core/Core/FifoPlayer/FifoDataFile.cpp +++ b/Source/Core/Core/FifoPlayer/FifoDataFile.cpp @@ -9,9 +9,59 @@ #include "Common/FileUtil.h" #include "Core/FifoPlayer/FifoDataFile.h" -#include "Core/FifoPlayer/FifoFileStruct.h" -using namespace FifoFileStruct; +enum +{ + FILE_ID = 0x0d01f1f0, + VERSION_NUMBER = 4, + MIN_LOADER_VERSION = 1, +}; + +#pragma pack(push, 1) + +struct FileHeader +{ + u32 fileId; + u32 file_version; + u32 min_loader_version; + u64 bpMemOffset; + u32 bpMemSize; + u64 cpMemOffset; + u32 cpMemSize; + u64 xfMemOffset; + u32 xfMemSize; + u64 xfRegsOffset; + u32 xfRegsSize; + u64 frameListOffset; + u32 frameCount; + u32 flags; + u64 texMemOffset; + u32 texMemSize; + u8 reserved[40]; +}; + +struct FileFrameInfo +{ + u64 fifoDataOffset; + u32 fifoDataSize; + u32 fifoStart; + u32 fifoEnd; + u64 memoryUpdatesOffset; + u32 numMemoryUpdates; + u8 reserved[32]; +}; + +struct FileMemoryUpdate +{ + u32 fifoPosition; + u32 address; + u64 dataOffset; + u32 dataSize; + u8 type; + u8 reserved[3]; +}; + +#pragma pack(pop) FifoDataFile::FifoDataFile() = default; diff --git a/Source/Core/Core/FifoPlayer/FifoFileStruct.h b/Source/Core/Core/FifoPlayer/FifoFileStruct.h deleted file mode 100644 index d40f8f6a1f..0000000000 --- a/Source/Core/Core/FifoPlayer/FifoFileStruct.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2011 Dolphin Emulator Project -// Licensed under GPLv2+ -// Refer to the license.txt file included. - -#pragma once - -#include "Common/CommonTypes.h" - -namespace FifoFileStruct -{ -enum -{ - FILE_ID = 0x0d01f1f0, - VERSION_NUMBER = 4, - MIN_LOADER_VERSION = 1, -}; - -#pragma pack(push, 1) - -struct FileHeader -{ - u32 fileId; - u32 file_version; - u32 min_loader_version; - u64 bpMemOffset; - u32 bpMemSize; - u64 cpMemOffset; - u32 cpMemSize; - u64 xfMemOffset; - u32 xfMemSize; - u64 xfRegsOffset; - u32 xfRegsSize; - u64 frameListOffset; - u32 frameCount; - u32 flags; - u64 texMemOffset; - u32 texMemSize; - u8 reserved[40]; -}; - -struct FileFrameInfo -{ - u64 fifoDataOffset; - u32 fifoDataSize; - u32 fifoStart; - u32 fifoEnd; - u64 memoryUpdatesOffset; - u32 numMemoryUpdates; - u8 reserved[32]; -}; - -struct FileMemoryUpdate -{ - u32 fifoPosition; - u32 address; - u64 dataOffset; - u32 dataSize; - u8 type; - u8 reserved[3]; -}; - -#pragma pack(pop) -} From 82d0f6edb225c57e36772c397112300bafd53585 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Tue, 25 Apr 2017 17:43:37 -0700 Subject: [PATCH 3/3] FifoDataFile: static_assert that structs are right size --- Source/Core/Core/FifoPlayer/FifoDataFile.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Core/Core/FifoPlayer/FifoDataFile.cpp b/Source/Core/Core/FifoPlayer/FifoDataFile.cpp index dd90da5da7..3cb0d25493 100644 --- a/Source/Core/Core/FifoPlayer/FifoDataFile.cpp +++ b/Source/Core/Core/FifoPlayer/FifoDataFile.cpp @@ -39,6 +39,7 @@ struct FileHeader u32 texMemSize; u8 reserved[40]; }; +static_assert(sizeof(FileHeader) == 128, "FileHeader should be 128 bytes"); struct FileFrameInfo { @@ -50,6 +51,7 @@ struct FileFrameInfo u32 numMemoryUpdates; u8 reserved[32]; }; +static_assert(sizeof(FileFrameInfo) == 64, "FileFrameInfo should be 64 bytes"); struct FileMemoryUpdate { @@ -60,6 +62,7 @@ struct FileMemoryUpdate u8 type; u8 reserved[3]; }; +static_assert(sizeof(FileMemoryUpdate) == 24, "FileMemoryUpdate should be 24 bytes"); #pragma pack(pop)