1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//
//
#ifndef __ExState_h__
#define __ExState_h__
class ExceptionFlags;
class DebuggerExState;
class EHClauseInfo;
#include "exceptionhandling.h"
#if !defined(FEATURE_EH_FUNCLETS)
// ExInfo contains definitions for 32bit
#include "exinfo.h"
#endif // !defined(FEATURE_EH_FUNCLETS)
#if !defined(DACCESS_COMPILE)
#define PRESERVE_WATSON_ACROSS_CONTEXTS 1
#endif
extern StackWalkAction COMPlusUnwindCallback(CrawlFrame *pCf, ThrowCallbackType *pData);
//
// This class serves as a forwarding and abstraction layer for the EH subsystem.
// Since we have two different implementations, this class is needed to unify
// the EE's view of EH. Ideally, this is just a step along the way to a unified
// EH subsystem.
//
typedef DPTR(class ThreadExceptionState) PTR_ThreadExceptionState;
class ThreadExceptionState
{
friend class ClrDataExceptionState;
friend class CheckAsmOffsets;
friend class StackFrameIterator;
#ifdef DACCESS_COMPILE
friend class ClrDataAccess;
#endif // DACCESS_COMPILE
// ProfToEEInterfaceImpl::GetNotifiedExceptionClauseInfo needs access so that it can fetch the
// ExceptionTracker or the ExInfo as appropriate for the platform
friend class ProfToEEInterfaceImpl;
#ifdef FEATURE_EH_FUNCLETS
friend class ExceptionTracker;
#else
friend class ExInfo;
#endif // FEATURE_EH_FUNCLETS
public:
void FreeAllStackTraces();
#ifdef _DEBUG
typedef enum
{
STEC_All,
STEC_CurrentTrackerEqualNullOkHackForFatalStackOverflow,
#ifdef FEATURE_INTERPRETER
STEC_CurrentTrackerEqualNullOkForInterpreter,
#endif // FEATURE_INTERPRETER
} SetThrowableErrorChecking;
#endif
void SetThrowable(OBJECTREF throwable DEBUG_ARG(SetThrowableErrorChecking stecFlags = STEC_All));
OBJECTREF GetThrowable();
OBJECTHANDLE GetThrowableAsHandle();
DWORD GetExceptionCode();
BOOL IsComPlusException();
EXCEPTION_POINTERS* GetExceptionPointers();
PTR_EXCEPTION_RECORD GetExceptionRecord();
PTR_CONTEXT GetContextRecord();
BOOL IsExceptionInProgress();
void GetLeafFrameInfo(StackTraceElement* pStackTrace);
ExceptionFlags* GetFlags();
ThreadExceptionState();
~ThreadExceptionState();
#if !defined(FEATURE_EH_FUNCLETS)
void SetExceptionPointers(EXCEPTION_POINTERS *pExceptionPointers);
#endif
#ifdef DEBUGGING_SUPPORTED
// DebuggerExState stores information necessary for intercepting an exception
DebuggerExState* GetDebuggerState();
// check to see if the current exception is interceptable
BOOL IsDebuggerInterceptable();
#endif // DEBUGGING_SUPPORTED
EHClauseInfo* GetCurrentEHClauseInfo();
#ifdef DACCESS_COMPILE
void EnumChainMemoryRegions(CLRDataEnumMemoryFlags flags);
#endif // DACCESS_COMPILE
enum ThreadExceptionFlag
{
TEF_None = 0x00000000,
// Right now this flag is only used on WIN64. We set this flag near the end of the second pass when we pop
// the ExceptionTracker for the current exception but before we actually resume execution. It is unsafe
// to start a funclet-skipping stackwalk in this time window.
TEF_InconsistentExceptionState = 0x00000001,
TEF_ForeignExceptionRaise = 0x00000002,
};
void SetThreadExceptionFlag(ThreadExceptionFlag flag);
void ResetThreadExceptionFlag(ThreadExceptionFlag flag);
BOOL HasThreadExceptionFlag(ThreadExceptionFlag flag);
inline void SetRaisingForeignException()
{
LIMITED_METHOD_CONTRACT;
SetThreadExceptionFlag(TEF_ForeignExceptionRaise);
}
inline BOOL IsRaisingForeignException()
{
LIMITED_METHOD_CONTRACT;
return HasThreadExceptionFlag(TEF_ForeignExceptionRaise);
}
inline void ResetRaisingForeignException()
{
LIMITED_METHOD_CONTRACT;
ResetThreadExceptionFlag(TEF_ForeignExceptionRaise);
}
#if defined(_DEBUG)
void AssertStackTraceInfo(StackTraceInfo *pSTI);
#endif // _debug
private:
Thread* GetMyThread();
#ifdef FEATURE_EH_FUNCLETS
PTR_ExceptionTracker m_pCurrentTracker;
ExceptionTracker m_OOMTracker;
public:
PTR_ExceptionTracker GetCurrentExceptionTracker()
{
LIMITED_METHOD_CONTRACT;
return m_pCurrentTracker;
}
#else
ExInfo m_currentExInfo;
public:
PTR_ExInfo GetCurrentExceptionTracker()
{
LIMITED_METHOD_CONTRACT;
return PTR_ExInfo(PTR_HOST_MEMBER_TADDR(ThreadExceptionState, this, m_currentExInfo));
}
#endif
private:
ThreadExceptionFlag m_flag;
#ifndef TARGET_UNIX
private:
EHWatsonBucketTracker m_UEWatsonBucketTracker;
public:
PTR_EHWatsonBucketTracker GetUEWatsonBucketTracker()
{
LIMITED_METHOD_CONTRACT;
return PTR_EHWatsonBucketTracker(PTR_HOST_MEMBER_TADDR(ThreadExceptionState, this, m_UEWatsonBucketTracker));
}
#endif // !TARGET_UNIX
private:
#ifndef FEATURE_EH_FUNCLETS
//
// @NICE: Ideally, these friends shouldn't all be enumerated like this. If they were all part of the same
// class, that would be nice. I'm trying to avoid adding x86-specific accessors to this class as well as
// trying to limit the visibility of the ExInfo struct since Win64 doesn't use ExInfo.
//
friend EXCEPTION_DISPOSITION COMPlusAfterUnwind(
EXCEPTION_RECORD *pExceptionRecord,
EXCEPTION_REGISTRATION_RECORD *pEstablisherFrame,
ThrowCallbackType& tct);
friend EXCEPTION_DISPOSITION COMPlusAfterUnwind(
EXCEPTION_RECORD *pExceptionRecord,
EXCEPTION_REGISTRATION_RECORD *pEstablisherFrame,
ThrowCallbackType& tct,
Frame *pStartFrame);
friend EXCEPTION_HANDLER_IMPL(COMPlusFrameHandler);
friend EXCEPTION_DISPOSITION __cdecl
CPFH_RealFirstPassHandler(EXCEPTION_RECORD *pExceptionRecord,
EXCEPTION_REGISTRATION_RECORD *pEstablisherFrame,
CONTEXT *pContext,
void *pDispatcherContext,
BOOL bAsynchronousThreadStop,
BOOL fPGCDisabledOnEntry);
friend EXCEPTION_DISPOSITION __cdecl
CPFH_UnwindHandler(EXCEPTION_RECORD *pExceptionRecord,
EXCEPTION_REGISTRATION_RECORD *pEstablisherFrame,
CONTEXT *pContext,
void *pDispatcherContext);
friend void CPFH_UnwindFrames1(Thread* pThread,
EXCEPTION_REGISTRATION_RECORD* pEstablisherFrame,
DWORD exceptionCode);
#ifdef TARGET_X86
friend LPVOID COMPlusEndCatchWorker(Thread * pThread);
#endif
friend StackWalkAction COMPlusThrowCallback(CrawlFrame *pCf, ThrowCallbackType *pData);
friend StackWalkAction COMPlusUnwindCallback(CrawlFrame *pCf, ThrowCallbackType *pData);
#if defined(TARGET_X86)
friend void ResumeAtJitEH(CrawlFrame* pCf, BYTE* startPC, EE_ILEXCEPTION_CLAUSE *EHClausePtr,
DWORD nestingLevel, Thread *pThread, BOOL unwindStack);
#endif // TARGET_X86
friend _EXCEPTION_HANDLER_DECL(COMPlusNestedExceptionHandler);
friend void COMPlusCooperativeTransitionHandler(Frame* pFrame);
friend bool ShouldHandleManagedFault(
EXCEPTION_RECORD* pExceptionRecord,
CONTEXT* pContext,
EXCEPTION_REGISTRATION_RECORD* pEstablisherFrame,
Thread* pThread);
friend class Thread;
// It it the following method that needs to be a friend. But the prototype pulls in a lot more stuff,
// so just make the Thread class a friend.
// friend StackWalkAction Thread::StackWalkFramesEx(PREGDISPLAY pRD, PSTACKWALKFRAMESCALLBACK pCallback,
// VOID *pData, unsigned flags, Frame *pStartFrame);
#endif // FEATURE_EH_FUNCLETS
};
// <WARNING>
// This holder is not thread safe.
// </WARNING>
class ThreadExceptionFlagHolder
{
public:
ThreadExceptionFlagHolder(ThreadExceptionState::ThreadExceptionFlag flag);
~ThreadExceptionFlagHolder();
private:
ThreadExceptionState* m_pExState;
ThreadExceptionState::ThreadExceptionFlag m_flag;
};
extern BOOL IsWatsonEnabled();
#endif // __ExState_h__
|