1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 
5 #pragma once
6 
7 #if defined(_TARGET_AMD64_) || defined(_TARGET_X86_)
8 struct T_RUNTIME_FUNCTION {
9     uint32_t BeginAddress;
10     uint32_t EndAddress;
11     uint32_t UnwindInfoAddress;
12 };
13 #elif defined(_TARGET_ARM_)
14 struct T_RUNTIME_FUNCTION {
15     uint32_t BeginAddress;
16     uint32_t UnwindData;
17 };
18 #elif defined(_TARGET_ARM64_)
19 struct T_RUNTIME_FUNCTION {
20     uint32_t BeginAddress;
21     union {
22         uint32_t UnwindData;
23         struct {
24             uint32_t Flag : 2;
25             uint32_t FunctionLength : 11;
26             uint32_t RegF : 3;
27             uint32_t RegI : 4;
28             uint32_t H : 1;
29             uint32_t CR : 2;
30             uint32_t FrameSize : 9;
31         } PackedUnwindData;
32     };
33 };
34 #else
35 #error unexpected target architecture
36 #endif
37 
38 typedef DPTR(T_RUNTIME_FUNCTION) PTR_RUNTIME_FUNCTION;
39 
40 class CoffNativeCodeManager : public ICodeManager
41 {
42     TADDR m_moduleBase;
43     PTR_RUNTIME_FUNCTION m_pRuntimeFunctionTable;
44     UInt32 m_nRuntimeFunctionTable;
45 
46     PTR_PTR_VOID m_pClasslibFunctions;
47     UInt32 m_nClasslibFunctions;
48 
49 public:
50     CoffNativeCodeManager(TADDR moduleBase,
51                           PTR_RUNTIME_FUNCTION pRuntimeFunctionTable, UInt32 nRuntimeFunctionTable,
52                           PTR_PTR_VOID pClasslibFunctions, UInt32 nClasslibFunctions);
53     ~CoffNativeCodeManager();
54 
55     //
56     // Code manager methods
57     //
58 
59     bool FindMethodInfo(PTR_VOID        ControlPC,
60                         MethodInfo *    pMethodInfoOut);
61 
62     bool IsFunclet(MethodInfo * pMethodInfo);
63 
64     bool IsFilter(MethodInfo * pMethodInfo);
65 
66     PTR_VOID GetFramePointer(MethodInfo *   pMethodInfo,
67                              REGDISPLAY *   pRegisterSet);
68 
69     void EnumGcRefs(MethodInfo *    pMethodInfo,
70                     PTR_VOID        safePointAddress,
71                     REGDISPLAY *    pRegisterSet,
72                     GCEnumContext * hCallback);
73 
74     bool UnwindStackFrame(MethodInfo *    pMethodInfo,
75                           REGDISPLAY *    pRegisterSet,                 // in/out
76                           PTR_VOID *      ppPreviousTransitionFrame);   // out
77 
78     UIntNative GetConservativeUpperBoundForOutgoingArgs(MethodInfo *   pMethodInfo,
79                                                         REGDISPLAY *   pRegisterSet);
80 
81     bool GetReturnAddressHijackInfo(MethodInfo *    pMethodInfo,
82                                     REGDISPLAY *    pRegisterSet,       // in
83                                     PTR_PTR_VOID *  ppvRetAddrLocation, // out
84                                     GCRefKind *     pRetValueKind);     // out
85 
86     void UnsynchronizedHijackMethodLoops(MethodInfo * pMethodInfo);
87 
88     PTR_VOID RemapHardwareFaultToGCSafePoint(MethodInfo * pMethodInfo, PTR_VOID controlPC);
89 
90     bool EHEnumInit(MethodInfo * pMethodInfo, PTR_VOID * pMethodStartAddress, EHEnumState * pEHEnumState);
91 
92     bool EHEnumNext(EHEnumState * pEHEnumState, EHClause * pEHClause);
93 
94     PTR_VOID GetMethodStartAddress(MethodInfo * pMethodInfo);
95 
96     void * GetClasslibFunction(ClasslibFunctionId functionId);
97 
98     PTR_VOID GetAssociatedData(PTR_VOID ControlPC);
99 
100     PTR_VOID GetOsModuleHandle();
101 };
102