summaryrefslogtreecommitdiff
path: root/packaging/0005-Allow-RelativePointer-SetValue-usage-for-non-DAC-bui.patch
blob: d7e7b7ecf721f5ab321a15f23572d4a8f5b478fc (plain)
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
From fae13b76411ba059de27f68d56b09397bbc81b37 Mon Sep 17 00:00:00 2001
From: gbalykov <g.balykov@samsung.com>
Date: Thu, 25 May 2017 01:50:26 +0300
Subject: [PATCH 05/32] Allow RelativePointer::SetValue usage for non-DAC
 builds only (#11891)

---
 src/inc/fixuppointer.h | 76 +++++++++++---------------------------------------
 src/vm/ceeload.cpp     |  5 +++-
 src/vm/ceeload.h       |  5 ++++
 src/vm/ceeload.inl     |  6 ++--
 src/vm/class.h         |  4 +--
 src/vm/classhash.cpp   |  7 +++--
 src/vm/method.cpp      |  5 +++-
 src/vm/method.hpp      |  2 +-
 src/vm/methodtable.h   | 11 +++++---
 9 files changed, 48 insertions(+), 73 deletions(-)

diff --git a/src/inc/fixuppointer.h b/src/inc/fixuppointer.h
index 3467cfe..549023a 100644
--- a/src/inc/fixuppointer.h
+++ b/src/inc/fixuppointer.h
@@ -23,9 +23,9 @@
 // There are several flavors of conversions from/to RelativePointer:
 //  - GetValue/SetValue: The most common version. Assumes that the pointer is not NULL.
 //  - GetValueMaybeNull/SetValueMaybeNull: Pointer can be NULL.
-//  - GetValueAtPtr/SetValueAtPtr: Static version of GetValue/SetValue. It is 
+//  - GetValueAtPtr: Static version of GetValue. It is
 //    meant to simplify access to arrays of RelativePointers.
-//  - GetValueMaybeNullAtPtr/SetValueMaybeNullAtPtr
+//  - GetValueMaybeNullAtPtr
 template<typename PTR_TYPE>
 class RelativePointer
 {
@@ -112,55 +112,33 @@ public:
         return dac_cast<DPTR(RelativePointer<PTR_TYPE>)>(base)->GetValueMaybeNull(base);
     }
 
-    // Set encoded value of the pointer. Assumes that the value is not NULL.
-    void SetValue(TADDR base, PTR_TYPE addr)
-    {
-        LIMITED_METHOD_CONTRACT;
-        PRECONDITION(addr != NULL);
-        m_delta = dac_cast<TADDR>(addr) - base;
-    }
-
 #ifndef DACCESS_COMPILE
     // Set encoded value of the pointer. Assumes that the value is not NULL.
-    // Does not need explicit base and thus can be used in non-DAC builds only.
     FORCEINLINE void SetValue(PTR_TYPE addr)
     {
         LIMITED_METHOD_CONTRACT;
-        return SetValue((TADDR)this, addr);
-    }
-#endif
-
-    // Static version of SetValue. It is meant to simplify access to arrays of pointers.
-    FORCEINLINE static void SetValueAtPtr(TADDR base, PTR_TYPE addr)
-    {
-        LIMITED_METHOD_CONTRACT;
-        dac_cast<DPTR(RelativePointer<PTR_TYPE>)>(base)->SetValue(base, addr);
+        PRECONDITION(addr != NULL);
+        m_delta = (TADDR)addr - (TADDR)this;
     }
 
     // Set encoded value of the pointer. The value can be NULL.
     void SetValueMaybeNull(TADDR base, PTR_TYPE addr)
     {
         LIMITED_METHOD_CONTRACT;
-        if (addr == NULL) m_delta = NULL; else SetValue(base, addr);
+        if (addr == NULL)
+            m_delta = NULL;
+        else
+            m_delta = (TADDR)addr - (TADDR)base;
     }
 
-#ifndef DACCESS_COMPILE
     // Set encoded value of the pointer. The value can be NULL.
-    // Does not need explicit base and thus can be used in non-DAC builds only.
     FORCEINLINE void SetValueMaybeNull(PTR_TYPE addr)
     {
         LIMITED_METHOD_CONTRACT;
-        return SetValueMaybeNull((TADDR)this, addr);
+        SetValueMaybeNull((TADDR)this, addr);
     }
 #endif
 
-    // Static version of SetValueMaybeNull. It is meant to simplify access to arrays of pointers.
-    FORCEINLINE static void SetValueMaybeNullAtPtr(TADDR base, PTR_TYPE addr)
-    {
-        LIMITED_METHOD_CONTRACT;
-        dac_cast<DPTR(RelativePointer<PTR_TYPE>)>(base)->SetValueMaybeNull(base, addr);
-    }
-
 #ifndef DACCESS_COMPILE
     void BitwiseCopyTo(RelativePointer<PTR_TYPE> &dest) const
     {
@@ -347,55 +325,33 @@ public:
         return dac_cast<DPTR(RelativeFixupPointer<PTR_TYPE>)>(base)->GetValueMaybeNull(base);
     }
 
-    // Set encoded value of the pointer. Assumes that the value is not NULL.
-    void SetValue(TADDR base, PTR_TYPE addr)
-    {
-        LIMITED_METHOD_CONTRACT;
-        PRECONDITION(addr != NULL);
-        m_delta = dac_cast<TADDR>(addr) - base;
-    }
-
 #ifndef DACCESS_COMPILE
     // Set encoded value of the pointer. Assumes that the value is not NULL.
-    // Does not need explicit base and thus can be used in non-DAC builds only.
     FORCEINLINE void SetValue(PTR_TYPE addr)
     {
         LIMITED_METHOD_CONTRACT;
-        return SetValue((TADDR)this, addr);
-    }
-#endif
-
-    // Static version of SetValue. It is meant to simplify access to arrays of pointers.
-    FORCEINLINE static void SetValueAtPtr(TADDR base, PTR_TYPE addr)
-    {
-        LIMITED_METHOD_CONTRACT;
-        dac_cast<DPTR(RelativeFixupPointer<PTR_TYPE>)>(base)->SetValue(base, addr);
+        PRECONDITION(addr != NULL);
+        m_delta = (TADDR)addr - (TADDR)this;
     }
 
     // Set encoded value of the pointer. The value can be NULL.
     void SetValueMaybeNull(TADDR base, PTR_TYPE addr)
     {
         LIMITED_METHOD_CONTRACT;
-        if (addr == NULL) m_delta = NULL; else SetValue(base, addr);
+        if (addr == NULL)
+            m_delta = NULL;
+        else
+            m_delta = (TADDR)addr - (TADDR)base;
     }
 
-#ifndef DACCESS_COMPILE
     // Set encoded value of the pointer. The value can be NULL.
-    // Does not need explicit base and thus can be used in non-DAC builds only.
     FORCEINLINE void SetValueMaybeNull(PTR_TYPE addr)
     {
         LIMITED_METHOD_CONTRACT;
-        return SetValueMaybeNull((TADDR)this, addr);
+        SetValueMaybeNull((TADDR)this, addr);
     }
 #endif
 
-    // Static version of SetValueMaybeNull. It is meant to simplify access to arrays of pointers.
-    FORCEINLINE static void SetValueMaybeNullAtPtr(TADDR base, PTR_TYPE addr)
-    {
-        LIMITED_METHOD_CONTRACT;
-        dac_cast<DPTR(RelativeFixupPointer<PTR_TYPE>)>(base)->SetValueMaybeNull(base, addr);
-    }
-
     // Returns the pointer to the indirection cell.
     PTR_TYPE * GetValuePtr(TADDR base) const
     {
diff --git a/src/vm/ceeload.cpp b/src/vm/ceeload.cpp
index 6a1eb62..f995343 100644
--- a/src/vm/ceeload.cpp
+++ b/src/vm/ceeload.cpp
@@ -13708,7 +13708,10 @@ void LookupMapBase::CreateHotItemList(DataImage *image, CorProfileData *profileD
                 for (DWORD ii = 0; ii < numItems; ii++)
                 {
                     if (itemList[ii].value != NULL)
-                        RelativePointer<TADDR>::SetValueMaybeNullAtPtr(dac_cast<TADDR>(&itemList[ii].value), itemList[ii].value);
+                    {
+                        RelativePointer<TADDR> *pRelPtr = (RelativePointer<TADDR> *)&itemList[ii].value;
+                        pRelPtr->SetValueMaybeNull(itemList[ii].value);
+                    }
                 }
 
                 if (itemList != NULL)
diff --git a/src/vm/ceeload.h b/src/vm/ceeload.h
index 2f3fe90..dc21eec 100644
--- a/src/vm/ceeload.h
+++ b/src/vm/ceeload.h
@@ -311,7 +311,10 @@ template <typename TYPE>
 struct LookupMap : LookupMapBase
 {
     static TYPE GetValueAt(PTR_TADDR pValue, TADDR* pFlags, TADDR supportedFlags);
+
+#ifndef DACCESS_COMPILE
     static void SetValueAt(PTR_TADDR pValue, TYPE value, TADDR flags);
+#endif // DACCESS_COMPILE
 
     TYPE GetElement(DWORD rid, TADDR* pFlags);
     void SetElement(DWORD rid, TYPE value, TADDR flags);
@@ -368,6 +371,7 @@ public:
         SetElement(rid, value, flags);
     }
 
+#ifndef DACCESS_COMPILE
     void AddFlag(DWORD rid, TADDR flag)
     {
         WRAPPER_NO_CONTRACT;
@@ -388,6 +392,7 @@ public:
         TYPE existingValue = GetValueAt(pElement, &existingFlags, supportedFlags);
         SetValueAt(pElement, existingValue, existingFlags | flag);
     }
+#endif // DACCESS_COMPILE
 
     //
     // Try to store an association in a map. Will never throw or fail.
diff --git a/src/vm/ceeload.inl b/src/vm/ceeload.inl
index 9184a74..8226dce 100644
--- a/src/vm/ceeload.inl
+++ b/src/vm/ceeload.inl
@@ -26,6 +26,8 @@ TYPE LookupMap<TYPE>::GetValueAt(PTR_TADDR pValue, TADDR* pFlags, TADDR supporte
     return (TYPE)(dac_cast<TADDR>(value) & ~supportedFlags);
 }
 
+#ifndef DACCESS_COMPILE
+
 template<typename TYPE>
 inline 
 void LookupMap<TYPE>::SetValueAt(PTR_TADDR pValue, TYPE value, TADDR flags)
@@ -34,10 +36,10 @@ void LookupMap<TYPE>::SetValueAt(PTR_TADDR pValue, TYPE value, TADDR flags)
 
     value = (TYPE)(dac_cast<TADDR>(value) | flags);
 
-    RelativePointer<TYPE>::SetValueAtPtr(dac_cast<TADDR>(pValue), value);
+    RelativePointer<TYPE> *pRelPtr = (RelativePointer<TYPE> *)pValue;
+    pRelPtr->SetValue(value);
 }
 
-#ifndef DACCESS_COMPILE
 //
 // Specialization of Get/SetValueAt methods to support maps of pointer-sized value types
 //
diff --git a/src/vm/class.h b/src/vm/class.h
index e3ec0ba..6358624 100644
--- a/src/vm/class.h
+++ b/src/vm/class.h
@@ -1265,7 +1265,7 @@ public:
     inline void SetFieldDescList (FieldDesc* pFieldDescList)
     {
         LIMITED_METHOD_CONTRACT;
-        m_pFieldDescList.SetValue(PTR_HOST_MEMBER_TADDR(EEClass, this, m_pFieldDescList), pFieldDescList);
+        m_pFieldDescList.SetValue(pFieldDescList);
     }
 #endif // !DACCESS_COMPILE
 
@@ -1700,7 +1700,7 @@ public:
     inline void SetChunks (MethodDescChunk* pChunks)
     {
         LIMITED_METHOD_CONTRACT;
-        m_pChunks.SetValueMaybeNull(PTR_HOST_MEMBER_TADDR(EEClass, this, m_pChunks), pChunks);
+        m_pChunks.SetValueMaybeNull(pChunks);
     }
 #endif // !DACCESS_COMPILE
     void AddChunk (MethodDescChunk* pNewChunk);
diff --git a/src/vm/classhash.cpp b/src/vm/classhash.cpp
index 408a6e8..2ffc612 100644
--- a/src/vm/classhash.cpp
+++ b/src/vm/classhash.cpp
@@ -47,7 +47,7 @@ PTR_VOID EEClassHashEntry::GetData()
 }
 
 #ifndef DACCESS_COMPILE
-void EEClassHashEntry::SetData(PTR_VOID data)
+void EEClassHashEntry::SetData(void *data)
 {
     CONTRACTL
     {
@@ -60,7 +60,10 @@ void EEClassHashEntry::SetData(PTR_VOID data)
     // TypeHandles are encoded as a relative pointer rather than a regular pointer to avoid the need for image
     // fixups (any TypeHandles in this hash are defined in the same module).
     if (((TADDR)data & EECLASSHASH_TYPEHANDLE_DISCR) == 0)
-        RelativePointer<PTR_VOID>::SetValueMaybeNullAtPtr((TADDR)&m_Data, data);
+    {
+        RelativePointer<void *> *pRelPtr = (RelativePointer<void *> *) &m_Data;
+        pRelPtr->SetValueMaybeNull(data);
+    }
     else
         m_Data = data;
 }
diff --git a/src/vm/method.cpp b/src/vm/method.cpp
index 34ae6d9..751ceac 100644
--- a/src/vm/method.cpp
+++ b/src/vm/method.cpp
@@ -2493,7 +2493,10 @@ void MethodDesc::Reset()
     }
 
     if (HasNativeCodeSlot())
-        NativeCodeSlot::SetValueMaybeNullAtPtr(GetAddrOfNativeCodeSlot(), NULL);
+    {
+        RelativePointer<TADDR> *pRelPtr = (RelativePointer<TADDR> *)GetAddrOfNativeCodeSlot();
+        pRelPtr->SetValueMaybeNull(NULL);
+    }
     _ASSERTE(!HasNativeCode());
 }
 
