From 4b831a8583a436977ef8b2751258c4e057e06ac8 Mon Sep 17 00:00:00 2001 From: SaeHie Park Date: Wed, 30 Nov 2016 11:36:27 +0900 Subject: [PATCH] [x86/Linux] Fix Dacp structure size mismatch Fix compile error for x86/Linux - add __attribute__((__ms_struct__)) as "MSLAYOUT" for those structures - Fix "Dacp structs cannot be modified due to backwards compatibility" error --- src/debug/inc/common.h | 24 +-------- src/inc/dacprivate.h | 113 +++++++++++++++++++++++++---------------- 2 files changed, 69 insertions(+), 68 deletions(-) diff --git a/src/debug/inc/common.h b/src/debug/inc/common.h index 77fe27a4b3e8..3bbf0a6f08da 100644 --- a/src/debug/inc/common.h +++ b/src/debug/inc/common.h @@ -295,29 +295,7 @@ inline CORDB_ADDRESS ALIGN_ADDRESS( CORDB_ADDRESS val, CORDB_ADDRESS alignment ) return result; } -// -// Whenever a structure is marshalled between different platforms, we need to ensure the -// layout is the same in both cases. We tell GCC to use the MSVC-style packing with -// the following attribute. The main thing this appears to control is whether -// 8-byte values are aligned at 4-bytes (GCC default) or 8-bytes (MSVC default). -// This attribute affects only the immediate struct it is applied to, you must also apply -// it to any nested structs if you want their layout affected as well. You also must -// apply this to unions embedded in other structures, since it can influence the starting -// alignment. -// -// Note that there doesn't appear to be any disadvantage to applying this a little -// more agressively than necessary, so we generally use it on all classes / structures -// defined in a file that defines marshalled data types (eg. DacDbiStructures.h) -// The -mms-bitfields compiler option also does this for the whole file, but we don't -// want to go changing the layout of, for example, structures defined in OS header files -// so we explicitly opt-in with this attribute. -// -#ifdef __GNUC__ -#define MSLAYOUT __attribute__((__ms_struct__)) -#else -#define MSLAYOUT -#endif - +#include "dacprivate.h" // for MSLAYOUT #include "dumpcommon.h" #endif //DEBUGGER_COMMON_H diff --git a/src/inc/dacprivate.h b/src/inc/dacprivate.h index 5a09abe1132e..0db4affcfca8 100644 --- a/src/inc/dacprivate.h +++ b/src/inc/dacprivate.h @@ -20,6 +20,29 @@ #include #endif // FEATURE_PAL +// +// Whenever a structure is marshalled between different platforms, we need to ensure the +// layout is the same in both cases. We tell GCC to use the MSVC-style packing with +// the following attribute. The main thing this appears to control is whether +// 8-byte values are aligned at 4-bytes (GCC default) or 8-bytes (MSVC default). +// This attribute affects only the immediate struct it is applied to, you must also apply +// it to any nested structs if you want their layout affected as well. You also must +// apply this to unions embedded in other structures, since it can influence the starting +// alignment. +// +// Note that there doesn't appear to be any disadvantage to applying this a little +// more agressively than necessary, so we generally use it on all classes / structures +// defined in a file that defines marshalled data types (eg. DacDbiStructures.h) +// The -mms-bitfields compiler option also does this for the whole file, but we don't +// want to go changing the layout of, for example, structures defined in OS header files +// so we explicitly opt-in with this attribute. +// +#ifdef __GNUC__ +#define MSLAYOUT __attribute__((__ms_struct__)) +#else +#define MSLAYOUT +#endif + //---------------------------------------------------------------------------- // // Utility class to allow for zero initialization of our Dacp- structs. @@ -58,7 +81,7 @@ enum }; enum DacpObjectType { OBJ_STRING=0,OBJ_FREE,OBJ_OBJECT,OBJ_ARRAY,OBJ_OTHER }; -struct DacpObjectData : ZeroInit +struct MSLAYOUT DacpObjectData : ZeroInit { CLRDATA_ADDRESS MethodTable; DacpObjectType ObjectType; @@ -81,7 +104,7 @@ struct DacpObjectData : ZeroInit } }; -struct DacpExceptionObjectData : ZeroInit +struct MSLAYOUT DacpExceptionObjectData : ZeroInit { CLRDATA_ADDRESS Message; CLRDATA_ADDRESS InnerException; @@ -105,7 +128,7 @@ struct DacpExceptionObjectData : ZeroInit } }; -struct DacpUsefulGlobalsData : ZeroInit +struct MSLAYOUT DacpUsefulGlobalsData : ZeroInit { CLRDATA_ADDRESS ArrayMethodTable; CLRDATA_ADDRESS StringMethodTable; @@ -114,7 +137,7 @@ struct DacpUsefulGlobalsData : ZeroInit CLRDATA_ADDRESS FreeMethodTable; }; -struct DacpFieldDescData : ZeroInit +struct MSLAYOUT DacpFieldDescData : ZeroInit { CorElementType Type; CorElementType sigType; // ELEMENT_TYPE_XXX from signature. We need this to disply pretty name for String in minidump's case @@ -137,7 +160,7 @@ struct DacpFieldDescData : ZeroInit } }; -struct DacpMethodTableFieldData : ZeroInit +struct MSLAYOUT DacpMethodTableFieldData : ZeroInit { WORD wNumInstanceFields; WORD wNumStaticFields; @@ -154,7 +177,7 @@ struct DacpMethodTableFieldData : ZeroInit } }; -struct DacpMethodTableTransparencyData : ZeroInit +struct MSLAYOUT DacpMethodTableTransparencyData : ZeroInit { BOOL bHasCriticalTransparentInfo; BOOL bIsCritical; @@ -166,7 +189,7 @@ struct DacpMethodTableTransparencyData : ZeroInit +struct MSLAYOUT DacpDomainLocalModuleData : ZeroInit { // These two parameters are used as input params when calling the // no-argument form of Request below. @@ -186,7 +209,7 @@ struct DacpDomainLocalModuleData : ZeroInit }; -struct DacpThreadLocalModuleData : ZeroInit +struct MSLAYOUT DacpThreadLocalModuleData : ZeroInit { // These two parameters are used as input params when calling the // no-argument form of Request below. @@ -200,7 +223,7 @@ struct DacpThreadLocalModuleData : ZeroInit }; -struct DacpModuleData : ZeroInit +struct MSLAYOUT DacpModuleData : ZeroInit { CLRDATA_ADDRESS Address; CLRDATA_ADDRESS File; // A PEFile addr @@ -243,7 +266,7 @@ struct DacpModuleData : ZeroInit void operator=(const DacpModuleData&); }; -struct DacpMethodTableData : ZeroInit +struct MSLAYOUT DacpMethodTableData : ZeroInit { BOOL bIsFree; // everything else is NULL if this is true. CLRDATA_ADDRESS Module; @@ -260,7 +283,7 @@ struct DacpMethodTableData : ZeroInit BOOL bIsShared; // flags & enum_flag_DomainNeutral BOOL bIsDynamic; BOOL bContainsPointers; - + HRESULT Request(ISOSDacInterface *sos, CLRDATA_ADDRESS addr) { return sos->GetMethodTableData(addr, this); @@ -279,7 +302,7 @@ struct DacpMethodTableData : ZeroInit #define CLRSECURITYHOSTED 0x80 #define CLRHOSTED 0x80000000 -struct DacpThreadStoreData : ZeroInit +struct MSLAYOUT DacpThreadStoreData : ZeroInit { LONG threadCount; LONG unstartedThreadCount; @@ -290,14 +313,14 @@ struct DacpThreadStoreData : ZeroInit CLRDATA_ADDRESS finalizerThread; CLRDATA_ADDRESS gcThread; DWORD fHostConfig; // Uses hosting flags defined above - + HRESULT Request(ISOSDacInterface *sos) { return sos->GetThreadStoreData(this); } }; -struct DacpAppDomainStoreData : ZeroInit +struct MSLAYOUT DacpAppDomainStoreData : ZeroInit { CLRDATA_ADDRESS sharedDomain; CLRDATA_ADDRESS systemDomain; @@ -309,14 +332,14 @@ struct DacpAppDomainStoreData : ZeroInit } }; -struct DacpCOMInterfacePointerData : ZeroInit +struct MSLAYOUT DacpCOMInterfacePointerData : ZeroInit { CLRDATA_ADDRESS methodTable; CLRDATA_ADDRESS interfacePtr; CLRDATA_ADDRESS comContext; }; -struct DacpRCWData : ZeroInit +struct MSLAYOUT DacpRCWData : ZeroInit { CLRDATA_ADDRESS identityPointer; CLRDATA_ADDRESS unknownPointer; @@ -355,7 +378,7 @@ struct DacpRCWData : ZeroInit } }; -struct DacpCCWData : ZeroInit +struct MSLAYOUT DacpCCWData : ZeroInit { CLRDATA_ADDRESS outerIUnknown; CLRDATA_ADDRESS managedObject; @@ -397,7 +420,7 @@ enum DacpAppDomainDataStage { // Information about a BaseDomain (AppDomain, SharedDomain or SystemDomain). // For types other than AppDomain, some fields (like dwID, DomainLocalBlock, etc.) will be 0/null. -struct DacpAppDomainData : ZeroInit +struct MSLAYOUT DacpAppDomainData : ZeroInit { // The pointer to the BaseDomain (not necessarily an AppDomain). // It's useful to keep this around in the structure @@ -420,7 +443,7 @@ struct DacpAppDomainData : ZeroInit } }; -struct DacpAssemblyData : ZeroInit +struct MSLAYOUT DacpAssemblyData : ZeroInit { CLRDATA_ADDRESS AssemblyPtr; //useful to have CLRDATA_ADDRESS ClassLoader; @@ -445,7 +468,7 @@ struct DacpAssemblyData : ZeroInit }; -struct DacpThreadData : ZeroInit +struct MSLAYOUT DacpThreadData : ZeroInit { DWORD corThreadId; DWORD osThreadId; @@ -470,7 +493,7 @@ struct DacpThreadData : ZeroInit }; -struct DacpReJitData : ZeroInit +struct MSLAYOUT DacpReJitData : ZeroInit { enum Flags { @@ -485,7 +508,7 @@ struct DacpReJitData : ZeroInit CLRDATA_ADDRESS NativeCodeAddr; }; -struct DacpMethodDescData : ZeroInit +struct MSLAYOUT DacpMethodDescData : ZeroInit { BOOL bHasNativeCode; BOOL bIsDynamic; @@ -529,7 +552,7 @@ struct DacpMethodDescData : ZeroInit } }; -struct DacpMethodDescTransparencyData : ZeroInit +struct MSLAYOUT DacpMethodDescTransparencyData : ZeroInit { BOOL bHasCriticalTransparentInfo; BOOL bIsCritical; @@ -544,7 +567,7 @@ struct DacpMethodDescTransparencyData : ZeroInit // for JITType enum JITTypes {TYPE_UNKNOWN=0,TYPE_JIT,TYPE_PJIT}; -struct DacpCodeHeaderData : ZeroInit +struct MSLAYOUT DacpCodeHeaderData : ZeroInit { CLRDATA_ADDRESS GCInfo; JITTypes JITType; @@ -561,7 +584,7 @@ struct DacpCodeHeaderData : ZeroInit } }; -struct DacpWorkRequestData : ZeroInit +struct MSLAYOUT DacpWorkRequestData : ZeroInit { CLRDATA_ADDRESS Function; CLRDATA_ADDRESS Context; @@ -573,7 +596,7 @@ struct DacpWorkRequestData : ZeroInit } }; -struct DacpHillClimbingLogEntry : ZeroInit +struct MSLAYOUT DacpHillClimbingLogEntry : ZeroInit { DWORD TickCount; int Transition; @@ -589,7 +612,7 @@ struct DacpHillClimbingLogEntry : ZeroInit // Used for CLR versions >= 4.0 -struct DacpThreadpoolData : ZeroInit +struct MSLAYOUT DacpThreadpoolData : ZeroInit { LONG cpuUtilization; int NumIdleWorkerThreads; @@ -623,7 +646,7 @@ struct DacpThreadpoolData : ZeroInit } }; -struct DacpGenerationData : ZeroInit +struct MSLAYOUT DacpGenerationData : ZeroInit { CLRDATA_ADDRESS start_segment; CLRDATA_ADDRESS allocation_start; @@ -636,18 +659,18 @@ struct DacpGenerationData : ZeroInit #define DAC_NUMBERGENERATIONS 4 -struct DacpAllocData : ZeroInit +struct MSLAYOUT DacpAllocData : ZeroInit { CLRDATA_ADDRESS allocBytes; CLRDATA_ADDRESS allocBytesLoh; }; -struct DacpGenerationAllocData : ZeroInit +struct MSLAYOUT DacpGenerationAllocData : ZeroInit { DacpAllocData allocData[DAC_NUMBERGENERATIONS]; }; -struct DacpGcHeapDetails : ZeroInit +struct MSLAYOUT DacpGcHeapDetails : ZeroInit { CLRDATA_ADDRESS heapAddr; // Only filled in in server mode, otherwise NULL CLRDATA_ADDRESS alloc_allocated; @@ -681,7 +704,7 @@ struct DacpGcHeapDetails : ZeroInit } }; -struct DacpGcHeapData +struct MSLAYOUT DacpGcHeapData : ZeroInit { BOOL bServerMode; @@ -695,7 +718,7 @@ struct DacpGcHeapData } }; -struct DacpHeapSegmentData +struct MSLAYOUT DacpHeapSegmentData : ZeroInit { CLRDATA_ADDRESS segmentAddr; @@ -730,7 +753,7 @@ struct DacpHeapSegmentData } }; -struct DacpOomData : ZeroInit +struct MSLAYOUT DacpOomData : ZeroInit { int reason; ULONG64 alloc_size; @@ -761,7 +784,7 @@ struct DacpOomData : ZeroInit #define MAX_GC_MECHANISM_BITS_COUNT 2 // This is from ndp\clr\src\vm\common.h #define MAX_GLOBAL_GC_MECHANISMS_COUNT 6 -struct DacpGCInterestingInfoData : ZeroInit +struct MSLAYOUT DacpGCInterestingInfoData : ZeroInit { size_t interestingDataPoints[NUM_GC_DATA_POINTS]; size_t compactReasons[MAX_COMPACT_REASONS_COUNT]; @@ -808,7 +831,7 @@ struct DacpGCInterestingInfoData : ZeroInit } }; -struct DacpGcHeapAnalyzeData +struct MSLAYOUT DacpGcHeapAnalyzeData : ZeroInit { CLRDATA_ADDRESS heapAddr; // Only filled in in server mode, otherwise NULL @@ -836,7 +859,7 @@ struct DacpGcHeapAnalyzeData #define SYNCBLOCKDATA_COMFLAGS_RCW 2 #define SYNCBLOCKDATA_COMFLAGS_CF 4 -struct DacpSyncBlockData : ZeroInit +struct MSLAYOUT DacpSyncBlockData : ZeroInit { CLRDATA_ADDRESS Object; BOOL bFree; // if set, no other fields are useful @@ -863,7 +886,7 @@ struct DacpSyncBlockData : ZeroInit } }; -struct DacpSyncBlockCleanupData : ZeroInit +struct MSLAYOUT DacpSyncBlockCleanupData : ZeroInit { CLRDATA_ADDRESS SyncBlockPointer; @@ -883,7 +906,7 @@ struct DacpSyncBlockCleanupData : ZeroInit enum EHClauseType {EHFault, EHFinally, EHFilter, EHTyped, EHUnknown}; -struct DACEHInfo : ZeroInit +struct MSLAYOUT DACEHInfo : ZeroInit { EHClauseType clauseType; CLRDATA_ADDRESS tryStartOffset; @@ -898,7 +921,7 @@ struct DACEHInfo : ZeroInit mdToken tokCatch; // the type token of the TYPED clause type }; -struct DacpGetModuleAddress : ZeroInit +struct MSLAYOUT DacpGetModuleAddress : ZeroInit { CLRDATA_ADDRESS ModulePtr; HRESULT Request(IXCLRDataModule* pDataModule) @@ -907,7 +930,7 @@ struct DacpGetModuleAddress : ZeroInit } }; -struct DacpGetModuleData : ZeroInit +struct MSLAYOUT DacpGetModuleData : ZeroInit { BOOL IsDynamic; BOOL IsInMemory; @@ -924,7 +947,7 @@ struct DacpGetModuleData : ZeroInit } }; -struct DacpFrameData : ZeroInit +struct MSLAYOUT DacpFrameData : ZeroInit { CLRDATA_ADDRESS frameAddr; @@ -937,7 +960,7 @@ struct DacpFrameData : ZeroInit } }; -struct DacpJitManagerInfo : ZeroInit +struct MSLAYOUT DacpJitManagerInfo : ZeroInit { CLRDATA_ADDRESS managerAddr; DWORD codeType; // for union below @@ -946,14 +969,14 @@ struct DacpJitManagerInfo : ZeroInit enum CodeHeapType {CODEHEAP_LOADER=0,CODEHEAP_HOST,CODEHEAP_UNKNOWN}; -struct DacpJitCodeHeapInfo : ZeroInit +struct MSLAYOUT DacpJitCodeHeapInfo : ZeroInit { DWORD codeHeapType; // for union below union { CLRDATA_ADDRESS LoaderHeap; // if CODEHEAP_LOADER - struct + struct MSLAYOUT { CLRDATA_ADDRESS baseAddr; // if CODEHEAP_HOST CLRDATA_ADDRESS currentAddr;