diff --git a/src/coreclr/debug/di/hash.cpp b/src/coreclr/debug/di/hash.cpp index 6a70025c095e8c..911e0742814bb2 100644 --- a/src/coreclr/debug/di/hash.cpp +++ b/src/coreclr/debug/di/hash.cpp @@ -201,7 +201,7 @@ void CordbHashTableEnum::BuildOrThrow( CordbBase * pOwnerObj, NeuterList * pOwnerList, CordbHashTable *pTable, - const _GUID &id, + const GUID &id, RSInitHolder * pHolder) { CordbHashTableEnum * pEnum = new CordbHashTableEnum(pOwnerObj, pOwnerList, pTable, id); diff --git a/src/coreclr/debug/di/rspriv.h b/src/coreclr/debug/di/rspriv.h index 7b8098cf84a503..356c5e6ebee154 100644 --- a/src/coreclr/debug/di/rspriv.h +++ b/src/coreclr/debug/di/rspriv.h @@ -1837,14 +1837,14 @@ public ICorDebugAssemblyEnum CordbBase * pOwnerObj, NeuterList * pOwnerList, CordbHashTable *table, - const _GUID &id); + const GUID &id); public: static void BuildOrThrow( CordbBase * pOwnerObj, NeuterList * pOwnerList, CordbHashTable *table, - const _GUID &id, + const GUID &id, RSInitHolder * pHolder); CordbHashTableEnum(CordbHashTableEnum *cloneSrc); diff --git a/src/coreclr/debug/inc/dbgtransportsession.h b/src/coreclr/debug/inc/dbgtransportsession.h index 7a5df64d41eec8..7fc6087bed2bda 100644 --- a/src/coreclr/debug/inc/dbgtransportsession.h +++ b/src/coreclr/debug/inc/dbgtransportsession.h @@ -521,7 +521,7 @@ class DbgTransportSession // Struct defining the format of the data block sent with a SessionRequest. struct SessionRequestData { - minipal_guid_t m_sSessionID; // Unique session ID. Treated as byte blob so no endian-ness + GUID m_sSessionID; // Unique session ID. Treated as byte blob so no endian-ness }; // Struct used to track a message that is being (or will soon be) sent but has not yet been acknowledged. @@ -676,7 +676,7 @@ class DbgTransportSession // Session ID randomly allocated by the right side and sent over in the SessionRequest message. This // serves to disambiguate a re-send of the SessionRequest due to a network error versus a SessionRequest // from a different debugger. - minipal_guid_t m_sSessionID; + GUID m_sSessionID; // Lock used to synchronize sending messages and updating the session state. This ensures message bytes // don't become interleaved on the transport connection, the send queue is updated consistently across diff --git a/src/coreclr/ilasm/portable_pdb.cpp b/src/coreclr/ilasm/portable_pdb.cpp index a60214c99e9f39..3aa26fe1597a5f 100644 --- a/src/coreclr/ilasm/portable_pdb.cpp +++ b/src/coreclr/ilasm/portable_pdb.cpp @@ -93,7 +93,7 @@ HRESULT PortablePdbWriter::Init(IMetaDataDispenserEx2* mdDispenser) time_t now; time(&now); m_pdbStream.id.pdbTimeStamp = (ULONG)now; - if (!minipal_guid_v4_create(reinterpret_cast(&m_pdbStream.id.pdbGuid))) + if (!minipal_guid_v4_create(&m_pdbStream.id.pdbGuid)) { hr = E_FAIL; goto exit; diff --git a/src/coreclr/ildasm/dasm.cpp b/src/coreclr/ildasm/dasm.cpp index e30cea034d29e9..d3ef6797a1b7f0 100644 --- a/src/coreclr/ildasm/dasm.cpp +++ b/src/coreclr/ildasm/dasm.cpp @@ -5157,10 +5157,10 @@ void DumpCodeManager(IMAGE_COR20_HEADER *CORHeader, void* GUICookie) ULONG iCount = VAL32(CORHeader->CodeManagerTable.Size) / sizeof(GUID); for (ULONG i=0; ipLCD->FileToken != ulWasFileToken) { @@ -830,9 +830,9 @@ BOOL SourceLinesHelper(void *GUICookie, LineCodeDescr* pLCD, _Out_writes_(nSize) ||memcmp(&guidLangVendor,&guidWasLangVendor,sizeof(GUID)) ||memcmp(&guidDoc,&guidWasDoc,sizeof(GUID))) { - GuidToLPSTR(guidLang,zLang); - GuidToLPSTR(guidLangVendor,zVendor); - GuidToLPSTR(guidDoc,zDoc); + minipal_guid_as_string(guidLang, zLang, MINIPAL_GUID_BUFFER_LEN); + minipal_guid_as_string(guidLangVendor, zVendor, MINIPAL_GUID_BUFFER_LEN); + minipal_guid_as_string(guidDoc, zDoc, MINIPAL_GUID_BUFFER_LEN); sprintf_s(szString,SZSTRING_SIZE,"%s%s '%s', '%s', '%s'", g_szAsmCodeIndent,KEYWORD(".language"), zLang,zVendor,zDoc); printLine(pParam->GUICookie,szString); diff --git a/src/coreclr/ildasm/dman.cpp b/src/coreclr/ildasm/dman.cpp index 91761723a081c1..f045a4f8956313 100644 --- a/src/coreclr/ildasm/dman.cpp +++ b/src/coreclr/ildasm/dman.cpp @@ -120,7 +120,7 @@ void DumpScope(void* GUICookie) mdModule mdm; GUID mvid; WCHAR scopeName[1024]; - CHAR guidString[GUID_STR_BUFFER_LEN]; + CHAR guidString[MINIPAL_GUID_BUFFER_LEN]; memset(scopeName,0,1024*sizeof(WCHAR)); if(SUCCEEDED(g_pPubImport->GetScopeProps( scopeName, 1024, NULL, &mvid))&& scopeName[0]) { @@ -133,7 +133,7 @@ void DumpScope(void* GUICookie) VDELETE(sz); } printLine(GUICookie,szString); - GuidToLPSTR(mvid, guidString); + minipal_guid_as_string(mvid, guidString, MINIPAL_GUID_BUFFER_LEN); sprintf_s(szString,SZSTRING_SIZE,COMMENT("%s// MVID: %s"),g_szAsmCodeIndent,guidString); printLine(GUICookie,szString); diff --git a/src/coreclr/inc/jiteeversionguid.h b/src/coreclr/inc/jiteeversionguid.h index 77c4fb49ca8de1..ca025f62a7ec4d 100644 --- a/src/coreclr/inc/jiteeversionguid.h +++ b/src/coreclr/inc/jiteeversionguid.h @@ -32,16 +32,10 @@ ////////////////////////////////////////////////////////////////////////////////////////////////////////// // -#ifndef GUID_DEFINED -typedef struct _GUID { - uint32_t Data1; // NOTE: diff from Win32, for LP64 - uint16_t Data2; - uint16_t Data3; - uint8_t Data4[ 8 ]; -} GUID; -typedef const GUID *LPCGUID; -#define GUID_DEFINED -#endif // !GUID_DEFINED +#ifndef JIT_EE_VERSIONING_GUID_H +#define JIT_EE_VERSIONING_GUID_H + +#include constexpr GUID JITEEVersionIdentifier = { /* 4463d6ac-dfcb-4ab0-a941-c53b56089b7c */ 0x4463d6ac, @@ -50,8 +44,4 @@ constexpr GUID JITEEVersionIdentifier = { /* 4463d6ac-dfcb-4ab0-a941-c53b56089b7 {0xa9, 0x41, 0xc5, 0x3b, 0x56, 0x08, 0x9b, 0x7c} }; -////////////////////////////////////////////////////////////////////////////////////////////////////////// -// -// END JITEEVersionIdentifier -// -////////////////////////////////////////////////////////////////////////////////////////////////////////// +#endif // JIT_EE_VERSIONING_GUID_H diff --git a/src/coreclr/inc/utilcode.h b/src/coreclr/inc/utilcode.h index 30a0e38aa4c0a9..9b8e1ee3dfd704 100644 --- a/src/coreclr/inc/utilcode.h +++ b/src/coreclr/inc/utilcode.h @@ -35,7 +35,8 @@ using std::nothrow; #include "contract.h" -#include +#include +#include #include #include "clrnt.h" @@ -149,14 +150,10 @@ typedef LPSTR LPUTF8; #endif #endif -#include // for offsetof -#include - #define IS_DIGIT(ch) (((ch) >= W('0')) && ((ch) <= W('9'))) #define DIGIT_TO_INT(ch) ((ch) - W('0')) #define INT_TO_DIGIT(i) ((WCHAR)(W('0') + (i))) - // Helper will 4 byte align a value, rounding up. #define ALIGN4BYTE(val) (((val) + 3) & ~0x3) @@ -3031,23 +3028,6 @@ class ConfigMethodSet BYTE m_inited; }; -// 38 characters + 1 null terminating. -#define GUID_STR_BUFFER_LEN (ARRAY_SIZE("{12345678-1234-1234-1234-123456789abc}")) - -//***************************************************************************** -// Convert a GUID into a pointer to a string -//***************************************************************************** -int GuidToLPSTR( - REFGUID guid, // [IN] The GUID to convert. - LPSTR szGuid, // [OUT] String into which the GUID is stored - DWORD cchGuid); // [IN] Size in chars of szGuid - -template -int GuidToLPSTR(REFGUID guid, CHAR (&s)[N]) -{ - return GuidToLPSTR(guid, s, N); -} - //***************************************************************************** // Convert a pointer to a string into a GUID. //***************************************************************************** diff --git a/src/coreclr/nativeaot/Runtime/inc/CommonTypes.h b/src/coreclr/nativeaot/Runtime/inc/CommonTypes.h index 1b6e92b1788f27..e77e9878e3ebd2 100644 --- a/src/coreclr/nativeaot/Runtime/inc/CommonTypes.h +++ b/src/coreclr/nativeaot/Runtime/inc/CommonTypes.h @@ -53,12 +53,6 @@ typedef uint32_t ULONG; typedef int64_t LONGLONG; typedef uint8_t BYTE; typedef uint16_t UINT16; -typedef struct _GUID { - uint32_t Data1; - uint16_t Data2; - uint16_t Data3; - uint8_t Data4[8]; -} GUID; #endif // FEATURE_EVENT_TRACE && !_INC_WINDOWS // Hijack funcs are not called, they are "returned to". And when done, they return to the actual caller. diff --git a/src/coreclr/pal/inc/pal_mstypes.h b/src/coreclr/pal/inc/pal_mstypes.h index e3423c41f89803..a0762726ba18e9 100644 --- a/src/coreclr/pal/inc/pal_mstypes.h +++ b/src/coreclr/pal/inc/pal_mstypes.h @@ -9,6 +9,7 @@ #define __PAL_MSTYPES_H__ #include +#include #ifdef __cplusplus extern "C" { @@ -316,17 +317,6 @@ typedef union _LARGE_INTEGER { LONGLONG QuadPart; } LARGE_INTEGER, *PLARGE_INTEGER; -#ifndef GUID_DEFINED -typedef struct _GUID { - ULONG Data1; // NOTE: diff from Win32, for LP64 - USHORT Data2; - USHORT Data3; - UCHAR Data4[ 8 ]; -} GUID; -typedef const GUID *LPCGUID; -#define GUID_DEFINED -#endif // !GUID_DEFINED - typedef struct _FILETIME { DWORD dwLowDateTime; DWORD dwHighDateTime; diff --git a/src/coreclr/pal/inc/rt/palrt.h b/src/coreclr/pal/inc/rt/palrt.h index 9317654958b63b..91cd688fdbe862 100644 --- a/src/coreclr/pal/inc/rt/palrt.h +++ b/src/coreclr/pal/inc/rt/palrt.h @@ -2,27 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // -// -// =========================================================================== -// File: palrt.h -// -// =========================================================================== - /*++ - - Abstract: PAL runtime functions. These are functions which are ordinarily implemented as part of the Win32 API set, but when compiling CoreCLR for Unix-like systems, are implemented as a runtime library on top of the PAL. - -Author: - - - -Revision History: - --*/ #ifndef __PALRT_H__ @@ -213,19 +198,7 @@ EXTERN_C const GUID GUID_NULL; typedef GUID *LPGUID; typedef const GUID FAR *LPCGUID; -#ifdef __cplusplus -extern "C++" { -#if !defined _SYS_GUID_OPERATOR_EQ_ && !defined _NO_SYS_GUID_OPERATOR_EQ_ -#define _SYS_GUID_OPERATOR_EQ_ -inline int IsEqualGUID(REFGUID rguid1, REFGUID rguid2) - { return !memcmp(&rguid1, &rguid2, sizeof(GUID)); } -inline int operator==(REFGUID guidOne, REFGUID guidOther) - { return IsEqualGUID(guidOne,guidOther); } -inline int operator!=(REFGUID guidOne, REFGUID guidOther) - { return !IsEqualGUID(guidOne,guidOther); } -#endif -}; -#endif // __cplusplus +#define IsEqualGUID(guid1, guid2) guid1 == guid2 #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ EXTERN_C const GUID FAR name diff --git a/src/coreclr/scripts/genEventing.py b/src/coreclr/scripts/genEventing.py index b7439e2b4f7d68..d97a3a080bca1b 100644 --- a/src/coreclr/scripts/genEventing.py +++ b/src/coreclr/scripts/genEventing.py @@ -875,6 +875,7 @@ def getKeywordsMaskCombined(keywords, keywordsToMask): def updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, is_host_windows, eventpipe_trace_context_typedef, dotnet_trace_context_typedef_windows, user_events_trace_context_typedef, tree, clrallevents, inclusion_list, generatedFileType, user_events): with open_for_update(clrallevents) as Clrallevents: Clrallevents.write(stdprolog) + Clrallevents.write('#include \n\n') if generatedFileType=="header-impl": if runtimeFlavor.mono: Clrallevents.write(getCoreCLRMonoNativeAotTypeAdaptionDefines() + "\n") @@ -912,7 +913,7 @@ def updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, is_host_wi Clrallevents.write(dotnet_trace_context_typedef_windows + "\n") else: Clrallevents.write("\n") - + if not is_host_windows and runtimeFlavor.coreclr: Clrallevents.write(user_events_trace_context_typedef) diff --git a/src/coreclr/tools/metainfo/mdinfo.cpp b/src/coreclr/tools/metainfo/mdinfo.cpp index 927949b104ee5e..bac3b2158117aa 100644 --- a/src/coreclr/tools/metainfo/mdinfo.cpp +++ b/src/coreclr/tools/metainfo/mdinfo.cpp @@ -514,7 +514,10 @@ void MDInfo::DisplayScopeInfo() VWriteLine("ScopeName : %s",ConvertToUtf8(scopeName, scopeNameUtf8, ARRAY_SIZE(scopeNameUtf8))); if (!(m_DumpFilter & MDInfo::dumpNoLogo)) - VWriteLine("MVID : %s",GUIDAsString(mvid, guidString, STRING_BUFFER_LEN)); + { + minipal_guid_as_string(mvid, guidString, STRING_BUFFER_LEN); + VWriteLine("MVID : %s", guidString); + } hr = m_pImport->GetModuleFromScope(&mdm); if (FAILED(hr)) Error("GetModuleFromScope failed.", hr); @@ -2189,15 +2192,6 @@ void MDInfo::DisplayPermissionInfo(mdPermission inPermission, const char *preFix DisplayCustomAttributes(inPermission, newPreFix); } // void MDInfo::DisplayPermissionInfo() - -// simply prints out the given GUID in standard form - -LPCSTR MDInfo::GUIDAsString(GUID inGuid, _Out_writes_(bufLen) LPSTR guidString, ULONG bufLen) -{ - GuidToLPSTR(inGuid, guidString, bufLen); - return guidString; -} // LPCSTR MDInfo::GUIDAsString() - #ifdef FEATURE_COMINTEROP LPCSTR MDInfo::VariantAsString(VARIANT *pVariant, _Out_writes_(bufLen) LPSTR buffer, ULONG bufLen) { diff --git a/src/coreclr/tools/superpmi/superpmi/jitinstance.cpp b/src/coreclr/tools/superpmi/superpmi/jitinstance.cpp index 40e6b0c2e22b67..4bc2fb0784aa88 100644 --- a/src/coreclr/tools/superpmi/superpmi/jitinstance.cpp +++ b/src/coreclr/tools/superpmi/superpmi/jitinstance.cpp @@ -225,13 +225,13 @@ HRESULT JitInstance::StartUp(char* PathToJit, bool copyJit, bool breakOnDebugBre GUID expected = JITEEVersionIdentifier; GUID actual = versionId; LogError("Jit Compiler has wrong version identifier. Expected: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x. Actual: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x.", - expected.Data1, expected.Data2, expected.Data3, + expected.Data1, expected.Data2, expected.Data3, expected.Data4[0], expected.Data4[1], expected.Data4[2], expected.Data4[3], expected.Data4[4], expected.Data4[5], expected.Data4[6], expected.Data4[7], - actual.Data1, actual.Data2, actual.Data3, + actual.Data1, actual.Data2, actual.Data3, actual.Data4[0], actual.Data4[1], actual.Data4[2], actual.Data4[3], actual.Data4[4], actual.Data4[5], actual.Data4[6], actual.Data4[7]); - + return -1; } diff --git a/src/coreclr/utilcode/util.cpp b/src/coreclr/utilcode/util.cpp index 1ff5d5e1fc8ab4..8a9c78fbee76b6 100644 --- a/src/coreclr/utilcode/util.cpp +++ b/src/coreclr/utilcode/util.cpp @@ -2649,7 +2649,7 @@ namespace Com { STANDARD_VM_CONTRACT; - WCHAR wszClsid[GUID_STR_BUFFER_LEN]; + WCHAR wszClsid[MINIPAL_GUID_BUFFER_LEN]; if (GuidToLPWSTR(rclsid, wszClsid) == 0) return E_UNEXPECTED; diff --git a/src/coreclr/utilcode/util_nodependencies.cpp b/src/coreclr/utilcode/util_nodependencies.cpp index 3a08158b0daadb..59f8bcd8edb825 100644 --- a/src/coreclr/utilcode/util_nodependencies.cpp +++ b/src/coreclr/utilcode/util_nodependencies.cpp @@ -434,27 +434,6 @@ HRESULT GetDebuggerSettingInfoWorker(_Out_writes_to_opt_(*pcchDebuggerString, *p #endif //!defined(FEATURE_UTILCODE_NO_DEPENDENCIES) || defined(_DEBUG) - -//***************************************************************************** -// Convert a GUID into a pointer to a string -//***************************************************************************** -int -GuidToLPSTR( - REFGUID guid, // The GUID to convert. - _Out_writes_(cchGuid) LPSTR szGuid, // String into which the GUID is stored - DWORD cchGuid) // Count in chars -{ - if (cchGuid < GUID_STR_BUFFER_LEN) - return 0; - - return sprintf_s(szGuid, cchGuid, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", - guid.Data1, guid.Data2, guid.Data3, - guid.Data4[0], guid.Data4[1], - guid.Data4[2], guid.Data4[3], - guid.Data4[4], guid.Data4[5], - guid.Data4[6], guid.Data4[7]) + 1; -} - //***************************************************************************** // Convert hex value into a wide string of hex digits //***************************************************************************** @@ -508,7 +487,7 @@ GuidToLPWSTR( // successive fields break the GUID into the form DWORD-WORD-WORD-WORD-WORD.DWORD // covering the 128-bit GUID. The string includes enclosing braces, which are an OLE convention. - if (cchGuid < GUID_STR_BUFFER_LEN) + if (cchGuid < MINIPAL_GUID_BUFFER_LEN) return 0; // {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} diff --git a/src/coreclr/vm/assemblybinder.cpp b/src/coreclr/vm/assemblybinder.cpp index 23dbd296cff859..3c82bbb0664c30 100644 --- a/src/coreclr/vm/assemblybinder.cpp +++ b/src/coreclr/vm/assemblybinder.cpp @@ -44,11 +44,11 @@ NativeImage* AssemblyBinder::LoadNativeImage(Module* componentModule, LPCUTF8 na #ifdef FEATURE_READYTORUN static void MvidMismatchFatalError(GUID mvidActual, GUID mvidExpected, LPCUTF8 simpleName, bool compositeComponent, LPCUTF8 assemblyRequirementName) { - CHAR assemblyMvidText[GUID_STR_BUFFER_LEN]; - GuidToLPSTR(mvidActual, assemblyMvidText); + CHAR assemblyMvidText[MINIPAL_GUID_BUFFER_LEN]; + minipal_guid_as_string(mvidActual, assemblyMvidText, MINIPAL_GUID_BUFFER_LEN); - CHAR componentMvidText[GUID_STR_BUFFER_LEN]; - GuidToLPSTR(mvidExpected, componentMvidText); + CHAR componentMvidText[MINIPAL_GUID_BUFFER_LEN]; + minipal_guid_as_string(mvidExpected, componentMvidText, MINIPAL_GUID_BUFFER_LEN); SString message; if (compositeComponent) diff --git a/src/coreclr/vm/comcallablewrapper.cpp b/src/coreclr/vm/comcallablewrapper.cpp index 5b15ff2a3332ba..d4ab264a755747 100644 --- a/src/coreclr/vm/comcallablewrapper.cpp +++ b/src/coreclr/vm/comcallablewrapper.cpp @@ -3647,8 +3647,8 @@ BOOL ComMethodTable::LayOutInterfaceMethodTable(MethodTable* pClsMT) { BEGIN_PROFILER_CALLBACK(CORProfilerTrackCCW()); #if defined(_DEBUG) - CHAR rIID[GUID_STR_BUFFER_LEN]; - GuidToLPSTR(m_IID, rIID); + CHAR rIID[MINIPAL_GUID_BUFFER_LEN]; + minipal_guid_as_string(m_IID, rIID, MINIPAL_GUID_BUFFER_LEN); LOG((LF_CORPROF, LL_INFO100, "COMClassicVTableCreated Class:%hs, IID:%s, vTbl:%#08x\n", pItfClass->GetDebugClassName(), rIID, pUnkVtable)); #else @@ -4698,8 +4698,8 @@ ComCallWrapperTemplate* ComCallWrapperTemplate::CreateTemplate(TypeHandle thClas GenerateClassItfGuid(thClass, &IClassXIID); #if defined(_DEBUG) - CHAR rIID[GUID_STR_BUFFER_LEN]; - GuidToLPSTR(IClassXIID, rIID); + CHAR rIID[MINIPAL_GUID_BUFFER_LEN]; + minipal_guid_as_string(IClassXIID, rIID, MINIPAL_GUID_BUFFER_LEN); SString ssName; thClass.GetName(ssName); LOG((LF_CORPROF, LL_INFO100, "COMClassicVTableCreated Class:%s, IID:%s, vTbl:%#08x\n", diff --git a/src/coreclr/vm/eventpipeinternal.cpp b/src/coreclr/vm/eventpipeinternal.cpp index 0c89c706b30511..1fabe8f08ef967 100644 --- a/src/coreclr/vm/eventpipeinternal.cpp +++ b/src/coreclr/vm/eventpipeinternal.cpp @@ -192,7 +192,7 @@ extern "C" int QCALLTYPE EventPipeInternal_EventActivityIdControl(uint32_t contr case ActivityControlCode::EVENT_ACTIVITY_CONTROL_CREATE_ID: - minipal_guid_v4_create(reinterpret_cast(pActivityId)); + minipal_guid_v4_create(pActivityId); break; case ActivityControlCode::EVENT_ACTIVITY_CONTROL_GET_SET_ID: diff --git a/src/coreclr/vm/interoputil.cpp b/src/coreclr/vm/interoputil.cpp index ee12cd717164e3..468d5ef7ffd796 100644 --- a/src/coreclr/vm/interoputil.cpp +++ b/src/coreclr/vm/interoputil.cpp @@ -3913,8 +3913,7 @@ VOID LogInteropQI(IUnknown* pItf, REFIID iid, HRESULT hrArg, _In_z_ LPCSTR szMsg LPVOID pCurrCtx = NULL; HRESULT hr = S_OK; SafeComHolder pUnk = NULL; - int cch = 0; - CHAR szIID[GUID_STR_BUFFER_LEN]; + CHAR szIID[MINIPAL_GUID_BUFFER_LEN]; hr = SafeQueryInterface(pItf, IID_IUnknown, &pUnk); @@ -3922,8 +3921,7 @@ VOID LogInteropQI(IUnknown* pItf, REFIID iid, HRESULT hrArg, _In_z_ LPCSTR szMsg { pCurrCtx = GetCurrentCtxCookie(); - cch = GuidToLPSTR(iid, szIID); - _ASSERTE(cch > 0); + minipal_guid_as_string(iid, szIID, MINIPAL_GUID_BUFFER_LEN); if (SUCCEEDED(hrArg)) { diff --git a/src/coreclr/vm/perfmap.cpp b/src/coreclr/vm/perfmap.cpp index 1f515b00922eef..e3892bd1018f6c 100644 --- a/src/coreclr/vm/perfmap.cpp +++ b/src/coreclr/vm/perfmap.cpp @@ -99,7 +99,7 @@ void PerfMap::Enable(PerfMapType type, bool sendExisting) { s_ShowOptimizationTiers = true; } - + s_enabled = true; } } @@ -164,7 +164,7 @@ void PerfMap::Enable(PerfMapType type, bool sendExisting) codeInfo.GetMethodRegionInfo(&methodRegionInfo); _ASSERTE(methodRegionInfo.hotStartAddress == codeStart); _ASSERTE(methodRegionInfo.hotSize > 0); - + PrepareCodeConfig config(!nativeCodeVersion.IsNull() ? nativeCodeVersion : NativeCodeVersion(pMethod), FALSE, FALSE); PerfMap::LogJITCompiledMethod(pMethod, codeStart, methodRegionInfo.hotSize, &config); } @@ -425,16 +425,13 @@ void PerfMap::GetNativeImageSignature(PEAssembly * pPEAssembly, CHAR * pszSig, u CONTRACTL{ PRECONDITION(pPEAssembly != nullptr); PRECONDITION(pszSig != nullptr); - PRECONDITION(nSigSize >= GUID_STR_BUFFER_LEN); + PRECONDITION(nSigSize >= MINIPAL_GUID_BUFFER_LEN); } CONTRACTL_END; // We use the MVID as the signature, since ready to run images // don't have a native image signature. GUID mvid; pPEAssembly->GetMVID(&mvid); - if(!GuidToLPSTR(mvid, pszSig, nSigSize)) - { - pszSig[0] = '\0'; - } + minipal_guid_as_string(mvid, pszSig, nSigSize); } #endif // FEATURE_PERFMAP && !DACCESS_COMPILE diff --git a/src/coreclr/vm/profilinghelper.cpp b/src/coreclr/vm/profilinghelper.cpp index 60d200d46da7ad..d94dce9d89c9c1 100644 --- a/src/coreclr/vm/profilinghelper.cpp +++ b/src/coreclr/vm/profilinghelper.cpp @@ -707,8 +707,8 @@ HRESULT ProfilingAPIUtility::AttemptLoadProfilerForStartup() return hr; } - char clsidUtf8[GUID_STR_BUFFER_LEN]; - GuidToLPSTR(clsid, clsidUtf8); + char clsidUtf8[MINIPAL_GUID_BUFFER_LEN]; + minipal_guid_as_string(clsid, clsidUtf8, MINIPAL_GUID_BUFFER_LEN); hr = LoadProfiler( kStartupLoad, &clsid, @@ -741,8 +741,8 @@ HRESULT ProfilingAPIUtility::AttemptLoadDelayedStartupProfilers() LOG((LF_CORPROF, LL_INFO10, "**PROF: Profiler loading from GUID/Path stored from the IPC channel.")); CLSID *pClsid = &(item->guid); - char clsidUtf8[GUID_STR_BUFFER_LEN]; - GuidToLPSTR(*pClsid, clsidUtf8); + char clsidUtf8[MINIPAL_GUID_BUFFER_LEN]; + minipal_guid_as_string(*pClsid, clsidUtf8, MINIPAL_GUID_BUFFER_LEN); HRESULT hr = LoadProfiler( kStartupLoad, pClsid, @@ -824,8 +824,8 @@ HRESULT ProfilingAPIUtility::AttemptLoadProfilerList() continue; } - char clsidUtf8[GUID_STR_BUFFER_LEN]; - GuidToLPSTR(clsid, clsidUtf8); + char clsidUtf8[MINIPAL_GUID_BUFFER_LEN]; + minipal_guid_as_string(clsid, clsidUtf8, MINIPAL_GUID_BUFFER_LEN); hr = LoadProfiler( kStartupLoad, &clsid, diff --git a/src/coreclr/vm/profilinghelper.inl b/src/coreclr/vm/profilinghelper.inl index 87aff4efd19ef2..eb529e55dfa686 100644 --- a/src/coreclr/vm/profilinghelper.inl +++ b/src/coreclr/vm/profilinghelper.inl @@ -110,8 +110,8 @@ inline void ProfilingAPIUtility::LogNoInterfaceError(REFIID iidRequested, LPCSTR } CONTRACTL_END; - char iidUtf8[GUID_STR_BUFFER_LEN]; - GuidToLPSTR(iidRequested, iidUtf8); + char iidUtf8[MINIPAL_GUID_BUFFER_LEN]; + minipal_guid_as_string(iidRequested, iidUtf8, MINIPAL_GUID_BUFFER_LEN); ProfilingAPIUtility::LogProfError(IDS_E_PROF_NO_CALLBACK_IFACE, szCLSID, (LPCSTR)iidUtf8); } @@ -176,8 +176,8 @@ inline HRESULT ProfilingAPIUtility::LoadProfilerForAttach( CONTRACTL_END; // Inform user we're about to try attaching the profiler - char clsidUtf8[GUID_STR_BUFFER_LEN]; - GuidToLPSTR(*pClsid, clsidUtf8); + char clsidUtf8[MINIPAL_GUID_BUFFER_LEN]; + minipal_guid_as_string(*pClsid, clsidUtf8, MINIPAL_GUID_BUFFER_LEN); ProfilingAPIUtility::LogProfInfo(IDS_PROF_ATTACH_REQUEST_RECEIVED, (LPCSTR)clsidUtf8); return LoadProfiler( diff --git a/src/coreclr/vm/runtimecallablewrapper.cpp b/src/coreclr/vm/runtimecallablewrapper.cpp index 04eff1d909f30f..3be731e6654e96 100644 --- a/src/coreclr/vm/runtimecallablewrapper.cpp +++ b/src/coreclr/vm/runtimecallablewrapper.cpp @@ -65,7 +65,7 @@ void ComClassFactory::ThrowHRMsg(HRESULT hr, DWORD dwMsgResID) SString strMessage; SString strResource; - WCHAR strClsid[GUID_STR_BUFFER_LEN]; + WCHAR strClsid[MINIPAL_GUID_BUFFER_LEN]; SString strHRDescription; // Obtain the textual representation of the HRESULT. @@ -505,7 +505,7 @@ IClassFactory *ComClassFactory::GetIClassFactory() { SString strMessage; SString strResource; - WCHAR strClsid[GUID_STR_BUFFER_LEN]; + WCHAR strClsid[MINIPAL_GUID_BUFFER_LEN]; SString strHRDescription; // Obtain the textual representation of the HRESULT. @@ -2512,7 +2512,7 @@ void ComObject::ThrowInvalidCastException(OBJECTREF *pObj, MethodTable *pCastToM } // Convert the IID to a string. - WCHAR strIID[GUID_STR_BUFFER_LEN]; + WCHAR strIID[MINIPAL_GUID_BUFFER_LEN]; GuidToLPWSTR(iid, strIID); // Obtain the textual description of the HRESULT. @@ -2530,7 +2530,7 @@ void ComObject::ThrowInvalidCastException(OBJECTREF *pObj, MethodTable *pCastToM pSrcItfClass->GetGuid(&SrcItfIID, TRUE); // Convert the source interface IID to a string. - WCHAR strSrcItfIID[GUID_STR_BUFFER_LEN]; + WCHAR strSrcItfIID[MINIPAL_GUID_BUFFER_LEN]; GuidToLPWSTR(SrcItfIID, strSrcItfIID); COMPlusThrow(kInvalidCastException, IDS_EE_RCW_INVALIDCAST_EVENTITF, strHRDescription.GetUnicode(), strComObjClassName.GetUnicode(), diff --git a/src/native/eventpipe/ep-thread.h b/src/native/eventpipe/ep-thread.h index a4e6e3b73e4222..81093ec06827bd 100644 --- a/src/native/eventpipe/ep-thread.h +++ b/src/native/eventpipe/ep-thread.h @@ -117,7 +117,7 @@ ep_thread_create_activity_id ( EP_ASSERT (activity_id != NULL); EP_ASSERT (activity_id_len == EP_ACTIVITY_ID_SIZE); - minipal_guid_v4_create ((minipal_guid_t *)(activity_id)); + minipal_guid_v4_create ((GUID *)(activity_id)); } static diff --git a/src/native/minipal/guid.c b/src/native/minipal/guid.c index 8002e323c40784..a3620c10783c3a 100644 --- a/src/native/minipal/guid.c +++ b/src/native/minipal/guid.c @@ -4,6 +4,8 @@ #include "guid.h" #include "random.h" #include +#include +#include #ifdef HOST_WINDOWS #include #endif @@ -26,11 +28,11 @@ // o Set all the other bits to randomly (or pseudo-randomly) chosen // values. // -bool minipal_guid_v4_create(minipal_guid_t* guid) +bool minipal_guid_v4_create(GUID* guid) { #ifdef HOST_WINDOWS // Windows has a built-in function for creating v4 GUIDs. - return SUCCEEDED(CoCreateGuid((GUID*)guid)); + return SUCCEEDED(CoCreateGuid(guid)); #else // Technically, v4 GUIDs don't require cryptographically secure random bytes; // however, CoCreateGuid provides that guarantee and we want to ensure @@ -42,21 +44,36 @@ bool minipal_guid_v4_create(minipal_guid_t* guid) // time_hi_and_version const uint16_t mask = 0xf000; // b1111000000000000 const uint16_t value = 0x4000; // b0100000000000000 - guid->data3 = (guid->data3 & ~mask) | value; + guid->Data3 = (guid->Data3 & ~mask) | value; } { // clock_seq_hi_and_reserved const uint8_t mask = 0xc0; // b11000000 const uint8_t value = 0x80; // b10000000 - guid->data4[0] = (guid->data4[0] & ~mask) | value; + guid->Data4[0] = (guid->Data4[0] & ~mask) | value; } return true; #endif } -bool minipal_guid_equals(minipal_guid_t const* g1, minipal_guid_t const* g2) +bool minipal_guid_equals(GUID const* g1, GUID const* g2) { - return memcmp(g1, g2, sizeof(minipal_guid_t)) == 0; + return memcmp(g1, g2, sizeof(GUID)) == 0; +} + +void minipal_guid_as_string(GUID guid, char* guidString, uint32_t len) +{ + assert(len >= MINIPAL_GUID_BUFFER_LEN); + + int32_t nBytes = snprintf(guidString, len, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", + guid.Data1, guid.Data2, guid.Data3, + guid.Data4[0], guid.Data4[1], + guid.Data4[2], guid.Data4[3], + guid.Data4[4], guid.Data4[5], + guid.Data4[6], guid.Data4[7]); + + (void)nBytes; // unused in release mode + assert(nBytes == MINIPAL_GUID_BUFFER_LEN - 1); } diff --git a/src/native/minipal/guid.h b/src/native/minipal/guid.h index ef7dcaaadca7b4..b9abaedd6fb28f 100644 --- a/src/native/minipal/guid.h +++ b/src/native/minipal/guid.h @@ -6,45 +6,73 @@ #include #include +#include #ifdef __cplusplus extern "C" { #endif // __cplusplus +#ifdef _WIN32 +#include +#else // _WIN32 typedef struct minipal_guid__ { - uint32_t data1; - uint16_t data2; - uint16_t data3; - uint8_t data4[8]; -} minipal_guid_t; + uint32_t Data1; + uint16_t Data2; + uint16_t Data3; + uint8_t Data4[8]; +} GUID; +#endif // _WIN32 -bool minipal_guid_v4_create(minipal_guid_t* guid); +/** + * Define the buffer length required to store a GUID string, including the null terminator. + * + * This accounts for the standard GUID format: "{12345678-1234-1234-1234-123456789abc}" + * which consists of 38 characters plus 1 null-terminating character. + */ +#define MINIPAL_GUID_BUFFER_LEN (ARRAY_SIZE("{12345678-1234-1234-1234-123456789abc}")) -bool minipal_guid_equals(minipal_guid_t const* g1, minipal_guid_t const* g2); +/** + * Generate a new version 4 GUID (randomly generated) + * + * @param guid Pointer to a GUID structure to receive the new GUID. + * @return true if the GUID was successfully created, false otherwise. + */ +bool minipal_guid_v4_create(GUID* guid); + +/** + * Compare two GUIDs for equality + * + * @param g1 Pointer to the first GUID. + * @param g2 Pointer to the second GUID. + * @return true if the GUIDs are equal, false otherwise. + */ +bool minipal_guid_equals(GUID const* g1, GUID const* g2); + +/** + * Convert a GUID to its string representation + * + * @param guid The GUID to be converted. + * @param guidString Pointer to a buffer to store the GUID string. The buffer must be at least MINIPAL_GUID_BUFFER_LEN in size. + * @param len Length of the destination buffer. + */ +void minipal_guid_as_string(GUID guid, char* guidString, uint32_t len); #ifdef __cplusplus } -#endif // __cplusplus -#ifdef __cplusplus -inline bool operator==(minipal_guid_t const& a, minipal_guid_t const& b) +#ifndef _WIN32 +inline bool operator==(GUID const& a, GUID const& b) { return minipal_guid_equals(&a, &b); } -inline bool operator!=(minipal_guid_t const& a, minipal_guid_t const& b) +inline bool operator!=(GUID const& a, GUID const& b) { return !(a == b); } - -template -bool minipal_guid_v4_create(T* guid) -{ - static_assert(sizeof(T) == sizeof(minipal_guid_t), "minipal_guid_t size mismatch"); - return minipal_guid_v4_create(reinterpret_cast(guid)); -} -#endif +#endif // _WIN32 +#endif // __cplusplus #endif // MINIPAL_GUID_H diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 6c7d4cb9fd512d..48440806fbea55 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -7,6 +7,9 @@ include(${CLR_ENG_NATIVE_DIR}/configurecompiler.cmake) include_directories("${CLR_SRC_NATIVE_DIR}") +add_subdirectory(${CLR_SRC_NATIVE_DIR}/minipal minipal) +list(APPEND LINK_LIBRARIES_ADDITIONAL PRIVATE minipal) + # Add this subdir. We install the headers for the jit. add_subdirectory(${CLR_REPO_ROOT_DIR}/src/coreclr/pal/prebuilt/inc ${CLR_ARTIFACTS_OBJ_DIR}/coreclr/pal/prebuilt/inc) diff --git a/src/tests/Interop/common/xplatform.h b/src/tests/Interop/common/xplatform.h index 0b7f5130fe364f..73d816b9867620 100644 --- a/src/tests/Interop/common/xplatform.h +++ b/src/tests/Interop/common/xplatform.h @@ -5,6 +5,7 @@ #define __XPLAT_H__ #include +#include #ifndef WINDOWS @@ -43,34 +44,12 @@ typedef struct HSTRING__{ // Declare the HSTRING handle for C/C++ typedef HSTRING__* HSTRING; -#ifndef GUID_DEFINED -typedef struct _GUID { - uint32_t Data1; // NOTE: diff from Win32, for LP64 - uint16_t Data2; - uint16_t Data3; - uint8_t Data4[8]; -} GUID; typedef const GUID *LPCGUID; -#define GUID_DEFINED -#endif // !GUID_DEFINED - #define REFGUID const GUID & -extern "C++" { -#if !defined _SYS_GUID_OPERATOR_EQ_ && !defined _NO_SYS_GUID_OPERATOR_EQ_ -#define _SYS_GUID_OPERATOR_EQ_ -inline int IsEqualGUID(REFGUID rguid1, REFGUID rguid2) - { return !memcmp(&rguid1, &rguid2, sizeof(GUID)); } -inline int operator==(REFGUID guidOne, REFGUID guidOther) - { return IsEqualGUID(guidOne,guidOther); } -inline int operator!=(REFGUID guidOne, REFGUID guidOther) - { return !IsEqualGUID(guidOne,guidOther); } -#endif -}; - typedef GUID IID; #define REFIID const IID & -#define IsEqualIID(riid1, riid2) IsEqualGUID(riid1, riid2) +#define IsEqualIID(riid1, riid2) riid1 == riid2 #define __uuidof(type) IID_##type diff --git a/src/tests/profiler/native/CMakeLists.txt b/src/tests/profiler/native/CMakeLists.txt index 4333a8b2698280..6d0ed4771f2051 100644 --- a/src/tests/profiler/native/CMakeLists.txt +++ b/src/tests/profiler/native/CMakeLists.txt @@ -55,7 +55,7 @@ else(WIN32) set(DEPENDENCIES pthread ${CMAKE_DL_LIBS}) endif(WIN32) -target_link_libraries(Profiler PUBLIC ${DEPENDENCIES}) +target_link_libraries(Profiler PUBLIC ${DEPENDENCIES} ${LINK_LIBRARIES_ADDITIONAL}) # add the install targets install(TARGETS Profiler DESTINATION bin)