-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
frames.h
3434 lines (2849 loc) · 107 KB
/
frames.h
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// FRAMES.H
//
// These C++ classes expose activation frames to the rest of the EE.
// Activation frames are actually created by JIT-generated or stub-generated
// code on the machine stack. Thus, the layout of the Frame classes and
// the JIT/Stub code generators are tightly interwined.
//
// IMPORTANT: Since frames are not actually constructed by C++,
// don't try to define constructor/destructor functions. They won't get
// called.
//
// IMPORTANT: Not all methods have full-fledged activation frames (in
// particular, the JIT may create frameless methods.) This is one reason
// why Frame doesn't expose a public "Next()" method: such a method would
// skip frameless method calls. You must instead use one of the
// StackWalk methods.
//
//
// The following is the hierarchy of frames:
//
// Frame - the root class. There are no actual instances
// | of Frames.
// |
// +- FaultingExceptionFrame - this frame was placed on a method which faulted
// | to save additional state information
// |
#ifdef FEATURE_HIJACK
// |
// +-HijackFrame - if a method's return address is hijacked, we
// | construct one of these to allow crawling back
// | to where the return should have gone.
// |
// +-ResumableFrame - this abstract frame provides the context necessary to
// | | allow garbage collection during handling of
// | | a resumable exception (e.g. during edit-and-continue,
// | | or under GCStress4).
// | |
// | +-RedirectedThreadFrame - this frame is used for redirecting threads during suspension
// |
#endif // FEATURE_HIJACK
// |
// |
// |
// +-InlinedCallFrame - if a call to unmanaged code is hoisted into
// | a JIT'ted caller, the calling method keeps
// | this frame linked throughout its activation.
// |
// +-HelperMethodFrame - frame used allow stack crawling inside jit helpers and fcalls
// | |
// + +-HelperMethodFrame_1OBJ- reports additional object references
// | |
// + +-HelperMethodFrame_2OBJ- reports additional object references
// | |
// + +-HelperMethodFrame_3OBJ- reports additional object references
// | |
// + +-HelperMethodFrame_PROTECTOBJ - reports additional object references
// |
// +-TransitionFrame - this abstract frame represents a transition from
// | | one or more nested frameless method calls
// | | to either a EE runtime helper function or
// | | a framed method.
// | |
// | +-MulticastFrame - this frame protects arguments to a MulticastDelegate
// | Invoke() call while calling each subscriber.
// |
// | +-FramedMethodFrame - this abstract frame represents a call to a method
// | | that generates a full-fledged frame.
// | |
#ifdef FEATURE_COMINTEROP
// | |
// | +-ComPlusMethodFrame - represents a CLR to COM call using the generic worker
// | |
#endif //FEATURE_COMINTEROP
// | |
// | +-PInvokeCalliFrame - protects arguments when a call to GetILStubForCalli is made
// | | to get or create IL stub for an unmanaged CALLI
// | |
// | +-PrestubMethodFrame - represents a call to a prestub
// | |
// | +-StubDispatchFrame - represents a call into the virtual call stub manager
// | |
// | +-CallCountingHelperFrame - represents a call into the call counting helper when the
// | | call count threshold is reached
// | |
// | +-ExternalMethodFrame - represents a call from an ExternalMethdThunk
// | |
// | +-TPMethodFrame - for calls on transparent proxy
// |
#ifdef FEATURE_COMINTEROP
// +-UnmanagedToManagedFrame - this frame represents a transition from
// | | unmanaged code back to managed code. It's
// | | main functions are to stop COM+ exception
// | | propagation and to expose unmanaged parameters.
// | |
// | +-ComMethodFrame - this frame represents a transition from
// | | com to com+
// | |
// | +-ComPrestubMethodFrame - prestub frame for calls from COM to CLR
// |
#endif //FEATURE_COMINTEROP
#if defined(TARGET_X86) && !defined(UNIX_X86_ABI)
// +-TailCallFrame - padding for tailcalls
// |
#endif
// +-ProtectByRefsFrame
// |
// +-ProtectValueClassFrame
// |
// +-DebuggerClassInitMarkFrame - marker frame to indicate that "class init" code is running
// |
// +-DebuggerSecurityCodeMarkFrame - marker frame to indicate that security code is running
// |
// +-DebuggerExitFrame - marker frame to indicate that a "break" IL instruction is being executed
// |
// +-DebuggerU2MCatchHandlerFrame - marker frame to indicate that native code is going to catch and
// | swallow a managed exception
// |
#ifdef DEBUGGING_SUPPORTED
// +-FuncEvalFrame - frame for debugger function evaluation
#endif // DEBUGGING_SUPPORTED
// |
// |
// +-ExceptionFilterFrame - this frame wraps call to exception filter
//
//------------------------------------------------------------------------
#if 0
//------------------------------------------------------------------------
This is the list of Interop stubs & transition helpers with information
regarding what (if any) Frame they used and where they were set up:
P/Invoke:
JIT inlined: The code to call the method is inlined into the caller by the JIT.
InlinedCallFrame is erected by the JITted code.
Requires marshaling: The stub does not erect any frames explicitly but contains
an unmanaged CALLI which turns it into the JIT inlined case.
Delegate over a native function pointer:
The same as P/Invoke but the raw JIT inlined case is not present (the call always
goes through an IL stub).
Calli:
The same as P/Invoke.
PInvokeCalliFrame is erected in stub generated by GenerateGetStubForPInvokeCalli
before calling to GetILStubForCalli which generates the IL stub. This happens only
the first time a call via the corresponding VASigCookie is made.
ClrToCom:
Late-bound or eventing: The stub is generated by GenerateGenericComplusWorker
(x86) or exists statically as GenericComPlusCallStub[RetBuffArg] (64-bit),
and it erects a ComPlusMethodFrame frame.
Early-bound: The stub does not erect any frames explicitly but contains an
unmanaged CALLI which turns it into the JIT inlined case.
ComToClr:
Normal stub:
Interpreted: The stub is generated by ComCall::CreateGenericComCallStub
(in ComToClrCall.cpp) and it erects a ComMethodFrame frame.
Prestub:
The prestub is ComCallPreStub (in ComCallableWrapper.cpp) and it erects
a ComPrestubMethodFrame frame.
Reverse P/Invoke (used for C++ exports & fixups as well as delegates
obtained from function pointers):
Normal stub:
The stub exists statically as UMThunkStub and calls to IL stub.
Prestub:
The prestub exists statically as TheUMEntryPrestub.
//------------------------------------------------------------------------
#endif // 0
//------------------------------------------------------------------------
#ifndef FRAME_ABSTRACT_TYPE_NAME
#define FRAME_ABSTRACT_TYPE_NAME(frameType)
#endif
#ifndef FRAME_TYPE_NAME
#define FRAME_TYPE_NAME(frameType)
#endif
FRAME_ABSTRACT_TYPE_NAME(FrameBase)
FRAME_ABSTRACT_TYPE_NAME(Frame)
FRAME_ABSTRACT_TYPE_NAME(TransitionFrame)
#ifdef FEATURE_HIJACK
FRAME_TYPE_NAME(ResumableFrame)
FRAME_TYPE_NAME(RedirectedThreadFrame)
#endif // FEATURE_HIJACK
FRAME_TYPE_NAME(FaultingExceptionFrame)
#ifdef DEBUGGING_SUPPORTED
FRAME_TYPE_NAME(FuncEvalFrame)
#endif // DEBUGGING_SUPPORTED
FRAME_TYPE_NAME(HelperMethodFrame)
FRAME_TYPE_NAME(HelperMethodFrame_1OBJ)
FRAME_TYPE_NAME(HelperMethodFrame_2OBJ)
FRAME_TYPE_NAME(HelperMethodFrame_3OBJ)
FRAME_TYPE_NAME(HelperMethodFrame_PROTECTOBJ)
FRAME_ABSTRACT_TYPE_NAME(FramedMethodFrame)
FRAME_TYPE_NAME(MulticastFrame)
#ifdef FEATURE_COMINTEROP
FRAME_ABSTRACT_TYPE_NAME(UnmanagedToManagedFrame)
FRAME_TYPE_NAME(ComMethodFrame)
FRAME_TYPE_NAME(ComPlusMethodFrame)
FRAME_TYPE_NAME(ComPrestubMethodFrame)
#endif // FEATURE_COMINTEROP
FRAME_TYPE_NAME(PInvokeCalliFrame)
#ifdef FEATURE_HIJACK
FRAME_TYPE_NAME(HijackFrame)
#endif // FEATURE_HIJACK
FRAME_TYPE_NAME(PrestubMethodFrame)
FRAME_TYPE_NAME(CallCountingHelperFrame)
FRAME_TYPE_NAME(StubDispatchFrame)
FRAME_TYPE_NAME(ExternalMethodFrame)
#ifdef FEATURE_READYTORUN
FRAME_TYPE_NAME(DynamicHelperFrame)
#endif
#ifdef FEATURE_INTERPRETER
FRAME_TYPE_NAME(InterpreterFrame)
#endif // FEATURE_INTERPRETER
FRAME_TYPE_NAME(ProtectByRefsFrame)
FRAME_TYPE_NAME(ProtectValueClassFrame)
FRAME_TYPE_NAME(DebuggerClassInitMarkFrame)
FRAME_TYPE_NAME(DebuggerSecurityCodeMarkFrame)
FRAME_TYPE_NAME(DebuggerExitFrame)
FRAME_TYPE_NAME(DebuggerU2MCatchHandlerFrame)
FRAME_TYPE_NAME(InlinedCallFrame)
#if defined(TARGET_X86) && !defined(UNIX_X86_ABI)
FRAME_TYPE_NAME(TailCallFrame)
#endif
FRAME_TYPE_NAME(ExceptionFilterFrame)
#if defined(_DEBUG)
FRAME_TYPE_NAME(AssumeByrefFromJITStack)
#endif // _DEBUG
#undef FRAME_ABSTRACT_TYPE_NAME
#undef FRAME_TYPE_NAME
//------------------------------------------------------------------------
#ifndef __frames_h__
#define __frames_h__
#if defined(_MSC_VER) && defined(TARGET_X86) && !defined(FPO_ON)
#pragma optimize("y", on) // Small critical routines, don't put in EBP frame
#define FPO_ON 1
#define FRAMES_TURNED_FPO_ON 1
#endif
#include "util.hpp"
#include "vars.hpp"
#include "regdisp.h"
#include "object.h"
#include <stddef.h>
#include "siginfo.hpp"
#include "method.hpp"
#include "stackwalk.h"
#include "stubmgr.h"
#include "gms.h"
#include "threads.h"
#include "callingconvention.h"
// Forward references
class Frame;
class FramedMethodFrame;
typedef VPTR(class FramedMethodFrame) PTR_FramedMethodFrame;
struct HijackArgs;
struct ResolveCacheElem;
#if defined(DACCESS_COMPILE)
class DacDbiInterfaceImpl;
#endif // DACCESS_COMPILE
#ifdef FEATURE_COMINTEROP
class ComMethodFrame;
class ComCallMethodDesc;
#endif // FEATURE_COMINTEROP
// Note: the value (-1) is used to generate the largest possible pointer value: this keeps frame addresses
// increasing upward. Because we want to ensure that we don't accidentally change this, we have a C_ASSERT
// in stackwalk.cpp. Since it requires constant values as args, we need to define FRAME_TOP in two steps.
// First we define FRAME_TOP_VALUE which we'll use when we do the compile-time check, then we'll define
// FRAME_TOP in terms of FRAME_TOP_VALUE. Defining FRAME_TOP as a PTR_Frame means we don't have to type cast
// whenever we compare it to a PTR_Frame value (the usual use of the value).
#define FRAME_TOP_VALUE ~0 // we want to say -1 here, but gcc has trouble with the signed value
#define FRAME_TOP (PTR_Frame(FRAME_TOP_VALUE))
#ifndef DACCESS_COMPILE
#if defined(TARGET_UNIX)
#define DEFINE_DTOR(klass) \
public: \
virtual ~klass() { PopIfChained(); }
#else
#define DEFINE_DTOR(klass)
#endif // TARGET_UNIX
#define DEFINE_VTABLE_GETTER(klass) \
public: \
static TADDR GetMethodFrameVPtr() { \
LIMITED_METHOD_CONTRACT; \
klass boilerplate(false); \
return *((TADDR*)&boilerplate); \
} \
klass(bool dummy) { LIMITED_METHOD_CONTRACT; }
#define DEFINE_VTABLE_GETTER_AND_DTOR(klass) \
DEFINE_VTABLE_GETTER(klass) \
DEFINE_DTOR(klass)
#define DEFINE_VTABLE_GETTER_AND_CTOR(klass) \
DEFINE_VTABLE_GETTER(klass) \
protected: \
klass() { LIMITED_METHOD_CONTRACT; }
#define DEFINE_VTABLE_GETTER_AND_CTOR_AND_DTOR(klass) \
DEFINE_VTABLE_GETTER_AND_DTOR(klass) \
protected: \
klass() { LIMITED_METHOD_CONTRACT; }
#else
#define DEFINE_VTABLE_GETTER(klass) \
public: \
static TADDR GetMethodFrameVPtr() { \
LIMITED_METHOD_CONTRACT; \
return klass::VPtrTargetVTable(); \
} \
#define DEFINE_VTABLE_GETTER_AND_DTOR(klass) \
DEFINE_VTABLE_GETTER(klass) \
#define DEFINE_VTABLE_GETTER_AND_CTOR(klass) \
DEFINE_VTABLE_GETTER(klass) \
#define DEFINE_VTABLE_GETTER_AND_CTOR_AND_DTOR(klass) \
DEFINE_VTABLE_GETTER_AND_CTOR(klass) \
#endif // #ifndef DACCESS_COMPILE
//-----------------------------------------------------------------------------
// For reporting on types of frames at runtime.
class FrameTypeName
{
public:
TADDR vtbl;
PTR_CSTR name;
};
typedef DPTR(FrameTypeName) PTR_FrameTypeName;
//-----------------------------------------------------------------------------
// Frame depends on the location of its vtable within the object. This
// superclass ensures that the vtable for Frame objects is in the same
// location under both MSVC and GCC.
//-----------------------------------------------------------------------------
class FrameBase
{
VPTR_BASE_VTABLE_CLASS(FrameBase)
public:
FrameBase() {LIMITED_METHOD_CONTRACT; }
virtual void GcScanRoots(promote_func *fn, ScanContext* sc) {
LIMITED_METHOD_CONTRACT;
// Nothing to protect
}
#ifdef DACCESS_COMPILE
virtual void EnumMemoryRegions(CLRDataEnumMemoryFlags flags) = 0;
#endif
};
//------------------------------------------------------------------------
// Frame defines methods common to all frame types. There are no actual
// instances of root frames.
//------------------------------------------------------------------------
class Frame : public FrameBase
{
friend class CheckAsmOffsets;
#ifdef DACCESS_COMPILE
friend void Thread::EnumMemoryRegions(CLRDataEnumMemoryFlags flags);
#endif
VPTR_ABSTRACT_VTABLE_CLASS(Frame, FrameBase)
public:
//------------------------------------------------------------------------
// Special characteristics of a frame
//------------------------------------------------------------------------
enum FrameAttribs {
FRAME_ATTR_NONE = 0,
FRAME_ATTR_EXCEPTION = 1, // This frame caused an exception
FRAME_ATTR_OUT_OF_LINE = 2, // The exception out of line (IP of the frame is not correct)
FRAME_ATTR_FAULTED = 4, // Exception caused by Win32 fault
FRAME_ATTR_RESUMABLE = 8, // We may resume from this frame
FRAME_ATTR_CAPTURE_DEPTH_2 = 0x10, // This is a helperMethodFrame and the capture occurred at depth 2
FRAME_ATTR_EXACT_DEPTH = 0x20, // This is a helperMethodFrame and a jit helper, but only crawl to the given depth
FRAME_ATTR_NO_THREAD_ABORT = 0x40, // This is a helperMethodFrame that should not trigger thread aborts on entry
};
virtual unsigned GetFrameAttribs()
{
LIMITED_METHOD_DAC_CONTRACT;
return FRAME_ATTR_NONE;
}
//------------------------------------------------------------------------
// Performs cleanup on an exception unwind
//------------------------------------------------------------------------
#ifndef DACCESS_COMPILE
virtual void ExceptionUnwind()
{
// Nothing to do here.
LIMITED_METHOD_CONTRACT;
}
#endif
// Should be overridden to return TRUE if the frame contains register
// state of the caller.
virtual BOOL NeedsUpdateRegDisplay()
{
return FALSE;
}
//------------------------------------------------------------------------
// Is this a frame used on transition to native code from jitted code?
//------------------------------------------------------------------------
virtual BOOL IsTransitionToNativeFrame()
{
LIMITED_METHOD_CONTRACT;
return FALSE;
}
virtual MethodDesc *GetFunction()
{
LIMITED_METHOD_DAC_CONTRACT;
return NULL;
}
virtual Assembly *GetAssembly()
{
WRAPPER_NO_CONTRACT;
MethodDesc *pMethod = GetFunction();
if (pMethod != NULL)
return pMethod->GetModule()->GetAssembly();
else
return NULL;
}
// indicate the current X86 IP address within the current method
// return 0 if the information is not available
virtual PTR_BYTE GetIP()
{
LIMITED_METHOD_CONTRACT;
return NULL;
}
// DACCESS: GetReturnAddressPtr should return the
// target address of the return address in the frame.
virtual TADDR GetReturnAddressPtr()
{
LIMITED_METHOD_DAC_CONTRACT;
return NULL;
}
virtual PCODE GetReturnAddress()
{
WRAPPER_NO_CONTRACT;
TADDR ptr = GetReturnAddressPtr();
return (ptr != NULL) ? *PTR_PCODE(ptr) : NULL;
}
#ifndef DACCESS_COMPILE
virtual Object **GetReturnExecutionContextAddr()
{
LIMITED_METHOD_CONTRACT;
return NULL;
}
void SetReturnAddress(TADDR val)
{
WRAPPER_NO_CONTRACT;
TADDR ptr = GetReturnAddressPtr();
_ASSERTE(ptr != NULL);
*(TADDR*)ptr = val;
}
#endif // #ifndef DACCESS_COMPILE
PTR_GSCookie GetGSCookiePtr()
{
WRAPPER_NO_CONTRACT;
return dac_cast<PTR_GSCookie>(dac_cast<TADDR>(this) + GetOffsetOfGSCookie());
}
static int GetOffsetOfGSCookie()
{
LIMITED_METHOD_DAC_CONTRACT;
return -(int)sizeof(GSCookie);
}
static bool HasValidVTablePtr(Frame * pFrame);
static PTR_GSCookie SafeGetGSCookiePtr(Frame * pFrame);
static void Init();
// Callers, note that the REGDISPLAY parameter is actually in/out. While
// UpdateRegDisplay is generally used to fill out the REGDISPLAY parameter, some
// overrides (e.g., code:ResumableFrame::UpdateRegDisplay) will actually READ what
// you pass in. So be sure to pass in a valid or zeroed out REGDISPLAY.
virtual void UpdateRegDisplay(const PREGDISPLAY)
{
LIMITED_METHOD_DAC_CONTRACT;
return;
}
//------------------------------------------------------------------------
// Debugger support
//------------------------------------------------------------------------
public:
enum ETransitionType
{
TT_NONE,
TT_M2U, // we can safely cast to a FramedMethodFrame
TT_U2M, // we can safely cast to a UnmanagedToManagedFrame
TT_AppDomain, // transitioniting between AppDomains.
TT_InternalCall, // calling into the CLR (ecall/fcall).
};
// Get the type of transition.
// M-->U, U-->M
virtual ETransitionType GetTransitionType()
{
LIMITED_METHOD_DAC_CONTRACT;
return TT_NONE;
}
enum
{
TYPE_INTERNAL,
TYPE_ENTRY,
TYPE_EXIT,
TYPE_CONTEXT_CROSS,
TYPE_INTERCEPTION,
TYPE_SECURITY,
TYPE_CALL,
TYPE_FUNC_EVAL,
TYPE_MULTICAST,
// HMFs and derived classes should use this so the profiling API knows it needs
// to ensure HMF-specific lazy initialization gets done w/out re-entering to the host.
TYPE_HELPER_METHOD_FRAME,
TYPE_COUNT
};
virtual int GetFrameType()
{
LIMITED_METHOD_DAC_CONTRACT;
return TYPE_INTERNAL;
};
// When stepping into a method, various other methods may be called.
// These are refererred to as interceptors. They are all invoked
// with frames of various types. GetInterception() indicates whether
// the frame was set up for execution of such interceptors
enum Interception
{
INTERCEPTION_NONE,
INTERCEPTION_CLASS_INIT,
INTERCEPTION_EXCEPTION,
INTERCEPTION_CONTEXT,
INTERCEPTION_SECURITY,
INTERCEPTION_PRESTUB,
INTERCEPTION_OTHER,
INTERCEPTION_COUNT
};
virtual Interception GetInterception()
{
LIMITED_METHOD_DAC_CONTRACT;
return INTERCEPTION_NONE;
}
// Return information about an unmanaged call the frame
// will make.
// ip - the unmanaged routine which will be called
// returnIP - the address in the stub which the unmanaged routine
// will return to.
// returnSP - the location returnIP is pushed onto the stack
// during the call.
//
virtual void GetUnmanagedCallSite(TADDR* ip,
TADDR* returnIP,
TADDR* returnSP)
{
LIMITED_METHOD_CONTRACT;
if (ip)
*ip = NULL;
if (returnIP)
*returnIP = NULL;
if (returnSP)
*returnSP = NULL;
}
// Return where the frame will execute next - the result is filled
// into the given "trace" structure. The frame is responsible for
// detecting where it is in its execution lifetime.
virtual BOOL TraceFrame(Thread *thread, BOOL fromPatch,
TraceDestination *trace, REGDISPLAY *regs)
{
LIMITED_METHOD_CONTRACT;
LOG((LF_CORDB, LL_INFO10000,
"Default TraceFrame always returns false.\n"));
return FALSE;
}
#ifdef DACCESS_COMPILE
virtual void EnumMemoryRegions(CLRDataEnumMemoryFlags flags)
{
WRAPPER_NO_CONTRACT;
DAC_ENUM_VTHIS();
// Many frames store a MethodDesc pointer in m_Datum
// so pick that up automatically.
MethodDesc* func = GetFunction();
if (func)
{
func->EnumMemoryRegions(flags);
}
// Include the NegSpace
GSCookie * pGSCookie = GetGSCookiePtr();
_ASSERTE(FitsIn<ULONG32>(PBYTE(pGSCookie) - PBYTE(this)));
ULONG32 negSpaceSize = static_cast<ULONG32>(PBYTE(pGSCookie) - PBYTE(this));
DacEnumMemoryRegion(dac_cast<TADDR>(this) - negSpaceSize, negSpaceSize);
}
#endif
//---------------------------------------------------------------
// Expose key offsets and values for stub generation.
//---------------------------------------------------------------
static BYTE GetOffsetOfNextLink()
{
WRAPPER_NO_CONTRACT;
size_t ofs = offsetof(class Frame, m_Next);
_ASSERTE(FitsInI1(ofs));
return (BYTE)ofs;
}
// get your VTablePointer (can be used to check what type the frame is)
TADDR GetVTablePtr()
{
LIMITED_METHOD_DAC_CONTRACT;
return VPTR_HOST_VTABLE_TO_TADDR(*(LPVOID*)this);
}
#if defined(_DEBUG) && !defined(DACCESS_COMPILE)
virtual BOOL Protects(OBJECTREF *ppObjectRef)
{
LIMITED_METHOD_CONTRACT;
return FALSE;
}
#endif
#ifndef DACCESS_COMPILE
// Link and Unlink this frame
VOID Push();
VOID Pop();
VOID Push(Thread *pThread);
VOID Pop(Thread *pThread);
#endif // DACCESS_COMPILE
#ifdef _DEBUG_IMPL
void Log();
static BOOL ShouldLogTransitions() { WRAPPER_NO_CONTRACT; return LoggingOn(LF_STUBS, LL_INFO1000000); }
static void __stdcall LogTransition(Frame* frame);
void LogFrame(int LF, int LL); // General purpose logging.
void LogFrameChain(int LF, int LL); // Log the whole chain.
virtual const char* GetFrameTypeName() {return NULL;}
static PTR_CSTR GetFrameTypeName(TADDR vtbl);
#endif
//------------------------------------------------------------------------
// Returns the address of a security object or
// null if there is no space for an object on this frame.
//------------------------------------------------------------------------
virtual OBJECTREF *GetAddrOfSecurityDesc()
{
LIMITED_METHOD_CONTRACT;
return NULL;
}
private:
// Pointer to the next frame up the stack.
protected:
PTR_Frame m_Next; // offset +4
public:
PTR_Frame PtrNextFrame() { return m_Next; }
private:
// Because JIT-method activations cannot be expressed as Frames,
// everyone must use the StackCrawler to walk the frame chain
// reliably. We'll expose the Next method only to the StackCrawler
// to prevent mistakes.
/*<TODO>@NICE: Restrict "friendship" again to the StackWalker method;
not done because of circular dependency with threads.h</TODO>
*/
// friend Frame* Thread::StackWalkFrames(PSTACKWALKFRAMESCALLBACK pCallback, VOID *pData);
friend class Thread;
friend void CrawlFrame::GotoNextFrame();
friend class StackFrameIterator;
friend class TailCallFrame;
friend class AppDomain;
friend VOID RealCOMPlusThrow(OBJECTREF);
friend FCDECL0(VOID, JIT_StressGC);
#ifdef _DEBUG
friend LONG WINAPI CLRVectoredExceptionHandlerShim(PEXCEPTION_POINTERS pExceptionInfo);
#endif
#ifdef HOST_64BIT
friend Thread * __stdcall JIT_InitPInvokeFrame(InlinedCallFrame *pFrame, PTR_VOID StubSecretArg);
#endif
#ifdef FEATURE_EH_FUNCLETS
friend class ExceptionTracker;
#endif
#if defined(DACCESS_COMPILE)
friend class DacDbiInterfaceImpl;
#endif // DACCESS_COMPILE
PTR_Frame Next()
{
LIMITED_METHOD_DAC_CONTRACT;
return m_Next;
}
protected:
// Frame is considered an abstract class: this protected constructor
// causes any attempt to instantiate one to fail at compile-time.
Frame()
: m_Next(dac_cast<PTR_Frame>(nullptr))
{
LIMITED_METHOD_CONTRACT;
}
#if defined(TARGET_UNIX) && !defined(DACCESS_COMPILE)
virtual ~Frame() { LIMITED_METHOD_CONTRACT; }
void PopIfChained();
#endif // TARGET_UNIX && !DACCESS_COMPILE
};
//-----------------------------------------------------------------------------
// This frame provides context for a frame that
// took an exception that is going to be resumed.
//
// It is necessary to create this frame if garbage
// collection may happen during handling of the
// exception. The FRAME_ATTR_RESUMABLE flag tells
// the GC that the preceding frame needs to be treated
// like the top of stack (with the important implication that
// caller-save-regsiters will be potential roots).
//-----------------------------------------------------------------------------
#ifdef FEATURE_HIJACK
//-----------------------------------------------------------------------------
class ResumableFrame : public Frame
{
VPTR_VTABLE_CLASS(ResumableFrame, Frame)
public:
#ifndef DACCESS_COMPILE
ResumableFrame(T_CONTEXT* regs) {
LIMITED_METHOD_CONTRACT;
m_Regs = regs;
}
#endif
virtual TADDR GetReturnAddressPtr();
virtual BOOL NeedsUpdateRegDisplay()
{
return TRUE;
}
virtual void UpdateRegDisplay(const PREGDISPLAY pRD);
virtual unsigned GetFrameAttribs() {
LIMITED_METHOD_DAC_CONTRACT;
return FRAME_ATTR_RESUMABLE; // Treat the next frame as the top frame.
}
T_CONTEXT *GetContext() {
LIMITED_METHOD_DAC_CONTRACT;
return (m_Regs);
}
#ifdef DACCESS_COMPILE
virtual void EnumMemoryRegions(CLRDataEnumMemoryFlags flags)
{
WRAPPER_NO_CONTRACT;
Frame::EnumMemoryRegions(flags);
m_Regs.EnumMem();
}
#endif
protected:
PTR_CONTEXT m_Regs;
// Keep as last entry in class
DEFINE_VTABLE_GETTER_AND_CTOR_AND_DTOR(ResumableFrame)
};
//-----------------------------------------------------------------------------
// RedirectedThreadFrame
//-----------------------------------------------------------------------------
class RedirectedThreadFrame : public ResumableFrame
{
VPTR_VTABLE_CLASS(RedirectedThreadFrame, ResumableFrame)
VPTR_UNIQUE(VPTR_UNIQUE_RedirectedThreadFrame)
public:
#ifndef DACCESS_COMPILE
RedirectedThreadFrame(T_CONTEXT *regs) : ResumableFrame(regs) {
LIMITED_METHOD_CONTRACT;
}
virtual void ExceptionUnwind();
#endif
virtual void GcScanRoots(promote_func* fn, ScanContext* sc)
{
WRAPPER_NO_CONTRACT;
#if defined(FEATURE_CONSERVATIVE_GC) && !defined(DACCESS_COMPILE)
if (sc->promotion && g_pConfig->GetGCConservative())
{
#ifdef TARGET_AMD64
Object** firstIntReg = (Object**)&this->GetContext()->Rax;
Object** lastIntReg = (Object**)&this->GetContext()->R15;
#elif defined(TARGET_X86)
Object** firstIntReg = (Object**)&this->GetContext()->Edi;
Object** lastIntReg = (Object**)&this->GetContext()->Ebp;
#elif defined(TARGET_ARM)
Object** firstIntReg = (Object**)&this->GetContext()->R0;
Object** lastIntReg = (Object**)&this->GetContext()->R12;
#elif defined(TARGET_ARM64)
Object** firstIntReg = (Object**)&this->GetContext()->X0;
Object** lastIntReg = (Object**)&this->GetContext()->X28;
#else
_ASSERTE(!"nyi for platform");
#endif
for (Object** ppObj = firstIntReg; ppObj <= lastIntReg; ppObj++)
{
fn(ppObj, sc, GC_CALL_INTERIOR | GC_CALL_PINNED);
}
}
#endif
}
// Keep as last entry in class
DEFINE_VTABLE_GETTER_AND_CTOR_AND_DTOR(RedirectedThreadFrame)
};
typedef DPTR(RedirectedThreadFrame) PTR_RedirectedThreadFrame;
inline BOOL ISREDIRECTEDTHREAD(Thread * thread)
{
WRAPPER_NO_CONTRACT;
return (thread->GetFrame() != FRAME_TOP &&
thread->GetFrame()->GetVTablePtr() ==
RedirectedThreadFrame::GetMethodFrameVPtr());
}
inline T_CONTEXT * GETREDIRECTEDCONTEXT(Thread * thread)
{
WRAPPER_NO_CONTRACT;
_ASSERTE(ISREDIRECTEDTHREAD(thread));
return dac_cast<PTR_RedirectedThreadFrame>(thread->GetFrame())->GetContext();
}
//------------------------------------------------------------------------
#else // FEATURE_HIJACK
//------------------------------------------------------------------------
inline BOOL ISREDIRECTEDTHREAD(Thread * thread) { LIMITED_METHOD_CONTRACT; return FALSE; }
inline CONTEXT * GETREDIRECTEDCONTEXT(Thread * thread) { LIMITED_METHOD_CONTRACT; return (CONTEXT*) NULL; }
//------------------------------------------------------------------------
#endif // FEATURE_HIJACK
//------------------------------------------------------------------------
// This frame represents a transition from one or more nested frameless
// method calls to either a EE runtime helper function or a framed method.
// Because most stackwalks from the EE start with a full-fledged frame,
// anything but the most trivial call into the EE has to push this
// frame in order to prevent the frameless methods inbetween from
// getting lost.
//------------------------------------------------------------------------
class TransitionFrame : public Frame
{
VPTR_ABSTRACT_VTABLE_CLASS(TransitionFrame, Frame)
public:
virtual TADDR GetTransitionBlock() = 0;
// DACCESS: GetReturnAddressPtr should return the
// target address of the return address in the frame.
virtual TADDR GetReturnAddressPtr()
{
LIMITED_METHOD_DAC_CONTRACT;
return GetTransitionBlock() + TransitionBlock::GetOffsetOfReturnAddress();
}
//---------------------------------------------------------------
// Get the "this" object.
//---------------------------------------------------------------
OBJECTREF GetThis()
{
WRAPPER_NO_CONTRACT;
Object* obj = PTR_Object(*PTR_TADDR(GetAddrOfThis()));
return ObjectToOBJECTREF(obj);
}
PTR_OBJECTREF GetThisPtr()
{
WRAPPER_NO_CONTRACT;
return PTR_OBJECTREF(GetAddrOfThis());
}
//---------------------------------------------------------------
// Get the extra info for shared generic code.
//---------------------------------------------------------------
PTR_VOID GetParamTypeArg();
//---------------------------------------------------------------
// Gets value indicating whether the generic parameter type
// argument should be supressed.
//---------------------------------------------------------------
virtual BOOL SuppressParamTypeArg()
{
return FALSE;
}
protected: // we don't want people using this directly
//---------------------------------------------------------------
// Get the address of the "this" object. WARNING!!! Whether or not "this"
// is gc-protected is depends on the frame type!!!
//---------------------------------------------------------------
TADDR GetAddrOfThis();
public:
//---------------------------------------------------------------
// For vararg calls, return cookie.
//---------------------------------------------------------------
VASigCookie *GetVASigCookie();
CalleeSavedRegisters *GetCalleeSavedRegisters()
{
LIMITED_METHOD_DAC_CONTRACT;
return dac_cast<PTR_CalleeSavedRegisters>(
GetTransitionBlock() + TransitionBlock::GetOffsetOfCalleeSavedRegisters());
}
ArgumentRegisters *GetArgumentRegisters()
{
LIMITED_METHOD_DAC_CONTRACT;
return dac_cast<PTR_ArgumentRegisters>(
GetTransitionBlock() + TransitionBlock::GetOffsetOfArgumentRegisters());
}
TADDR GetSP()
{
LIMITED_METHOD_DAC_CONTRACT;
return GetTransitionBlock() + sizeof(TransitionBlock);
}
virtual BOOL NeedsUpdateRegDisplay()
{
return TRUE;
}
virtual void UpdateRegDisplay(const PREGDISPLAY);
#ifdef TARGET_X86
void UpdateRegDisplayHelper(const PREGDISPLAY, UINT cbStackPop);
#endif