Skip to content

Commit 95b67ed

Browse files
authored
Remove HOST_CALLS contract and related stuff (#100604)
* Remove HOST_CALLS contract and related stuff The HOST_CALLS contract is obsolete remainder from the .NET framework era, this change removes all of the use of that contract and the related code. * Remove ShouldAvoidHost calls et al too.
1 parent ac7f025 commit 95b67ed

34 files changed

+43
-513
lines changed

src/coreclr/inc/contract.h

+5-86
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@
140140
// ModeViolation
141141
// FaultViolation
142142
// FaultNotFatal
143-
// HostViolation
144143
// LoadsTypeViolation
145144
// TakesLockViolation
146145
//
@@ -378,7 +377,7 @@ struct DbgStateLockState
378377

379378
#define CONTRACT_BITMASK_OK_TO_THROW 0x1 << 0
380379
#define CONTRACT_BITMASK_FAULT_FORBID 0x1 << 1
381-
#define CONTRACT_BITMASK_HOSTCALLS 0x1 << 2
380+
// Unused 0x1 << 2
382381
#define CONTRACT_BITMASK_SOTOLERANT 0x1 << 3
383382
#define CONTRACT_BITMASK_DEBUGONLY 0x1 << 4
384383
#define CONTRACT_BITMASK_SONOTMAINLINE 0x1 << 5
@@ -422,7 +421,6 @@ struct ClrDebugState
422421
// By default, GetThread() is perfectly fine to call
423422
// By default, it's ok to take a lock (or call someone who does)
424423
m_flags = CONTRACT_BITMASK_OK_TO_THROW|
425-
CONTRACT_BITMASK_HOSTCALLS|
426424
CONTRACT_BITMASK_SOTOLERANT|
427425
CONTRACT_BITMASK_OK_TO_LOCK|
428426
CONTRACT_BITMASK_OK_TO_RETAKE_LOCK;
@@ -512,30 +510,6 @@ struct ClrDebugState
512510
CONTRACT_BITMASK_RESET(CONTRACT_BITMASK_FAULT_FORBID);
513511
}
514512

515-
//--//
516-
BOOL IsHostCaller()
517-
{
518-
return CONTRACT_BITMASK_IS_SET(CONTRACT_BITMASK_HOSTCALLS);
519-
}
520-
521-
void SetHostCaller()
522-
{
523-
CONTRACT_BITMASK_SET(CONTRACT_BITMASK_HOSTCALLS);
524-
}
525-
526-
527-
BOOL SetHostCaller(BOOL value)
528-
{
529-
BOOL prevState = CONTRACT_BITMASK_IS_SET(CONTRACT_BITMASK_HOSTCALLS);
530-
CONTRACT_BITMASK_UPDATE(CONTRACT_BITMASK_HOSTCALLS,value);
531-
return prevState;
532-
}
533-
534-
void ResetHostCaller()
535-
{
536-
CONTRACT_BITMASK_RESET(CONTRACT_BITMASK_HOSTCALLS);
537-
}
538-
539513
//--//
540514
BOOL IsDebugOnly()
541515
{
@@ -896,11 +870,8 @@ class BaseContract
896870

897871
SO_MAINLINE_No = 0x00000800, // code is not part of our mainline SO scenario
898872

899-
// Any place where we can't safely call into the host should have a HOST_NoCalls contract
900-
HOST_Mask = 0x00003000,
901-
HOST_Calls = 0x00002000,
902-
HOST_NoCalls = 0x00001000,
903-
HOST_Disabled = 0x00000000, // the default
873+
// Unused = 0x00002000,
874+
// Unused = 0x00001000,
904875

905876
// These enforce the CAN_TAKE_LOCK / CANNOT_TAKE_LOCK contracts
906877
CAN_TAKE_LOCK_Mask = 0x00060000,
@@ -920,7 +891,7 @@ class BaseContract
920891
LOADS_TYPE_Disabled = 0x00000000, // the default
921892

922893
ALL_Disabled = THROWS_Disabled|GC_Disabled|FAULT_Disabled|MODE_Disabled|LOADS_TYPE_Disabled|
923-
HOST_Disabled|CAN_TAKE_LOCK_Disabled|CAN_RETAKE_LOCK_No_Disabled
894+
CAN_TAKE_LOCK_Disabled|CAN_RETAKE_LOCK_No_Disabled
924895

925896
};
926897

