void FixupInlineGetters(DWORD tlsSlot, const LPVOID * pLocations, int nLocations) { BYTE* pInlineGetter; DWORD dwOldProtect; for (int i=0; i<nLocations; i++) { pInlineGetter = (BYTE*)GetEEFuncEntryPoint((BYTE*)pLocations[i]); static const DWORD cbPatch = 9; if (!ClrVirtualProtect(pInlineGetter, cbPatch, PAGE_EXECUTE_READWRITE, &dwOldProtect)) { ThrowLastError(); } DWORD offset = (tlsSlot * sizeof(LPVOID) + offsetof(TEB, TlsSlots)); #if defined(_TARGET_AMD64_) // mov r??, gs:[TLS offset] _ASSERTE_ALL_BUILDS("clr/src/VM/JITinterfaceGen.cpp", pInlineGetter[0] == 0x65 && pInlineGetter[2] == 0x8B && pInlineGetter[4] == 0x25 && "Initialization failure while stomping instructions for the TLS slot offset: the instruction at the given offset did not match what we expect"); *((DWORD*)(pInlineGetter + 5)) = offset; #else // _TARGET_AMD64_ PORTABILITY_ASSERT("FixupInlineGetters"); #endif //_TARGET_AMD64_ FlushInstructionCache(GetCurrentProcess(), pInlineGetter, cbPatch); ClrVirtualProtect(pInlineGetter, cbPatch, dwOldProtect, &dwOldProtect); } }
void InitJITHelpers1() { STANDARD_VM_CONTRACT; _ASSERTE(g_SystemInfo.dwNumberOfProcessors != 0); #if defined(_TARGET_AMD64_) g_WriteBarrierManager.Initialize(); #ifndef FEATURE_IMPLICIT_TLS if (gThreadTLSIndex < TLS_MINIMUM_AVAILABLE) { FixupInlineGetters(gThreadTLSIndex, InlineGetThreadLocations, COUNTOF(InlineGetThreadLocations)); } if (gAppDomainTLSIndex < TLS_MINIMUM_AVAILABLE) { FixupInlineGetters(gAppDomainTLSIndex, InlineGetAppDomainLocations, COUNTOF(InlineGetAppDomainLocations)); } #endif // !FEATURE_IMPLICIT_TLS // Allocation helpers, faster but non-logging if (!((TrackAllocationsEnabled()) || (LoggingOn(LF_GCALLOC, LL_INFO10)) #ifdef _DEBUG || (g_pConfig->ShouldInjectFault(INJECTFAULT_GCHEAP) != 0) #endif // _DEBUG )) { // if (multi-proc || server GC) if (GCHeap::UseAllocationContexts()) { #ifdef FEATURE_IMPLICIT_TLS SetJitHelperFunction(CORINFO_HELP_NEWSFAST, JIT_NewS_MP_FastPortable); SetJitHelperFunction(CORINFO_HELP_NEWSFAST_ALIGN8, JIT_NewS_MP_FastPortable); SetJitHelperFunction(CORINFO_HELP_NEWARR_1_VC, JIT_NewArr1VC_MP_FastPortable); SetJitHelperFunction(CORINFO_HELP_NEWARR_1_OBJ, JIT_NewArr1OBJ_MP_FastPortable); ECall::DynamicallyAssignFCallImpl(GetEEFuncEntryPoint(AllocateString_MP_FastPortable), ECall::FastAllocateString); #else // !FEATURE_IMPLICIT_TLS // If the TLS for Thread is low enough use the super-fast helpers if (gThreadTLSIndex < TLS_MINIMUM_AVAILABLE) { SetJitHelperFunction(CORINFO_HELP_NEWSFAST, JIT_TrialAllocSFastMP_InlineGetThread); SetJitHelperFunction(CORINFO_HELP_NEWSFAST_ALIGN8, JIT_TrialAllocSFastMP_InlineGetThread); SetJitHelperFunction(CORINFO_HELP_BOX, JIT_BoxFastMP_InlineGetThread); SetJitHelperFunction(CORINFO_HELP_NEWARR_1_VC, JIT_NewArr1VC_MP_InlineGetThread); SetJitHelperFunction(CORINFO_HELP_NEWARR_1_OBJ, JIT_NewArr1OBJ_MP_InlineGetThread); ECall::DynamicallyAssignFCallImpl(GetEEFuncEntryPoint(AllocateStringFastMP_InlineGetThread), ECall::FastAllocateString); } else { SetJitHelperFunction(CORINFO_HELP_NEWSFAST, JIT_TrialAllocSFastMP); SetJitHelperFunction(CORINFO_HELP_NEWSFAST_ALIGN8, JIT_TrialAllocSFastMP); SetJitHelperFunction(CORINFO_HELP_BOX, JIT_BoxFastMP); SetJitHelperFunction(CORINFO_HELP_NEWARR_1_VC, JIT_NewArr1VC_MP); SetJitHelperFunction(CORINFO_HELP_NEWARR_1_OBJ, JIT_NewArr1OBJ_MP); ECall::DynamicallyAssignFCallImpl(GetEEFuncEntryPoint(AllocateStringFastMP), ECall::FastAllocateString); } #endif // FEATURE_IMPLICIT_TLS } else { #ifndef FEATURE_PAL // Replace the 1p slow allocation helpers with faster version // // When we're running Workstation GC on a single proc box we don't have // InlineGetThread versions because there is no need to call GetThread SetJitHelperFunction(CORINFO_HELP_NEWSFAST, JIT_TrialAllocSFastSP); SetJitHelperFunction(CORINFO_HELP_NEWSFAST_ALIGN8, JIT_TrialAllocSFastSP); SetJitHelperFunction(CORINFO_HELP_BOX, JIT_BoxFastUP); SetJitHelperFunction(CORINFO_HELP_NEWARR_1_VC, JIT_NewArr1VC_UP); SetJitHelperFunction(CORINFO_HELP_NEWARR_1_OBJ, JIT_NewArr1OBJ_UP); ECall::DynamicallyAssignFCallImpl(GetEEFuncEntryPoint(AllocateStringFastUP), ECall::FastAllocateString); #endif // !FEATURE_PAL } } #ifndef FEATURE_IMPLICIT_TLS if (gThreadTLSIndex >= TLS_MINIMUM_AVAILABLE) { // We need to patch the helpers for FCalls MakeIntoJumpStub(JIT_MonEnterWorker_InlineGetThread, JIT_MonEnterWorker_Slow); MakeIntoJumpStub(JIT_MonExitWorker_InlineGetThread, JIT_MonExitWorker_Slow); MakeIntoJumpStub(JIT_MonTryEnter_InlineGetThread, JIT_MonTryEnter_Slow); SetJitHelperFunction(CORINFO_HELP_MON_ENTER, JIT_MonEnterWorker_Slow); SetJitHelperFunction(CORINFO_HELP_MON_EXIT, JIT_MonExitWorker_Slow); SetJitHelperFunction(CORINFO_HELP_MON_ENTER_STATIC, JIT_MonEnterStatic_Slow); SetJitHelperFunction(CORINFO_HELP_MON_EXIT_STATIC, JIT_MonExitStatic_Slow); } if (gAppDomainTLSIndex >= TLS_MINIMUM_AVAILABLE) { SetJitHelperFunction(CORINFO_HELP_GETSHARED_GCSTATIC_BASE, JIT_GetSharedGCStaticBase_Slow); SetJitHelperFunction(CORINFO_HELP_GETSHARED_NONGCSTATIC_BASE, JIT_GetSharedNonGCStaticBase_Slow); SetJitHelperFunction(CORINFO_HELP_GETSHARED_GCSTATIC_BASE_NOCTOR, JIT_GetSharedGCStaticBaseNoCtor_Slow); SetJitHelperFunction(CORINFO_HELP_GETSHARED_NONGCSTATIC_BASE_NOCTOR,JIT_GetSharedNonGCStaticBaseNoCtor_Slow); } #endif // !FEATURE_IMPLICIT_TLS #endif // _TARGET_AMD64_ }
PCODE TheGenericComplusCallStub() { LIMITED_METHOD_CONTRACT; return GetEEFuncEntryPoint(GenericComPlusCallStub); }