Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 9 additions & 59 deletions src/coreclr/vm/amd64/cgenamd64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,47 +279,9 @@ void HijackFrame::UpdateRegDisplay_Impl(const PREGDISPLAY pRD, bool updateFloats
}
#endif // FEATURE_HIJACK

BOOL isJumpRel32(PCODE pCode)
bool isBackToBackJump(PCODE pCode)
{
CONTRACTL {
NOTHROW;
GC_NOTRIGGER;
SUPPORTS_DAC;
} CONTRACTL_END;

PTR_BYTE pbCode = PTR_BYTE(pCode);

return 0xE9 == pbCode[0];
}

//
// Given the same pBuffer that was used by emitJump this
// method decodes the instructions and returns the jump target
//
PCODE decodeJump32(PCODE pBuffer)
{
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
SUPPORTS_DAC;
}
CONTRACTL_END;

// jmp rel32
_ASSERTE(isJumpRel32(pBuffer));

return rel32Decode(pBuffer+1);
}

BOOL isJumpRel64(PCODE pCode)
{
CONTRACTL {
NOTHROW;
GC_NOTRIGGER;
SUPPORTS_DAC;
} CONTRACTL_END;

LIMITED_METHOD_CONTRACT;
PTR_BYTE pbCode = PTR_BYTE(pCode);

return 0x48 == pbCode[0] &&
Expand All @@ -328,19 +290,13 @@ BOOL isJumpRel64(PCODE pCode)
0xE0 == pbCode[11];
}

PCODE decodeJump64(PCODE pBuffer)
PCODE decodeBackToBackJump(PCODE pBuffer)
{
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
SUPPORTS_DAC;
}
CONTRACTL_END;
LIMITED_METHOD_CONTRACT;

// mov rax, xxx
// jmp rax
_ASSERTE(isJumpRel64(pBuffer));
_ASSERTE(isBackToBackJump(pBuffer));

return *PTR_UINT64(pBuffer+2);
}
Expand All @@ -353,11 +309,11 @@ BOOL GetAnyThunkTarget (CONTEXT *pctx, TADDR *pTarget, TADDR *pTargetMethodDesc)
*pTargetMethodDesc = (TADDR)NULL;

//
// Check for something generated by emitJump.
// Check for something generated by emitBackToBackJump.
//
if (isJumpRel64(pThunk))
if (isBackToBackJump(pThunk))
{
*pTarget = decodeJump64(pThunk);
*pTarget = decodeBackToBackJump(pThunk);
return TRUE;
}

Expand All @@ -368,12 +324,6 @@ BOOL GetAnyThunkTarget (CONTEXT *pctx, TADDR *pTarget, TADDR *pTargetMethodDesc)

#ifndef DACCESS_COMPILE

// Note: This is only used on server GC on Windows.
//
// This function returns the number of logical processors on a given physical chip. If it cannot
// determine the number of logical cpus, or the machine is not populated uniformly with the same
// type of processors, this function returns 1.

