From 7413020abdf1575950c0208f6f3b3002d21f9ab3 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Thu, 29 Feb 2024 21:11:31 +0100 Subject: [PATCH] Fix conflicting TADDR definition (#98925) * Fix conflicting TADDR definitions * Fix build breaks * Fix CrossDAC build * Fix FormatInteger on osx-x64 --------- Co-authored-by: Jan Kotas --- src/coreclr/debug/daccess/dacdbiimpl.cpp | 4 +- src/coreclr/debug/daccess/request.cpp | 6 ++- src/coreclr/debug/ee/controller.h | 2 +- src/coreclr/debug/inc/arm64/primitives.h | 6 +-- .../debug/inc/loongarch64/primitives.h | 4 +- src/coreclr/debug/inc/riscv64/primitives.h | 4 +- src/coreclr/inc/check.h | 12 ++++++ src/coreclr/inc/check.inl | 40 +++++++++++++++++++ src/coreclr/inc/clr_std/type_traits | 4 +- src/coreclr/inc/clrtypes.h | 9 +++++ src/coreclr/inc/daccess.h | 5 +-- src/coreclr/inc/regdisp.h | 2 +- src/coreclr/vm/amd64/cgenamd64.cpp | 2 +- src/coreclr/vm/amd64/gmsamd64.cpp | 2 +- src/coreclr/vm/arm/stubs.cpp | 2 +- src/coreclr/vm/arm64/stubs.cpp | 2 +- src/coreclr/vm/ceeload.inl | 2 +- 17 files changed, 86 insertions(+), 22 deletions(-) diff --git a/src/coreclr/debug/daccess/dacdbiimpl.cpp b/src/coreclr/debug/daccess/dacdbiimpl.cpp index bc1e6ad8475459..b316a0769d3f67 100644 --- a/src/coreclr/debug/daccess/dacdbiimpl.cpp +++ b/src/coreclr/debug/daccess/dacdbiimpl.cpp @@ -7455,13 +7455,13 @@ HRESULT DacDbiInterfaceImpl::GetILCodeVersionNodeData(VMPTR_ILCodeVersionNode vm #ifdef FEATURE_REJIT ILCodeVersion ilCode(vmILCodeVersionNode.GetDacPtr()); pData->m_state = ilCode.GetRejitState(); - pData->m_pbIL = PTR_TO_CORDB_ADDRESS(dac_cast(ilCode.GetIL())); + pData->m_pbIL = PTR_TO_CORDB_ADDRESS(dac_cast(ilCode.GetIL())); pData->m_dwCodegenFlags = ilCode.GetJitFlags(); const InstrumentedILOffsetMapping* pMapping = ilCode.GetInstrumentedILMap(); if (pMapping) { pData->m_cInstrumentedMapEntries = (ULONG)pMapping->GetCount(); - pData->m_rgInstrumentedMapEntries = PTR_TO_CORDB_ADDRESS(dac_cast(pMapping->GetOffsets())); + pData->m_rgInstrumentedMapEntries = PTR_TO_CORDB_ADDRESS(dac_cast(pMapping->GetOffsets())); } else { diff --git a/src/coreclr/debug/daccess/request.cpp b/src/coreclr/debug/daccess/request.cpp index 1e0912ea05cdde..cc438d1c903ca1 100644 --- a/src/coreclr/debug/daccess/request.cpp +++ b/src/coreclr/debug/daccess/request.cpp @@ -3810,9 +3810,13 @@ ClrDataAccess::GetJumpThunkTarget(T_CONTEXT *ctx, CLRDATA_ADDRESS *targetIP, CLR #ifdef TARGET_AMD64 SOSDacEnter(); - if (!GetAnyThunkTarget(ctx, targetIP, targetMD)) + TADDR tempTargetIP, tempTargetMD; + if (!GetAnyThunkTarget(ctx, &tempTargetIP, &tempTargetMD)) hr = E_FAIL; + *targetIP = TO_CDADDR(tempTargetIP); + *targetMD = TO_CDADDR(tempTargetMD); + SOSDacLeave(); return hr; #else diff --git a/src/coreclr/debug/ee/controller.h b/src/coreclr/debug/ee/controller.h index a2d8dc2e2602f3..b838e11c0f85a3 100644 --- a/src/coreclr/debug/ee/controller.h +++ b/src/coreclr/debug/ee/controller.h @@ -827,7 +827,7 @@ class DebuggerPatchTable : private CHashTableAndData DebuggerControllerPatch * GetPatch(PTR_CORDB_ADDRESS_TYPE address) { SUPPORTS_DAC; - ARM_ONLY(_ASSERTE(dac_cast(address) & THUMB_CODE)); + ARM_ONLY(_ASSERTE(dac_cast(address) & THUMB_CODE)); DebuggerControllerPatch * pPatch = dac_cast(Find(HashAddress(address), (SIZE_T)(dac_cast(address)))); diff --git a/src/coreclr/debug/inc/arm64/primitives.h b/src/coreclr/debug/inc/arm64/primitives.h index 05c03c7b3094f8..5f8b5262d993e4 100644 --- a/src/coreclr/debug/inc/arm64/primitives.h +++ b/src/coreclr/debug/inc/arm64/primitives.h @@ -153,9 +153,9 @@ inline void CORDbgSetInstruction(CORDB_ADDRESS_TYPE* address, #if !defined(DBI_COMPILE) && !defined(DACCESS_COMPILE) && defined(HOST_OSX) ExecutableWriterHolder instructionWriterHolder((LPVOID)address, sizeof(PRD_TYPE)); - ULONGLONG ptraddr = dac_cast(instructionWriterHolder.GetRW()); + TADDR ptraddr = dac_cast(instructionWriterHolder.GetRW()); #else // !DBI_COMPILE && !DACCESS_COMPILE && HOST_OSX - ULONGLONG ptraddr = dac_cast(address); + TADDR ptraddr = dac_cast(address); #endif // !DBI_COMPILE && !DACCESS_COMPILE && HOST_OSX *(PRD_TYPE *)ptraddr = instruction; FlushInstructionCache(GetCurrentProcess(), @@ -167,7 +167,7 @@ inline PRD_TYPE CORDbgGetInstruction(UNALIGNED CORDB_ADDRESS_TYPE* address) { LIMITED_METHOD_CONTRACT; - ULONGLONG ptraddr = dac_cast(address); + TADDR ptraddr = dac_cast(address); return *(PRD_TYPE *)ptraddr; } diff --git a/src/coreclr/debug/inc/loongarch64/primitives.h b/src/coreclr/debug/inc/loongarch64/primitives.h index 97e4fb9541a2ab..b30e7dcdd2ea91 100644 --- a/src/coreclr/debug/inc/loongarch64/primitives.h +++ b/src/coreclr/debug/inc/loongarch64/primitives.h @@ -135,7 +135,7 @@ inline void CORDbgSetInstruction(CORDB_ADDRESS_TYPE* address, // In a DAC build, this function assumes the input is an host address. LIMITED_METHOD_DAC_CONTRACT; - ULONGLONG ptraddr = dac_cast(address); + TADDR ptraddr = dac_cast(address); *(PRD_TYPE *)ptraddr = instruction; FlushInstructionCache(GetCurrentProcess(), address, @@ -146,7 +146,7 @@ inline PRD_TYPE CORDbgGetInstruction(UNALIGNED CORDB_ADDRESS_TYPE* address) { LIMITED_METHOD_CONTRACT; - ULONGLONG ptraddr = dac_cast(address); + TADDR ptraddr = dac_cast(address); return *(PRD_TYPE *)ptraddr; } diff --git a/src/coreclr/debug/inc/riscv64/primitives.h b/src/coreclr/debug/inc/riscv64/primitives.h index 066397fcda7146..17ace22981c77d 100644 --- a/src/coreclr/debug/inc/riscv64/primitives.h +++ b/src/coreclr/debug/inc/riscv64/primitives.h @@ -137,7 +137,7 @@ inline void CORDbgSetInstruction(CORDB_ADDRESS_TYPE* address, // In a DAC build, this function assumes the input is an host address. LIMITED_METHOD_DAC_CONTRACT; - ULONGLONG ptraddr = dac_cast(address); + TADDR ptraddr = dac_cast(address); *(PRD_TYPE *)ptraddr = instruction; FlushInstructionCache(GetCurrentProcess(), address, @@ -148,7 +148,7 @@ inline PRD_TYPE CORDbgGetInstruction(UNALIGNED CORDB_ADDRESS_TYPE* address) { LIMITED_METHOD_CONTRACT; - ULONGLONG ptraddr = dac_cast(address); + TADDR ptraddr = dac_cast(address); return *(PRD_TYPE *)ptraddr; } diff --git a/src/coreclr/inc/check.h b/src/coreclr/inc/check.h index c1ac08016d836f..6951e2a41837b6 100644 --- a/src/coreclr/inc/check.h +++ b/src/coreclr/inc/check.h @@ -684,6 +684,9 @@ CHECK CheckAligned(UINT value, UINT alignment); CHECK CheckAligned(ULONG value, UINT alignment); #endif CHECK CheckAligned(UINT64 value, UINT alignment); +#ifdef __APPLE__ +CHECK CheckAligned(SIZE_T value, UINT alignment); +#endif CHECK CheckAligned(const void *address, UINT alignment); CHECK CheckOverflow(UINT value1, UINT value2); @@ -691,6 +694,9 @@ CHECK CheckOverflow(UINT value1, UINT value2); CHECK CheckOverflow(ULONG value1, ULONG value2); #endif CHECK CheckOverflow(UINT64 value1, UINT64 value2); +#ifdef __APPLE__ +CHECK CheckOverflow(SIZE_T value1, SIZE_T value2); +#endif CHECK CheckOverflow(PTR_CVOID address, UINT offset); #if defined(_MSC_VER) CHECK CheckOverflow(const void *address, ULONG offset); @@ -702,11 +708,17 @@ CHECK CheckUnderflow(UINT value1, UINT value2); CHECK CheckUnderflow(ULONG value1, ULONG value2); #endif CHECK CheckUnderflow(UINT64 value1, UINT64 value2); +#ifdef __APPLE__ +CHECK CheckUnderflow(SIZE_T value1, SIZE_T value2); +#endif CHECK CheckUnderflow(const void *address, UINT offset); #if defined(_MSC_VER) CHECK CheckUnderflow(const void *address, ULONG offset); #endif CHECK CheckUnderflow(const void *address, UINT64 offset); +#ifdef __APPLE__ +CHECK CheckUnderflow(const void *address, SIZE_T offset); +#endif CHECK CheckUnderflow(const void *address, void *address2); CHECK CheckZeroedMemory(const void *memory, SIZE_T size); diff --git a/src/coreclr/inc/check.inl b/src/coreclr/inc/check.inl index 9296c48f7a7a3d..34a2956d1be6e2 100644 --- a/src/coreclr/inc/check.inl +++ b/src/coreclr/inc/check.inl @@ -156,6 +156,15 @@ inline CHECK CheckAligned(UINT64 value, UINT alignment) CHECK_OK; } +#ifdef __APPLE__ +inline CHECK CheckAligned(SIZE_T value, UINT alignment) +{ + STATIC_CONTRACT_WRAPPER; + CHECK(AlignmentTrim(value, alignment) == 0); + CHECK_OK; +} +#endif + inline CHECK CheckAligned(const void *address, UINT alignment) { STATIC_CONTRACT_WRAPPER; @@ -183,6 +192,14 @@ inline CHECK CheckOverflow(UINT64 value1, UINT64 value2) CHECK_OK; } +#ifdef __APPLE__ +inline CHECK CheckOverflow(SIZE_T value1, SIZE_T value2) +{ + CHECK(value1 + value2 >= value1); + CHECK_OK; +} +#endif + inline CHECK CheckOverflow(PTR_CVOID address, UINT offset) { TADDR targetAddr = dac_cast(address); @@ -254,6 +271,15 @@ inline CHECK CheckUnderflow(UINT64 value1, UINT64 value2) CHECK_OK; } +#ifdef __APPLE__ +inline CHECK CheckUnderflow(SIZE_T value1, SIZE_T value2) +{ + CHECK(value1 - value2 <= value1); + + CHECK_OK; +} +#endif + inline CHECK CheckUnderflow(const void *address, UINT offset) { #if POINTER_BITS == 32 @@ -290,6 +316,20 @@ inline CHECK CheckUnderflow(const void *address, UINT64 offset) CHECK_OK; } +#ifdef __APPLE__ +inline CHECK CheckUnderflow(const void *address, SIZE_T offset) +{ +#if POINTER_BITS == 32 + CHECK(offset >> 32 == 0); + CHECK((UINT) (SIZE_T) address - (UINT) offset <= (UINT) (SIZE_T) address); +#else + CHECK((UINT64) address - offset <= (UINT64) address); +#endif + + CHECK_OK; +} +#endif + inline CHECK CheckUnderflow(const void *address, void *address2) { #if POINTER_BITS == 32 diff --git a/src/coreclr/inc/clr_std/type_traits b/src/coreclr/inc/clr_std/type_traits index 12af99d5c4fee1..ba007c32d9fef2 100644 --- a/src/coreclr/inc/clr_std/type_traits +++ b/src/coreclr/inc/clr_std/type_traits @@ -358,7 +358,7 @@ namespace std // On Unix 'long' is a 64-bit type (same as __int64) and the following two definitions // conflict with _Is_integral and _Is_integral. -#ifndef HOST_UNIX +#if !defined(HOST_UNIX) || defined(__APPLE__) template<> struct _Is_integral : true_type @@ -370,7 +370,7 @@ namespace std : true_type { // determine whether _Ty is integral }; -#endif /* HOST_UNIX */ +#endif /* !HOST_UNIX || __APPLE__ */ #if _HAS_CHAR16_T_LANGUAGE_SUPPORT template<> diff --git a/src/coreclr/inc/clrtypes.h b/src/coreclr/inc/clrtypes.h index 19e9720b34d90b..9094e4932a2527 100644 --- a/src/coreclr/inc/clrtypes.h +++ b/src/coreclr/inc/clrtypes.h @@ -370,6 +370,15 @@ inline UINT64 AlignDown(UINT64 value, UINT alignment) return (value&~(UINT64)(alignment-1)); } +#ifdef __APPLE__ +inline SIZE_T AlignDown(SIZE_T value, UINT alignment) +{ + STATIC_CONTRACT_LEAF; + STATIC_CONTRACT_SUPPORTS_DAC; + return (value&~(SIZE_T)(alignment-1)); +} +#endif // __APPLE__ + inline UINT AlignmentPad(UINT value, UINT alignment) { STATIC_CONTRACT_WRAPPER; diff --git a/src/coreclr/inc/daccess.h b/src/coreclr/inc/daccess.h index 699947a02cdd42..7783fde153f942 100644 --- a/src/coreclr/inc/daccess.h +++ b/src/coreclr/inc/daccess.h @@ -614,8 +614,7 @@ struct DacTableHeader // Define TADDR as a non-pointer value so use of it as a pointer // will not work properly. Define it as unsigned so // pointer comparisons aren't affected by sign. -// This requires special casting to ULONG64 to sign-extend if necessary. -typedef ULONG_PTR TADDR; +typedef uintptr_t TADDR; // TSIZE_T used for counts or ranges that need to span the size of a // target pointer. For cross-plat, this may be different than SIZE_T @@ -2128,7 +2127,7 @@ inline void DACCOP_IGNORE(DacCopWarningCode code, const char * szReasonString) // Declare TADDR as a non-pointer type so that arithmetic // can be done on it directly, as with the DACCESS_COMPILE definition. // This also helps expose pointer usage that may need to be changed. -typedef ULONG_PTR TADDR; +typedef uintptr_t TADDR; typedef void* PTR_VOID; typedef LPVOID* PTR_PTR_VOID; diff --git a/src/coreclr/inc/regdisp.h b/src/coreclr/inc/regdisp.h index 4832791ebfa5dc..91a4305f9c668c 100644 --- a/src/coreclr/inc/regdisp.h +++ b/src/coreclr/inc/regdisp.h @@ -318,7 +318,7 @@ struct REGDISPLAY : public REGDISPLAY_BASE { memset(this, 0, sizeof(REGDISPLAY)); // Setup the pointer to ControlPC field - pPC = &ControlPC; + pPC = (DWORD *)&ControlPC; } }; diff --git a/src/coreclr/vm/amd64/cgenamd64.cpp b/src/coreclr/vm/amd64/cgenamd64.cpp index 261ecec5c46d8a..f774d71a3b427f 100644 --- a/src/coreclr/vm/amd64/cgenamd64.cpp +++ b/src/coreclr/vm/amd64/cgenamd64.cpp @@ -206,7 +206,7 @@ void HelperMethodFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloat #endif // TARGET_UNIX -#define CALLEE_SAVED_REGISTER(regname) pRD->pCurrentContextPointers->regname = m_MachState.m_Ptrs.p##regname; +#define CALLEE_SAVED_REGISTER(regname) pRD->pCurrentContextPointers->regname = (DWORD64 *)(TADDR *)m_MachState.m_Ptrs.p##regname; ENUM_CALLEE_SAVED_REGISTERS(); #undef CALLEE_SAVED_REGISTER diff --git a/src/coreclr/vm/amd64/gmsamd64.cpp b/src/coreclr/vm/amd64/gmsamd64.cpp index bc1079c14ace10..41c7b0c9afa211 100644 --- a/src/coreclr/vm/amd64/gmsamd64.cpp +++ b/src/coreclr/vm/amd64/gmsamd64.cpp @@ -136,7 +136,7 @@ void LazyMachState::unwindLazyState(LazyMachState* baseState, #else // !DACCESS_COMPILE -#define CALLEE_SAVED_REGISTER(regname) unwoundState->m_Ptrs.p##regname = PTR_ULONG64(nonVolRegPtrs.regname); +#define CALLEE_SAVED_REGISTER(regname) unwoundState->m_Ptrs.p##regname = PTR_TADDR(nonVolRegPtrs.regname); ENUM_CALLEE_SAVED_REGISTERS(); #undef CALLEE_SAVED_REGISTER diff --git a/src/coreclr/vm/arm/stubs.cpp b/src/coreclr/vm/arm/stubs.cpp index d72c32201700e2..1424dcecbd918d 100644 --- a/src/coreclr/vm/arm/stubs.cpp +++ b/src/coreclr/vm/arm/stubs.cpp @@ -1619,7 +1619,7 @@ void InlinedCallFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats // Update the frame pointer in the current context. pRD->pCurrentContext->R11 = m_pCalleeSavedFP; - pRD->pCurrentContextPointers->R11 = &m_pCalleeSavedFP; + pRD->pCurrentContextPointers->R11 = (DWORD *)&m_pCalleeSavedFP; // This is necessary to unwind methods with alloca. This needs to stay // in sync with definition of REG_SAVED_LOCALLOC_SP in the JIT. diff --git a/src/coreclr/vm/arm64/stubs.cpp b/src/coreclr/vm/arm64/stubs.cpp index 9f0c9ae14e7156..03783f016a52d3 100644 --- a/src/coreclr/vm/arm64/stubs.cpp +++ b/src/coreclr/vm/arm64/stubs.cpp @@ -731,7 +731,7 @@ void InlinedCallFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats // Update the frame pointer in the current context. - pRD->pCurrentContextPointers->Fp = &m_pCalleeSavedFP; + pRD->pCurrentContextPointers->Fp = (DWORD64 *)&m_pCalleeSavedFP; LOG((LF_GCROOTS, LL_INFO100000, "STACKWALK InlinedCallFrame::UpdateRegDisplay(pc:%p, sp:%p)\n", pRD->ControlPC, pRD->SP)); diff --git a/src/coreclr/vm/ceeload.inl b/src/coreclr/vm/ceeload.inl index ff446d4ec79912..18d7557d6e85bd 100644 --- a/src/coreclr/vm/ceeload.inl +++ b/src/coreclr/vm/ceeload.inl @@ -64,7 +64,7 @@ inline void LookupMap::SetValueAt(PTR_TADDR pValue, SIZE_T value, TADDR flags) { WRAPPER_NO_CONTRACT; - VolatileStore(pValue, value | flags); + VolatileStore(pValue, dac_cast(value | flags)); } #endif // DACCESS_COMPILE