@@ -1124,7 +1095,6 @@ enum ContractViolationBits
11241095
FaultNotFatal = 0x00000010, // suppress INJECT_FAULT but not fault injection by harness
11251096
LoadsTypeViolation = 0x00000040, // suppress LOADS_TYPE tags in this scope
11261097
TakesLockViolation = 0x00000080, // suppress CAN_TAKE_LOCK tags in this scope
1127-
HostViolation = 0x00000100, // suppress HOST_CALLS tags in this scope
11281098

11291099
//These are not violation bits. We steal some bits out of the violation mask to serve as
11301100
// general flag bits.
@@ -1667,7 +1637,7 @@ class ContractViolationHolder
16671637
FORCEINLINE void EnterInternal(UINT_PTR violationMask)
16681638
{
16691639
_ASSERTE(0 == (violationMask & ~(ThrowsViolation | GCViolation | ModeViolation | FaultViolation |
1670-
FaultNotFatal | HostViolation |
1640+
FaultNotFatal |
16711641
TakesLockViolation | LoadsTypeViolation)) ||
16721642
violationMask == AllViolation);
16731643

@@ -1738,9 +1708,6 @@ enum PermanentContractViolationReason
17381708
ReasonIBC, // Code runs in IBC scenarios only and the violation is safe.
17391709
ReasonNGEN, // Code runs in NGEN scenarios only and the violation is safe.
17401710
ReasonProfilerCallout, // Profiler implementers are guaranteed not to throw.
1741-
ReasonUnsupportedForSQLF1Profiling, // This code path violates HOST_NOCALLS, but that's ok b/c SQL will never
1742-
// invoke it, and thus SQL/F1 profiling (the primary reason to enforce
1743-
// HOST_NOCALLS) is not in danger.
17441711
ReasonRuntimeReentrancy, // e.g. SafeQueryInterface
17451712
ReasonShutdownOnly, // Code path only runs as part of Shutdown and the violation is safe.
17461713
ReasonSOTolerance, // We would like to redesign SO contracts anyways
@@ -2006,54 +1973,6 @@ inline ClrDebugState *GetClrDebugState(BOOL fAlloc)
20061973

20071974
return NULL;
20081975
}
2009-
#endif // ENABLE_CONTRACTS_IMPL
2010-
2011-
#ifdef ENABLE_CONTRACTS_IMPL
2012-
2013-
class HostNoCallHolder
2014-
{
2015-
public:
2016-
DEBUG_NOINLINE HostNoCallHolder()
2017-
{
2018-
SCAN_SCOPE_BEGIN;
2019-
STATIC_CONTRACT_HOST_NOCALLS;
2020-
2021-
m_clrDebugState = GetClrDebugState();
2022-
m_previousState = m_clrDebugState->SetHostCaller(FALSE);
2023-
}
2024-
2025-
DEBUG_NOINLINE ~HostNoCallHolder()
2026-
{
2027-
SCAN_SCOPE_END;
2028-
2029-
m_clrDebugState->SetHostCaller(m_previousState);
2030-
}
2031-
2032-
private:
2033-
BOOL m_previousState;
2034-
ClrDebugState* m_clrDebugState;
2035-
2036-
};
2037-
2038-
#define BEGIN_HOST_NOCALL_CODE \
2039-
{ \
2040-
HostNoCallHolder __hostNoCallHolder; \
2041-
CantAllocHolder __cantAlloc;
2042-
2043-
#define END_HOST_NOCALL_CODE \
2044-
}
2045-
2046-
#else // ENABLE_CONTRACTS_IMPL
2047-
#define BEGIN_HOST_NOCALL_CODE \
2048-
{ \
2049-
CantAllocHolder __cantAlloc; \
2050-
2051-
#define END_HOST_NOCALL_CODE \
2052-
}
2053-
#endif
2054-
2055-
2056-
#if defined(ENABLE_CONTRACTS_IMPL)
20571976