void EncodeLoadAndJumpThunk (LPBYTE pBuffer, LPVOID pv, LPVOID pTarget)
{
CONTRACTL
Expand Down Expand Up @@ -444,7 +394,7 @@ void emitCOMStubCall (ComCallMethodDesc *pCOMMethodRX, ComCallMethodDesc *pCOMMe
RETURN;
}

void emitJump(LPBYTE pBufferRX, LPBYTE pBufferRW, LPVOID target)
void emitBackToBackJump(LPBYTE pBufferRX, LPBYTE pBufferRW, LPVOID target)
{
CONTRACTL
{
Expand Down
35 changes: 3 additions & 32 deletions src/coreclr/vm/amd64/cgencpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,39 +508,10 @@ INT32 rel32UsingPreallocatedJumpStub(INT32 UNALIGNED * pRel32, PCODE target, PCO

void emitCOMStubCall (ComCallMethodDesc *pCOMMethodRX, ComCallMethodDesc *pCOMMethodRW, PCODE target);

void emitJump(LPBYTE pBufferRX, LPBYTE pBufferRW, LPVOID target);
void emitBackToBackJump(LPBYTE pBufferRX, LPBYTE pBufferRW, LPVOID target);

BOOL isJumpRel32(PCODE pCode);
PCODE decodeJump32(PCODE pCode);

BOOL isJumpRel64(PCODE pCode);
PCODE decodeJump64(PCODE pCode);

//
// On IA64 back to back jumps should be separated by a nop bundle to get
// the best performance from the hardware's branch prediction logic.
// For all other platforms back to back jumps don't require anything special
// That is why we have these two wrapper functions that call emitJump and decodeJump
//
inline void emitBackToBackJump(LPBYTE pBufferRX, LPBYTE pBufferRW, LPVOID target)
{
WRAPPER_NO_CONTRACT;

emitJump(pBufferRX, pBufferRW, target);
}

inline PCODE decodeBackToBackJump(PCODE pCode)
{
WRAPPER_NO_CONTRACT;
SUPPORTS_DAC;
if (isJumpRel32(pCode))
return decodeJump32(pCode);
else
if (isJumpRel64(pCode))
return decodeJump64(pCode);
else
return (PCODE)0;
}
bool isBackToBackJump(PCODE pCode);
PCODE decodeBackToBackJump(PCODE pCode);

extern "C" void setFPReturn(int fpSize, INT64 retVal);
extern "C" void getFPReturn(int fpSize, INT64 *retval);
Expand Down
27 changes: 3 additions & 24 deletions src/coreclr/vm/arm/cgencpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ inline int16_t decodeUnconditionalBranchThumb(LPBYTE pBuffer)
}

//------------------------------------------------------------------------
inline void emitJump(LPBYTE pBufferRX, LPBYTE pBufferRW, LPVOID target)
inline void emitBackToBackJump(LPBYTE pBufferRX, LPBYTE pBufferRW, LPVOID target)
{
LIMITED_METHOD_CONTRACT;

Expand All @@ -347,9 +347,9 @@ inline void emitJump(LPBYTE pBufferRX, LPBYTE pBufferRW, LPVOID target)
}

//------------------------------------------------------------------------
// Given the same pBuffer that was used by emitJump this method
// Given the same pBuffer that was used by emitBackToBackJump this method
// decodes the instructions and returns the jump target
inline PCODE decodeJump(PCODE pCode)
inline PCODE decodeBackToBackJump(PCODE pCode)
{
LIMITED_METHOD_CONTRACT;

Expand All @@ -358,27 +358,6 @@ inline PCODE decodeJump(PCODE pCode)
return *dac_cast<PTR_PCODE>(pInstr + sizeof(DWORD));
}

//
// On IA64 back to back jumps should be separated by a nop bundle to get
// the best performance from the hardware's branch prediction logic.
// For all other platforms back to back jumps don't require anything special
// That is why we have these two wrapper functions that call emitJump and decodeJump
//

//------------------------------------------------------------------------
inline void emitBackToBackJump(LPBYTE pBufferRX, LPBYTE pBufferRW, LPVOID target)
{
WRAPPER_NO_CONTRACT;
emitJump(pBufferRX, pBufferRW, target);
}

//------------------------------------------------------------------------
inline PCODE decodeBackToBackJump(PCODE pBuffer)
{
WRAPPER_NO_CONTRACT;
return decodeJump(pBuffer);
}

//----------------------------------------------------------------------
#include "stublink.h"

Expand Down
20 changes: 3 additions & 17 deletions src/coreclr/vm/arm64/cgencpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ inline BOOL ClrFlushInstructionCache(LPCVOID pCodeAddr, size_t sizeOfCode, bool
}

//------------------------------------------------------------------------
inline void emitJump(LPBYTE pBufferRX, LPBYTE pBufferRW, LPVOID target)
inline void emitBackToBackJump(LPBYTE pBufferRX, LPBYTE pBufferRW, LPVOID target)
{
LIMITED_METHOD_CONTRACT;
UINT32* pCode = (UINT32*)pBufferRW;
Expand All @@ -376,9 +376,9 @@ inline void emitJump(LPBYTE pBufferRX, LPBYTE pBufferRW, LPVOID target)
}

//------------------------------------------------------------------------
// Given the same pBuffer that was used by emitJump this method
// Given the same pBuffer that was used by emitBackToBackJump this method
// decodes the instructions and returns the jump target
inline PCODE decodeJump(PCODE pCode)
inline PCODE decodeBackToBackJump(PCODE pCode)
{
LIMITED_METHOD_CONTRACT;

Expand All @@ -387,20 +387,6 @@ inline PCODE decodeJump(PCODE pCode)
return *dac_cast<PTR_PCODE>(pInstr + 2*sizeof(DWORD));
}

//------------------------------------------------------------------------
inline void emitBackToBackJump(LPBYTE pBufferRX, LPBYTE pBufferRW, LPVOID target)
{
WRAPPER_NO_CONTRACT;
emitJump(pBufferRX, pBufferRW, target);
}

//------------------------------------------------------------------------
inline PCODE decodeBackToBackJump(PCODE pBuffer)
{
WRAPPER_NO_CONTRACT;
return decodeJump(pBuffer);
}

//----------------------------------------------------------------------

struct IntReg
Expand Down
8 changes: 0 additions & 8 deletions src/coreclr/vm/arm64/stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,14 +585,6 @@ LONG CLRNoCatchHandler(EXCEPTION_POINTERS* pExceptionInfo, PVOID pv)
return EXCEPTION_CONTINUE_SEARCH;
}

#ifdef DACCESS_COMPILE
BOOL GetAnyThunkTarget (T_CONTEXT *pctx, TADDR *pTarget, TADDR *pTargetMethodDesc)
{
_ASSERTE(!"ARM64:NYI");
return FALSE;
}
#endif // DACCESS_COMPILE

#ifndef DACCESS_COMPILE
// ----------------------------------------------------------------
// StubLinkerCPU methods
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/codeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2428,7 +2428,7 @@ HeapList* LoaderCodeHeap::CreateCodeHeap(CodeHeapRequestInfo *pInfo, LoaderHeap
if (pHp->CLRPersonalityRoutine != NULL)
{
ExecutableWriterHolder<BYTE> personalityRoutineWriterHolder(pHp->CLRPersonalityRoutine, 12);
emitJump(pHp->CLRPersonalityRoutine, personalityRoutineWriterHolder.GetRW(), (void *)ProcessCLRException);
emitBackToBackJump(pHp->CLRPersonalityRoutine, personalityRoutineWriterHolder.GetRW(), (void *)ProcessCLRException);
}
#endif // TARGET_64BIT

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/dynamicmethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ HeapList* HostCodeHeap::InitializeHeapList(CodeHeapRequestInfo *pInfo)
if (pHp->CLRPersonalityRoutine != NULL)
{
ExecutableWriterHolder<BYTE> personalityRoutineWriterHolder(pHp->CLRPersonalityRoutine, 12);
emitJump(pHp->CLRPersonalityRoutine, personalityRoutineWriterHolder.GetRW(), (void *)ProcessCLRException);
emitBackToBackJump(pHp->CLRPersonalityRoutine, personalityRoutineWriterHolder.GetRW(), (void *)ProcessCLRException);
}
#endif

Expand Down
27 changes: 3 additions & 24 deletions src/coreclr/vm/i386/cgencpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ inline BOOL isCallRegisterIndirect(const BYTE *pRetAddr)
}

//------------------------------------------------------------------------
inline void emitJump(LPBYTE pBufferRX, LPBYTE pBufferRW, LPVOID target)
inline void emitBackToBackJump(LPBYTE pBufferRX, LPBYTE pBufferRW, LPVOID target)
{
LIMITED_METHOD_CONTRACT;

Expand All @@ -385,36 +385,15 @@ inline void emitJumpInd(LPBYTE pBuffer, LPVOID target)
}

//------------------------------------------------------------------------
// Given the same pBuffer that was used by emitJump this method
// Given the same pBuffer that was used by emitBackToBackJump this method
// decodes the instructions and returns the jump target
inline PCODE decodeJump(PCODE pCode)
inline PCODE decodeBackToBackJump(PCODE pCode)
{
LIMITED_METHOD_DAC_CONTRACT;
CONSISTENCY_CHECK(*PTR_BYTE(pCode) == X86_INSTR_JMP_REL32);
return rel32Decode(pCode+1);
}

//
// On IA64 back to back jumps should be separated by a nop bundle to get
// the best performance from the hardware's branch prediction logic.
// For all other platforms back to back jumps don't require anything special
// That is why we have these two wrapper functions that call emitJump and decodeJump
//

//------------------------------------------------------------------------
inline void emitBackToBackJump(LPBYTE pBufferRX, LPBYTE pBufferRW, LPVOID target)
{
WRAPPER_NO_CONTRACT;
emitJump(pBufferRX, pBufferRW, target);
}

//------------------------------------------------------------------------
inline PCODE decodeBackToBackJump(PCODE pBuffer)
{
WRAPPER_NO_CONTRACT;
SUPPORTS_DAC;
return decodeJump(pBuffer);
}

EXTERN_C void __stdcall setFPReturn(int fpSize, INT64 retVal);
EXTERN_C void __stdcall getFPReturn(int fpSize, INT64 *pretval);
Expand Down
21 changes: 3 additions & 18 deletions src/coreclr/vm/loongarch64/cgencpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ inline BOOL ClrFlushInstructionCache(LPCVOID pCodeAddr, size_t sizeOfCode, bool
}

//------------------------------------------------------------------------
inline void emitJump(LPBYTE pBufferRX, LPBYTE pBufferRW, LPVOID target)
inline void emitBackToBackJump(LPBYTE pBufferRX, LPBYTE pBufferRW, LPVOID target)
{
LIMITED_METHOD_CONTRACT;
UINT32* pCode = (UINT32*)pBufferRW;
Expand All @@ -319,9 +319,9 @@ inline void emitJump(LPBYTE pBufferRX, LPBYTE pBufferRW, LPVOID target)
}

//------------------------------------------------------------------------
// Given the same pBuffer that was used by emitJump this method
// Given the same pBuffer that was used by emitBackToBackJump this method
// decodes the instructions and returns the jump target
inline PCODE decodeJump(PCODE pCode)
inline PCODE decodeBackToBackJump(PCODE pCode)
{
LIMITED_METHOD_CONTRACT;

Expand All @@ -330,21 +330,6 @@ inline PCODE decodeJump(PCODE pCode)
return *dac_cast<PTR_PCODE>(pInstr + 16);
}

//------------------------------------------------------------------------
inline void emitBackToBackJump(LPBYTE pBufferRX, LPBYTE pBufferRW, LPVOID target)
{
WRAPPER_NO_CONTRACT;
emitJump(pBufferRX, pBufferRW, target);
}

//------------------------------------------------------------------------
inline PCODE decodeBackToBackJump(PCODE pBuffer)
{
WRAPPER_NO_CONTRACT;
return decodeJump(pBuffer);
}


//----------------------------------------------------------------------

struct IntReg
Expand Down
8 changes: 0 additions & 8 deletions src/coreclr/vm/loongarch64/stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,14 +679,6 @@ int SwitchToNonWriteWatchBarrier(bool isRuntimeSuspended)
}
#endif // FEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP

#ifdef DACCESS_COMPILE
BOOL GetAnyThunkTarget (T_CONTEXT *pctx, TADDR *pTarget, TADDR *pTargetMethodDesc)
{
_ASSERTE(!"LOONGARCH64:NYI");
return FALSE;
}
#endif // DACCESS_COMPILE

#ifndef DACCESS_COMPILE
// ----------------------------------------------------------------
// StubLinkerCPU methods
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/precode.h
Original file line number Diff line number Diff line change
Expand Up @@ -696,8 +696,8 @@ class Precode {

#ifdef TARGET_AMD64
// Handle jump stubs
if (isJumpRel64(target)) {
target = decodeJump64(target);
if (isBackToBackJump(target)) {
target = decodeBackToBackJump(target);
if (target == addr)
return TRUE;
}
Expand Down
Loading
Loading