diff --git a/src/vm/method.hpp b/src/vm/method.hpp
index 3354e57..4ef6db0 100644
--- a/src/vm/method.hpp
+++ b/src/vm/method.hpp
@@ -2063,7 +2063,7 @@ public:
         LIMITED_METHOD_CONTRACT;
         _ASSERTE(m_methodTable.IsNull());
         _ASSERTE(pMT != NULL);
-        m_methodTable.SetValue(PTR_HOST_MEMBER_TADDR(MethodDescChunk, this, m_methodTable), pMT);
+        m_methodTable.SetValue(pMT);
     }
 
     inline void SetSizeAndCount(ULONG sizeOfMethodDescs, COUNT_T methodDescCount)
diff --git a/src/vm/methodtable.h b/src/vm/methodtable.h
index 2ce9f2a..93a9ae2 100644
--- a/src/vm/methodtable.h
+++ b/src/vm/methodtable.h
@@ -1671,12 +1671,13 @@ public:
     }
 
 #ifndef DACCESS_COMPILE
-    inline void SetNonVirtualSlotsArray(PTR_PCODE slots)
+    inline void SetNonVirtualSlotsArray(PCODE *slots)
     {
         LIMITED_METHOD_CONTRACT;
         _ASSERTE(HasNonVirtualSlotsArray());
-        
-        RelativePointer<PTR_PCODE>::SetValueAtPtr(GetNonVirtualSlotsPtr(), slots);
+
+        RelativePointer<PCODE *> *pRelPtr = (RelativePointer<PCODE *> *)GetNonVirtualSlotsPtr();
+        pRelPtr->SetValue(slots);
     }
 
     inline void SetHasSingleNonVirtualSlot()
@@ -2456,7 +2457,9 @@ public:
         _ASSERTE(HasDispatchMapSlot());
 
         TADDR pSlot = GetMultipurposeSlotPtr(enum_flag_HasDispatchMapSlot, c_DispatchMapSlotOffsets);
-        RelativePointer<PTR_DispatchMap>::SetValueAtPtr(pSlot, pDispatchMap);
+
+        RelativePointer<DispatchMap *> *pRelPtr = (RelativePointer<DispatchMap *> *)pSlot;
+        pRelPtr->SetValue(pDispatchMap);
     }
 #endif // !DACCESS_COMPILE
 
-- 
2.7.4