20581977
// Macros to indicate we're taking or releasing locks
20591978

src/coreclr/inc/staticcontract.h

-9
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@
9393
#define ANNOTATION_FN_MODE_COOPERATIVE __annotation(W("MODE_COOPERATIVE ") SCAN_WIDEN(__FUNCTION__))
9494
#define ANNOTATION_FN_MODE_PREEMPTIVE __annotation(W("MODE_PREEMPTIVE ") SCAN_WIDEN(__FUNCTION__))
9595
#define ANNOTATION_FN_MODE_ANY __annotation(W("MODE_ANY ") SCAN_WIDEN(__FUNCTION__))
96-
#define ANNOTATION_FN_HOST_NOCALLS __annotation(W("HOST_NOCALLS ") SCAN_WIDEN(__FUNCTION__))
97-
#define ANNOTATION_FN_HOST_CALLS __annotation(W("HOST_CALLS ") SCAN_WIDEN(__FUNCTION__))
9896

9997
#define ANNOTATION_ENTRY_POINT __annotation(W("SO_EP ") SCAN_WIDEN(__FUNCTION__))
10098

@@ -135,9 +133,6 @@
135133
#define ANNOTATION_TRY_MARKER { }
136134
#define ANNOTATION_CATCH_MARKER { }
137135

138-
#define ANNOTATION_FN_HOST_NOCALLS { }
139-
#define ANNOTATION_FN_HOST_CALLS { }
140-
141136
#define ANNOTATION_FN_SPECIAL_HOLDER_BEGIN { }
142137
#define ANNOTATION_SPECIAL_HOLDER_END { }
143138
#define ANNOTATION_SPECIAL_HOLDER_CALLER_NEEDS_DYNAMIC_CONTRACT { }
@@ -155,8 +150,6 @@
155150
#define ANNOTATION_FN_MODE_COOPERATIVE { }
156151
#define ANNOTATION_FN_MODE_PREEMPTIVE { }
157152
#define ANNOTATION_FN_MODE_ANY { }
158-
#define ANNOTATION_FN_HOST_NOCALLS { }
159-
#define ANNOTATION_FN_HOST_CALLS { }
160153

161154
#define ANNOTATION_SUPPORTS_DAC { }
162155
#define ANNOTATION_SUPPORTS_DAC_HOST_ONLY { }
@@ -179,8 +172,6 @@
179172
#define STATIC_CONTRACT_FORBID_FAULT ANNOTATION_FN_FORBID_FAULT
180173
#define STATIC_CONTRACT_GC_TRIGGERS ANNOTATION_FN_GC_TRIGGERS
181174
#define STATIC_CONTRACT_GC_NOTRIGGER ANNOTATION_FN_GC_NOTRIGGER
182-
#define STATIC_CONTRACT_HOST_NOCALLS ANNOTATION_FN_HOST_NOCALLS
183-
#define STATIC_CONTRACT_HOST_CALLS ANNOTATION_FN_HOST_CALLS
184175

185176
#define STATIC_CONTRACT_SUPPORTS_DAC ANNOTATION_SUPPORTS_DAC
186177
#define STATIC_CONTRACT_SUPPORTS_DAC_HOST_ONLY ANNOTATION_SUPPORTS_DAC_HOST_ONLY

src/coreclr/nativeaot/Runtime/windows/CoffNativeCodeManager.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#define CONTRACTL_END
3030
#define NOTHROW
3131
#define GC_NOTRIGGER
32-
#define HOST_NOCALLS
3332

3433
#include "../../inc/gcdecoder.cpp"
3534
#include "../../inc/gc_unwind_x86.h"

src/coreclr/utilcode/check.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ SPECIALIZED_VIOLATION(GCViolation);
6363
SPECIALIZED_VIOLATION(ModeViolation);
6464
SPECIALIZED_VIOLATION(FaultViolation);
6565
SPECIALIZED_VIOLATION(FaultNotFatal);
66-
SPECIALIZED_VIOLATION(HostViolation);
6766
SPECIALIZED_VIOLATION(TakesLockViolation);
6867
SPECIALIZED_VIOLATION(LoadsTypeViolation);
6968

