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// StubLink.inl
6//
7// Defines inline functions for StubLinker
8//
9
10
11#ifndef __STUBLINK_INL__
12#define __STUBLINK_INL__
13
14#include "stublink.h"
15#include "eeconfig.h"
16#include "safemath.h"
17
18
19#ifdef STUBLINKER_GENERATES_UNWIND_INFO
20
21inline //static
22SIZE_T StubUnwindInfoHeader::ComputeSize(UINT nUnwindInfoSize)
23{
24 LIMITED_METHOD_CONTRACT;
25
26 return ALIGN_UP( FIELD_OFFSET(StubUnwindInfoHeader, FunctionEntry)
27 + nUnwindInfoSize
28 + sizeof(StubUnwindInfoHeaderSuffix)
29 , sizeof(void*));
30}
31
32
33#ifndef DACCESS_COMPILE
34
35inline
36void StubUnwindInfoHeader::Init ()
37{
38 LIMITED_METHOD_CONTRACT;
39
40 pNext = (StubUnwindInfoHeader*)(SIZE_T)1;
41}
42
43
44inline
45bool StubUnwindInfoHeader::IsRegistered ()
46{
47 LIMITED_METHOD_CONTRACT;
48
49 return pNext != (StubUnwindInfoHeader*)(SIZE_T)1;
50}
51
52#endif // #ifndef DACCESS_COMPILE
53
54#endif // STUBLINKER_GENERATES_UNWIND_INFO
55
56
57inline
58void StubLinker::Push(UINT size)
59{
60 LIMITED_METHOD_CONTRACT;
61
62 ClrSafeInt<SHORT> stackSize(m_stackSize);
63 _ASSERTE(FitsIn<SHORT>(size));
64 SHORT sSize = static_cast<SHORT>(size);
65 stackSize += sSize;
66 _ASSERTE(!stackSize.IsOverflow());
67 m_stackSize = stackSize.Value();
68 UnwindAllocStack(sSize);
69}
70
71
72inline
73void StubLinker::Pop(UINT size)
74{
75 LIMITED_METHOD_CONTRACT;
76
77 ClrSafeInt<SHORT> stackSize(m_stackSize);
78 _ASSERTE(FitsIn<SHORT>(size));
79 stackSize = stackSize - ClrSafeInt<SHORT>(size);
80 _ASSERTE(!stackSize.IsOverflow());
81 m_stackSize = stackSize.Value();
82}
83
84
85inline
86VOID StubLinker::EmitUnwindInfoCheck()
87{
88#if defined(_DEBUG) && defined(STUBLINKER_GENERATES_UNWIND_INFO) && !defined(CROSSGEN_COMPILE)
89 if (g_pConfig->IsStubLinkerUnwindInfoVerificationOn())
90 {
91 if (!m_pUnwindInfoCheckLabel)
92 m_pUnwindInfoCheckLabel = NewCodeLabel();
93 EmitUnwindInfoCheckWorker(m_pUnwindInfoCheckLabel);
94 }
95#endif
96}
97
98
99#ifndef STUBLINKER_GENERATES_UNWIND_INFO
100
101inline VOID StubLinker::UnwindSavedReg (UCHAR reg, ULONG SPRelativeOffset) {LIMITED_METHOD_CONTRACT;}
102inline VOID StubLinker::UnwindAllocStack (SHORT FrameSizeIncrement) {LIMITED_METHOD_CONTRACT;}
103inline VOID StubLinker::UnwindSetFramePointer (UCHAR reg) {LIMITED_METHOD_CONTRACT;}
104
105inline VOID StubLinker::UnwindPushedReg (UCHAR reg)
106{
107 LIMITED_METHOD_CONTRACT;
108
109 m_stackSize += sizeof(void*);
110}
111
112#endif // !STUBLINKER_GENERATES_UNWIND_INFO
113
114
115#endif // !__STUBLINK_INL__
116
117