Skip to content
Prev Previous commit
Next Next commit
Fix pointer usage in daccess builds
  • Loading branch information
Koundinya Veluri committed Jan 23, 2020
commit 2ba422efceecbf7c0079e72b26048eb088b2bb64
40 changes: 23 additions & 17 deletions src/coreclr/src/vm/amd64/cgencpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,17 @@ inline BOOL ClrFlushInstructionCache(LPCVOID pCodeAddr, size_t sizeOfCode)
T(const T &) = delete; \
T &operator =(const T &) = delete

typedef UINT16 CallCount;
typedef DPTR(CallCount) PTR_CallCount;

////////////////////////////////////////////////////////////////
// CallCountingStub

class CallCountingStub;
typedef DPTR(const CallCountingStub) PTR_CallCountingStub;

class CallCountingStub
{
protected:
typedef UINT16 CallCount;

public:
static const SIZE_T Alignment = sizeof(void *);

Expand All @@ -567,7 +570,7 @@ class CallCountingStub
#endif // !DACCESS_COMPILE

public:
CallCount *GetRemainingCallCountCell() const;
PTR_CallCount GetRemainingCallCountCell() const;
PCODE GetTargetForMethod() const;

#ifndef DACCESS_COMPILE
Expand Down Expand Up @@ -602,7 +605,10 @@ class CallCountingStub
////////////////////////////////////////////////////////////////
// CallCountingStubShort

class CallCountingStubShort;
typedef DPTR(const CallCountingStubShort) PTR_CallCountingStubShort;
class CallCountingStubLong;
typedef DPTR(const CallCountingStubLong) PTR_CallCountingStubLong;

#pragma pack(push, 1)
class CallCountingStubShort : public CallCountingStub
Expand Down Expand Up @@ -663,18 +669,18 @@ class CallCountingStubShort : public CallCountingStub
#endif // !DACCESS_COMPILE

public:
static bool Is(const CallCountingStub *callCountingStub)
static bool Is(PTR_CallCountingStub callCountingStub)
{
WRAPPER_NO_CONTRACT;
return ((const CallCountingStubShort *)callCountingStub)->m_part1[4] == 0x85;
return dac_cast<PTR_CallCountingStubShort>(callCountingStub)->m_part1[4] == 0x85;
}

static const CallCountingStubShort *From(const CallCountingStub *callCountingStub)
static PTR_CallCountingStubShort From(PTR_CallCountingStub callCountingStub)
{
WRAPPER_NO_CONTRACT;
_ASSERTE(Is(callCountingStub));

return (const CallCountingStubShort *)callCountingStub;
return dac_cast<PTR_CallCountingStubShort>(callCountingStub);
}

PCODE GetTargetForMethod() const
Expand Down Expand Up @@ -782,21 +788,21 @@ class CallCountingStubLong : public CallCountingStub
#endif // !DACCESS_COMPILE

public:
static bool Is(const CallCountingStub *callCountingStub)
static bool Is(PTR_CallCountingStub callCountingStub)
{
WRAPPER_NO_CONTRACT;
static_assert_no_msg(offsetof(CallCountingStubShort, m_part1[4]) == offsetof(CallCountingStubLong, m_part1[4]));
static_assert_no_msg(sizeof(CallCountingStubShort::m_part1[4]) == sizeof(CallCountingStubLong::m_part1[4]));

return ((const CallCountingStubLong *)callCountingStub)->m_part1[4] == 0x0c;
return dac_cast<PTR_CallCountingStubLong>(callCountingStub)->m_part1[4] == 0x0c;
}

static const CallCountingStubLong *From(const CallCountingStub *callCountingStub)
static PTR_CallCountingStubLong From(PTR_CallCountingStub callCountingStub)
{
WRAPPER_NO_CONTRACT;
_ASSERTE(Is(callCountingStub));

return (const CallCountingStubLong *)callCountingStub;
return dac_cast<PTR_CallCountingStubLong>(callCountingStub);
}

PCODE GetTargetForMethod() const
Expand Down Expand Up @@ -826,24 +832,24 @@ inline const CallCountingStub *CallCountingStub::From(TADDR stubIdentifyingToken
}
#endif

inline CallCountingStub::CallCount *CallCountingStub::GetRemainingCallCountCell() const
inline PTR_CallCount CallCountingStub::GetRemainingCallCountCell() const
{
WRAPPER_NO_CONTRACT;
static_assert_no_msg(
offsetof(CallCountingStubShort, m_remainingCallCountCell) ==
offsetof(CallCountingStubLong, m_remainingCallCountCell));

return ((const CallCountingStubShort *)this)->m_remainingCallCountCell;
return PTR_CallCount(dac_cast<PTR_CallCountingStubShort>(this)->m_remainingCallCountCell);
}

inline PCODE CallCountingStub::GetTargetForMethod() const
{
WRAPPER_NO_CONTRACT;

return
CallCountingStubShort::Is(this)
? CallCountingStubShort::From(this)->GetTargetForMethod()
: CallCountingStubLong::From(this)->GetTargetForMethod();
CallCountingStubShort::Is(PTR_CallCountingStub(this))
? CallCountingStubShort::From(PTR_CallCountingStub(this))->GetTargetForMethod()
: CallCountingStubLong::From(PTR_CallCountingStub(this))->GetTargetForMethod();
}

////////////////////////////////////////////////////////////////
Expand Down
27 changes: 16 additions & 11 deletions src/coreclr/src/vm/arm/cgencpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -1350,14 +1350,17 @@ inline size_t GetARMInstructionLength(PBYTE pInstr)
T(const T &) = delete; \
T &operator =(const T &) = delete

typedef UINT16 CallCount;
typedef DPTR(CallCount) PTR_CallCount;

////////////////////////////////////////////////////////////////
// CallCountingStub

class CallCountingStub;
typedef DPTR(const CallCountingStub) PTR_CallCountingStub;

class CallCountingStub
{
protected:
typedef UINT16 CallCount;

public:
static const SIZE_T Alignment = sizeof(void *);

Expand All @@ -1378,7 +1381,7 @@ class CallCountingStub
#endif

public:
CallCount *GetRemainingCallCountCell() const;
PTR_CallCount GetRemainingCallCountCell() const;
PCODE GetTargetForMethod() const;

DISABLE_COPY(CallCountingStub);
Expand All @@ -1387,6 +1390,9 @@ class CallCountingStub
////////////////////////////////////////////////////////////////
// CallCountingStubShort

class CallCountingStubShort;
typedef DPTR(const CallCountingStubShort) PTR_CallCountingStubShort;

#pragma pack(push, 1)
class CallCountingStubShort : public CallCountingStub
{
Expand Down Expand Up @@ -1438,18 +1444,18 @@ class CallCountingStubShort : public CallCountingStub
#endif

public:
static bool Is(const CallCountingStub *callCountingStub)
static bool Is(PTR_CallCountingStub callCountingStub)
{
WRAPPER_NO_CONTRACT;
return true;
}

static const CallCountingStubShort *From(const CallCountingStub *callCountingStub)
static PTR_CallCountingStubShort From(PTR_CallCountingStub callCountingStub)
{
WRAPPER_NO_CONTRACT;
_ASSERTE(Is(callCountingStub));

return (const CallCountingStubShort *)callCountingStub;
return dac_cast<PTR_CallCountingStubShort>(callCountingStub);
}

PCODE GetTargetForMethod() const
Expand All @@ -1459,7 +1465,6 @@ class CallCountingStubShort : public CallCountingStub
}

friend CallCountingStub;
friend CallCountingStubLong;
DISABLE_COPY(CallCountingStubShort);
};
#pragma pack(pop)
Expand All @@ -1477,16 +1482,16 @@ inline const CallCountingStub *CallCountingStub::From(TADDR stubIdentifyingToken
}
#endif

inline CallCountingStub::CallCount *CallCountingStub::GetRemainingCallCountCell() const
inline PTR_CallCount CallCountingStub::GetRemainingCallCountCell() const
{
WRAPPER_NO_CONTRACT;
return ((const CallCountingStubShort *)this)->m_remainingCallCountCell;
return PTR_CallCount(dac_cast<PTR_CallCountingStubShort>(this)->m_remainingCallCountCell);
}

inline PCODE CallCountingStub::GetTargetForMethod() const
{
WRAPPER_NO_CONTRACT;
return CallCountingStubShort::From(this)->GetTargetForMethod();
return CallCountingStubShort::From(PTR_CallCountingStub(this))->GetTargetForMethod();
}

////////////////////////////////////////////////////////////////
Expand Down
27 changes: 16 additions & 11 deletions src/coreclr/src/vm/arm64/cgencpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -807,14 +807,17 @@ typedef DPTR(ThisPtrRetBufPrecode) PTR_ThisPtrRetBufPrecode;
T(const T &) = delete; \
T &operator =(const T &) = delete

typedef UINT16 CallCount;
typedef DPTR(CallCount) PTR_CallCount;

////////////////////////////////////////////////////////////////
// CallCountingStub

class CallCountingStub;
typedef DPTR(const CallCountingStub) PTR_CallCountingStub;

class CallCountingStub
{
protected:
typedef UINT16 CallCount;

public:
static const SIZE_T Alignment = sizeof(void *);

Expand All @@ -835,7 +838,7 @@ class CallCountingStub
#endif // !DACCESS_COMPILE

public:
CallCount *GetRemainingCallCountCell() const;
PTR_CallCount GetRemainingCallCountCell() const;

PCODE GetTargetForMethod() const
{
Expand All @@ -849,6 +852,9 @@ class CallCountingStub
////////////////////////////////////////////////////////////////
// CallCountingStubShort

class CallCountingStubShort;
typedef DPTR(const CallCountingStubShort) PTR_CallCountingStubShort;

#pragma pack(push, 1)
class CallCountingStubShort : public CallCountingStub
{
Expand Down Expand Up @@ -900,24 +906,23 @@ class CallCountingStubShort : public CallCountingStub
#endif // !DACCESS_COMPILE

public:
static bool Is(const CallCountingStub *callCountingStub)
static bool Is(PTR_CallCountingStub callCountingStub)
{
WRAPPER_NO_CONTRACT;
return true;
}

static const CallCountingStubShort *From(const CallCountingStub *callCountingStub)
static PTR_CallCountingStubShort From(PTR_CallCountingStub callCountingStub)
{
WRAPPER_NO_CONTRACT;
_ASSERTE(Is(callCountingStub));

return (const CallCountingStubShort *)callCountingStub;
return dac_cast<PTR_CallCountingStubShort>(callCountingStub);
}

PCODE GetTargetForMethod() const;

friend CallCountingStub;
friend CallCountingStubLong;
DISABLE_COPY(CallCountingStubShort);
};
#pragma pack(pop)
Expand All @@ -935,16 +940,16 @@ inline const CallCountingStub *CallCountingStub::From(TADDR stubIdentifyingToken
}
#endif

inline CallCountingStub::CallCount *CallCountingStub::GetRemainingCallCountCell() const
inline PTR_CallCount CallCountingStub::GetRemainingCallCountCell() const
{
WRAPPER_NO_CONTRACT;
return ((const CallCountingStubShort *)this)->m_remainingCallCountCell;
return PTR_CallCount(dac_cast<PTR_CallCountingStubShort>(this)->m_remainingCallCountCell);
}

inline PCODE CallCountingStub::GetTargetForMethod() const
{
WRAPPER_NO_CONTRACT;
return CallCountingStubShort::From(this)->GetTargetForMethod();
return CallCountingStubShort::From(PTR_CallCountingStub(this))->GetTargetForMethod();
}

////////////////////////////////////////////////////////////////
Expand Down
8 changes: 4 additions & 4 deletions src/coreclr/src/vm/callcounting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ CallCountingManager::CallCountingInfo::~CallCountingInfo()

#endif // !DACCESS_COMPILE

CallCountingManager::CallCountingInfo *CallCountingManager::CallCountingInfo::From(CallCount *remainingCallCountCell)
CallCountingManager::PTR_CallCountingInfo CallCountingManager::CallCountingInfo::From(PTR_CallCount remainingCallCountCell)
{
WRAPPER_NO_CONTRACT;
_ASSERTE(remainingCallCountCell != nullptr);

return (CallCountingInfo *)((UINT_PTR)remainingCallCountCell - offsetof(CallCountingInfo, m_remainingCallCount));
return PTR_CallCountingInfo(dac_cast<TADDR>(remainingCallCountCell) - offsetof(CallCountingInfo, m_remainingCallCount));
}

NativeCodeVersion CallCountingManager::CallCountingInfo::GetCodeVersion() const
Expand Down Expand Up @@ -131,7 +131,7 @@ void CallCountingManager::CallCountingInfo::ClearCallCountingStub()
m_callCountingStub = nullptr;
}

CallCountingManager::CallCount *CallCountingManager::CallCountingInfo::GetRemainingCallCountCell()
PTR_CallCount CallCountingManager::CallCountingInfo::GetRemainingCallCountCell()
{
WRAPPER_NO_CONTRACT;
_ASSERTE(IsCallCountingEnabled());
Expand Down Expand Up @@ -1229,7 +1229,7 @@ PCODE CallCountingManager::GetTargetForMethod(PCODE callCountingStubEntryPoint)

_ASSERTE(IsCallCountingStub(callCountingStubEntryPoint));

return ((const CallCountingStub *)PCODEToPINSTR(callCountingStubEntryPoint))->GetTargetForMethod();
return PTR_CallCountingStub(PCODEToPINSTR(callCountingStubEntryPoint))->GetTargetForMethod();
}

#ifdef DACCESS_COMPILE
Expand Down
5 changes: 1 addition & 4 deletions src/coreclr/src/vm/callcounting.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ typedef DPTR(CallCountingManager) PTR_CallCountingManager;

class CallCountingManager
{
public:
typedef UINT16 CallCount;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CallCountingManager::CallCountingInfo

Expand Down Expand Up @@ -121,7 +118,7 @@ class CallCountingManager
#endif

public:
static CallCountingInfo *From(CallCount *remainingCallCountCell);
static PTR_CallCountingInfo From(PTR_CallCount remainingCallCountCell);
NativeCodeVersion GetCodeVersion() const;
bool IsCallCountingEnabled() const;

Expand Down
Loading