src/coreclr/utilcode/debug.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,6 @@ VOID DbgAssertDialog(const char *szFile, int iLine, const char *szExpr)
411411

412412
SUPPRESS_ALLOCATION_ASSERTS_IN_THIS_SCOPE;
413413

414-
// Raising the assert dialog can cause us to re-enter the host when allocating
415-
// memory for the string. Since this is debug-only code, we can safely skip
416-
// violation asserts here, particularly since they can also cause infinite
417-
// recursion.
418-
PERMANENT_CONTRACT_VIOLATION(HostViolation, ReasonDebugOnly);
419-
420414
dbgForceToMemory = &szFile; //make certain these args are available in the debugger
421415
dbgForceToMemory = &iLine;
422416
dbgForceToMemory = &szExpr;

src/coreclr/vm/amd64/cgenamd64.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ void InlinedCallFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats
9393
#ifdef PROFILING_SUPPORTED
9494
PRECONDITION(CORProfilerStackSnapshotEnabled() || InlinedCallFrame::FrameHasActiveCall(this));
9595
#endif
96-
HOST_NOCALLS;
9796
MODE_ANY;
9897
SUPPORTS_DAC;
9998
}

src/coreclr/vm/amd64/gmsamd64.cpp

+2-16
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
void LazyMachState::unwindLazyState(LazyMachState* baseState,
1212
MachState* unwoundState,
1313
DWORD threadId,
14-
int funCallDepth /* = 1 */,
15-
HostCallPreference hostCallPreference /* = (HostCallPreference)(-1) */)
14+
int funCallDepth /* = 1 */)
1615
{
1716
CONTRACTL
1817
{
@@ -83,20 +82,7 @@ void LazyMachState::unwindLazyState(LazyMachState* baseState,
8382
{
8483
// Determine whether given IP resides in JITted code. (It returns nonzero in that case.)
8584
// Use it now to see if we've unwound to managed code yet.
86-
BOOL fFailedReaderLock = FALSE;
87-
BOOL fIsManagedCode = ExecutionManager::IsManagedCode(pvControlPc, hostCallPreference, &fFailedReaderLock);
88-
if (fFailedReaderLock)
89-
{
90-
// We don't know if we would have been able to find a JIT
91-
// manager, because we couldn't enter the reader lock without
92-
// yielding (and our caller doesn't want us to yield). So abort
93-
// now.
94-
95-
// Invalidate the lazyState we're returning, so the caller knows
96-
// we aborted before we could fully unwind
97-
unwoundState->_pRetAddr = NULL;
98-
return;
99-
}
85+
BOOL fIsManagedCode = ExecutionManager::IsManagedCode(pvControlPc);
10086

10187
if (fIsManagedCode)
10288
break;

src/coreclr/vm/amd64/gmscpu.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ struct LazyMachState : public MachState
101101
static void unwindLazyState(LazyMachState* baseState,
102102
MachState* lazyState,
103103
DWORD threadId,
104-
int funCallDepth = 1,
105-
HostCallPreference hostCallPreference = AllowHostCalls);
104+
int funCallDepth = 1);
106105

107106
friend class HelperMethodFrame;
108107
friend class CheckAsmOffsets;

src/coreclr/vm/arm/gmscpu.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ struct LazyMachState : public MachState {
8181
static void unwindLazyState(LazyMachState* baseState,
8282
MachState* lazyState,
8383
DWORD threadId,
84-
int funCallDepth = 1,
85-
HostCallPreference hostCallPreference = AllowHostCalls);
84+
int funCallDepth = 1);
8685

8786
friend class HelperMethodFrame;
8887
friend class CheckAsmOffsets;

src/coreclr/vm/arm/stubs.cpp

+2-17
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,7 @@ void FlushWriteBarrierInstructionCache()
509509
void LazyMachState::unwindLazyState(LazyMachState* baseState,
510510
MachState* unwoundstate,
511511
DWORD threadId,
512-
int funCallDepth,
513-
HostCallPreference hostCallPreference)
512+
int funCallDepth)
514513
{
515514
T_CONTEXT ctx;
516515
T_KNONVOLATILE_CONTEXT_POINTERS nonVolRegPtrs;
@@ -575,20 +574,7 @@ void LazyMachState::unwindLazyState(LazyMachState* baseState,
575574
{
576575
// Determine whether given IP resides in JITted code. (It returns nonzero in that case.)
577576
// Use it now to see if we've unwound to managed code yet.
578-
BOOL fFailedReaderLock = FALSE;
579-
BOOL fIsManagedCode = ExecutionManager::IsManagedCode(pvControlPc, hostCallPreference, &fFailedReaderLock);
580-
if (fFailedReaderLock)
581-
{
582-
// We don't know if we would have been able to find a JIT
583-
// manager, because we couldn't enter the reader lock without
584-
// yielding (and our caller doesn't want us to yield). So abort
585-
// now.
586-
587-
// Invalidate the lazyState we're returning, so the caller knows
588-
// we aborted before we could fully unwind
589-
unwoundstate->_isValid = false;
590-
return;
591-
}
577+
BOOL fIsManagedCode = ExecutionManager::IsManagedCode(pvControlPc);
592578

593579
if (fIsManagedCode)
594580
break;
@@ -1583,7 +1569,6 @@ void InlinedCallFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats
15831569
#ifdef PROFILING_SUPPORTED
15841570
PRECONDITION(CORProfilerStackSnapshotEnabled() || InlinedCallFrame::FrameHasActiveCall(this));
15851571
#endif
1586-
HOST_NOCALLS;
15871572
MODE_ANY;
15881573
SUPPORTS_DAC;
15891574
}

src/coreclr/vm/arm64/gmscpu.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ struct LazyMachState : public MachState{
4444
static void unwindLazyState(LazyMachState* baseState,
4545
MachState* lazyState,
4646
DWORD threadId,
47-
int funCallDepth = 1,
48-
HostCallPreference hostCallPreference = AllowHostCalls);
47+
int funCallDepth = 1);
4948
};
5049

5150
inline void LazyMachState::setLazyStateFromUnwind(MachState* copy)

src/coreclr/vm/arm64/stubs.cpp

+2-17
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,7 @@ void ClearRegDisplayArgumentAndScratchRegisters(REGDISPLAY * pRD)
277277
void LazyMachState::unwindLazyState(LazyMachState* baseState,
278278
MachState* unwoundstate,
279279
DWORD threadId,
280-
int funCallDepth,
281-
HostCallPreference hostCallPreference)
280+
int funCallDepth)
282281
{
283282
T_CONTEXT context;
284283
T_KNONVOLATILE_CONTEXT_POINTERS nonVolContextPtrs;
@@ -357,20 +356,7 @@ void LazyMachState::unwindLazyState(LazyMachState* baseState,
357356
{
358357
// Determine whether given IP resides in JITted code. (It returns nonzero in that case.)
359358
// Use it now to see if we've unwound to managed code yet.
360-
BOOL fFailedReaderLock = FALSE;
361-
BOOL fIsManagedCode = ExecutionManager::IsManagedCode(pvControlPc, hostCallPreference, &fFailedReaderLock);
362-
if (fFailedReaderLock)
363-
{
364-
// We don't know if we would have been able to find a JIT
365-
// manager, because we couldn't enter the reader lock without
366-
// yielding (and our caller doesn't want us to yield). So abort
367-
// now.
368-
369-
// Invalidate the lazyState we're returning, so the caller knows
370-
// we aborted before we could fully unwind
371-
unwoundstate->_isValid = false;
372-
return;
373-
}
359+
BOOL fIsManagedCode = ExecutionManager::IsManagedCode(pvControlPc);
374360

375361
if (fIsManagedCode)
376362
break;
@@ -684,7 +670,6 @@ void InlinedCallFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats
684670
#ifdef PROFILING_SUPPORTED
685671
PRECONDITION(CORProfilerStackSnapshotEnabled() || InlinedCallFrame::FrameHasActiveCall(this));
686672
#endif
687-
HOST_NOCALLS;
688673
MODE_ANY;
689674
SUPPORTS_DAC;
690675
}

0 commit comments

Comments
 (0)