summaryrefslogtreecommitdiff
path: root/packaging/0021-Additional-fixes-for-RelativePointer-FixupPointer-Re.patch
blob: d3599f03e766286ae9b555b8b1433b5779d7c875 (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
From 7f7ddcef2af73ce4993120778d9333da9620d81c Mon Sep 17 00:00:00 2001
From: Gleb Balykov <g.balykov@samsung.com>
Date: Thu, 22 Jun 2017 19:28:32 +0300
Subject: [PATCH 21/32] Additional fixes for RelativePointer, FixupPointer,
 RelativeFixupPointer, PlainPointer

---
 src/inc/fixuppointer.h | 155 ++++++++++++++++++++++++++++++++++++++++++-------
 src/vm/ceeload.cpp     |  12 ++--
 src/vm/debughelp.cpp   |   2 +-
 3 files changed, 142 insertions(+), 27 deletions(-)

diff --git a/src/inc/fixuppointer.h b/src/inc/fixuppointer.h
index 20eb9d8..a711418 100644
--- a/src/inc/fixuppointer.h
+++ b/src/inc/fixuppointer.h
@@ -214,15 +214,38 @@ public:
         return dac_cast<PTR_TYPE>(addr);
     }
 
+    // Returns value of the encoded pointer.
+    FORCEINLINE PTR_TYPE GetValueMaybeNull() const
+    {
+        LIMITED_METHOD_DAC_CONTRACT;
+        return GetValue();
+    }
+
+#ifndef DACCESS_COMPILE
     // Returns the pointer to the indirection cell.
     PTR_TYPE * GetValuePtr() const
     {
-        LIMITED_METHOD_DAC_CONTRACT;
+        LIMITED_METHOD_CONTRACT;
         TADDR addr = m_addr;
         if ((addr & FIXUP_POINTER_INDIRECTION) != 0)
-            return dac_cast<DPTR(PTR_TYPE)>(addr - FIXUP_POINTER_INDIRECTION);
+            return (PTR_TYPE *)(addr - FIXUP_POINTER_INDIRECTION);
         return (PTR_TYPE *)&m_addr;
     }
+#endif // !DACCESS_COMPILE
+
+    // Static version of GetValue. It is meant to simplify access to arrays of pointers.
+    FORCEINLINE static PTR_TYPE GetValueAtPtr(TADDR base)
+    {
+        LIMITED_METHOD_DAC_CONTRACT;
+        return dac_cast<DPTR(FixupPointer<PTR_TYPE>)>(base)->GetValue();
+    }
+
+    // Static version of GetValueMaybeNull. It is meant to simplify access to arrays of pointers.
+    FORCEINLINE static PTR_TYPE GetValueMaybeNullAtPtr(TADDR base)
+    {
+        LIMITED_METHOD_DAC_CONTRACT;
+        return dac_cast<DPTR(FixupPointer<PTR_TYPE>)>(base)->GetValueMaybeNull();
+    }
 
     // Returns value of the encoded pointer.
     // Allows the value to be tagged.
@@ -235,12 +258,20 @@ public:
         return addr;
     }
 
+#ifndef DACCESS_COMPILE
     void SetValue(PTR_TYPE addr)
     {
         LIMITED_METHOD_CONTRACT;
         m_addr = dac_cast<TADDR>(addr);
     }
 
+    void SetValueMaybeNull(PTR_TYPE addr)
+    {
+        LIMITED_METHOD_CONTRACT;
+        SetValue(addr);
+    }
+#endif // !DACCESS_COMPILE
+
 private:
     TADDR m_addr;
 };
@@ -270,9 +301,6 @@ public:
     RelativeFixupPointer<PTR_TYPE>& operator = (const RelativeFixupPointer<PTR_TYPE> &) =delete;
     RelativeFixupPointer<PTR_TYPE>& operator = (RelativeFixupPointer<PTR_TYPE> &&) =delete;
 
-    // Default constructor
-    RelativeFixupPointer<PTR_TYPE>() {}
-
     // Returns whether the encoded pointer is NULL.
     BOOL IsNull() const
     {
@@ -292,11 +320,12 @@ public:
     }
 
 #ifndef DACCESS_COMPILE
+    // Returns whether the indirection cell contain fixup that has not been converted to real pointer yet.
+    // Does not need explicit base and thus can be used in non-DAC builds only.
     FORCEINLINE BOOL IsTagged() const
     {
         LIMITED_METHOD_CONTRACT;
-        TADDR base = (TADDR) this;
-        return IsTagged(base);
+        return IsTagged((TADDR)this);
     }
 #endif // !DACCESS_COMPILE
 
@@ -391,21 +420,14 @@ public:
     }
 #endif
 
-    // Returns the pointer to the indirection cell.
-    PTR_TYPE * GetValuePtr(TADDR base) const
-    {
-        LIMITED_METHOD_CONTRACT;
-        TADDR addr = base + m_delta;
-        _ASSERTE((addr & FIXUP_POINTER_INDIRECTION) != 0);
-        return dac_cast<DPTR(PTR_TYPE)>(addr - FIXUP_POINTER_INDIRECTION);
-    }
-
 #ifndef DACCESS_COMPILE
+    // Returns the pointer to the indirection cell.
     PTR_TYPE * GetValuePtr() const
     {
         LIMITED_METHOD_CONTRACT;
-        TADDR base = (TADDR) this;
-        return GetValuePtr(base);
+        TADDR addr = ((TADDR)this) + m_delta;
+        _ASSERTE((addr & FIXUP_POINTER_INDIRECTION) != 0);
+        return (PTR_TYPE *)(addr - FIXUP_POINTER_INDIRECTION);
     }
 #endif // !DACCESS_COMPILE
 
@@ -421,6 +443,48 @@ public:
         return addr;
     }
 
+    // Returns whether pointer is indirect. Assumes that the value is not NULL.
+    bool IsIndirectPtr(TADDR base) const
+    {
+        LIMITED_METHOD_DAC_CONTRACT;
+        PRECONDITION(!IsNull());
+
+        TADDR addr = base + m_delta;
+
+        return (addr & FIXUP_POINTER_INDIRECTION) != 0;
+    }
+
+#ifndef DACCESS_COMPILE
+    // Returns whether pointer is indirect. Assumes that the value is not NULL.
+    // Does not need explicit base and thus can be used in non-DAC builds only.
+    bool IsIndirectPtr() const
+    {
+        LIMITED_METHOD_CONTRACT;
+        return IsIndirectPtr((TADDR)this);
+    }
+#endif
+
+    // Returns whether pointer is indirect. The value can be NULL.
+    bool IsIndirectPtrMaybeNull(TADDR base) const
+    {
+        LIMITED_METHOD_DAC_CONTRACT;
+
+        if (m_delta == 0)
+            return false;
+
+        return IsIndirectPtr(base);
+    }
+
+#ifndef DACCESS_COMPILE
+    // Returns whether pointer is indirect. The value can be NULL.
+    // Does not need explicit base and thus can be used in non-DAC builds only.
+    bool IsIndirectPtrMaybeNull() const
+    {
+        LIMITED_METHOD_CONTRACT;
+        return IsIndirectPtrMaybeNull((TADDR)this);
+    }
+#endif
+
 private:
 #ifndef DACCESS_COMPILE
     Volatile<TADDR> m_delta;
@@ -453,10 +517,20 @@ public:
     }
 
     // Returns whether the indirection cell contain fixup that has not been converted to real pointer yet.
+    BOOL IsTagged(TADDR base) const
+    {
+        LIMITED_METHOD_DAC_CONTRACT;
+        return IsTagged();
+    }
+
+    // Returns whether the indirection cell contain fixup that has not been converted to real pointer yet.
     BOOL IsTagged() const
     {
         LIMITED_METHOD_DAC_CONTRACT;
-        return m_ptr & 1;
+        TADDR addr = m_ptr;
+        if ((addr & FIXUP_POINTER_INDIRECTION) != 0)
+             return (*PTR_TADDR(addr - FIXUP_POINTER_INDIRECTION) & 1) != 0;
+        return FALSE;
     }
 
     // Returns value of the encoded pointer.
@@ -466,12 +540,17 @@ public:
         return dac_cast<PTR_TYPE>(m_ptr);
     }
 
+#ifndef DACCESS_COMPILE
     // Returns the pointer to the indirection cell.
     PTR_TYPE * GetValuePtr() const
     {
-        LIMITED_METHOD_DAC_CONTRACT;
+        LIMITED_METHOD_CONTRACT;
+        TADDR addr = m_ptr;
+        if ((addr & FIXUP_POINTER_INDIRECTION) != 0)
+            return (PTR_TYPE *)(addr - FIXUP_POINTER_INDIRECTION);
         return (PTR_TYPE *)&m_ptr;
     }
+#endif // !DACCESS_COMPILE
 
     // Returns value of the encoded pointer. Assumes that the pointer is not NULL.
     PTR_TYPE GetValue(TADDR base) const
@@ -508,6 +587,42 @@ public:
         return dac_cast<DPTR(PlainPointer<PTR_TYPE>)>(base)->GetValueMaybeNull(base);
     }
 
+    // Returns whether pointer is indirect. Assumes that the value is not NULL.
+    bool IsIndirectPtr(TADDR base) const
+    {
+        LIMITED_METHOD_DAC_CONTRACT;
+
+        return (m_ptr & FIXUP_POINTER_INDIRECTION) != 0;
+    }
+
+#ifndef DACCESS_COMPILE
+    // Returns whether pointer is indirect. Assumes that the value is not NULL.
+    // Does not need explicit base and thus can be used in non-DAC builds only.
+    bool IsIndirectPtr() const
+    {
+        LIMITED_METHOD_CONTRACT;
+        return IsIndirectPtr((TADDR)this);
+    }
+#endif
+
+    // Returns whether pointer is indirect. The value can be NULL.
+    bool IsIndirectPtrMaybeNull(TADDR base) const
+    {
+        LIMITED_METHOD_DAC_CONTRACT;
+
+        return IsIndirectPtr(base);
+    }
+
+#ifndef DACCESS_COMPILE
+    // Returns whether pointer is indirect. The value can be NULL.
+    // Does not need explicit base and thus can be used in non-DAC builds only.
+    bool IsIndirectPtrMaybeNull() const
+    {
+        LIMITED_METHOD_CONTRACT;
+        return IsIndirectPtrMaybeNull((TADDR)this);
+    }
+#endif
+
 #ifndef DACCESS_COMPILE
     void SetValue(PTR_TYPE addr)
     {
diff --git a/src/vm/ceeload.cpp b/src/vm/ceeload.cpp
index 3a85a52..43e2c14 100644
--- a/src/vm/ceeload.cpp
+++ b/src/vm/ceeload.cpp
@@ -10295,11 +10295,11 @@ void Module::RestoreMethodTablePointer(RelativeFixupPointer<PTR_MethodTable> * p
 
     if (ppMT->IsTagged((TADDR)ppMT))
     {
-        RestoreMethodTablePointerRaw(ppMT->GetValuePtr((TADDR)ppMT), pContainingModule, level);
+        RestoreMethodTablePointerRaw(ppMT->GetValuePtr(), pContainingModule, level);
     }
     else
     {
-        ClassLoader::EnsureLoaded(ppMT->GetValue((TADDR)ppMT), level);
+        ClassLoader::EnsureLoaded(ppMT->GetValue(), level);
     }
 }
 
@@ -10434,7 +10434,7 @@ PTR_Module Module::RestoreModulePointerIfLoaded(DPTR(RelativeFixupPointer<PTR_Mo
         return ppModule->GetValue(dac_cast<TADDR>(ppModule));
 
 #ifndef DACCESS_COMPILE 
-    PTR_Module * ppValue = ppModule->GetValuePtr(dac_cast<TADDR>(ppModule));
+    PTR_Module * ppValue = ppModule->GetValuePtr();
 
     // Ensure that the compiler won't fetch the value twice
     TADDR fixup = VolatileLoadWithoutBarrier((TADDR *)ppValue);
@@ -10487,7 +10487,7 @@ void Module::RestoreModulePointer(RelativeFixupPointer<PTR_Module> * ppModule, M
     if (!ppModule->IsTagged((TADDR)ppModule))
         return;
 
-    PTR_Module * ppValue = ppModule->GetValuePtr((TADDR)ppModule);
+    PTR_Module * ppValue = ppModule->GetValuePtr();
 
     // Ensure that the compiler won't fetch the value twice
     TADDR fixup = VolatileLoadWithoutBarrier((TADDR *)ppValue);
@@ -10641,7 +10641,7 @@ void Module::RestoreTypeHandlePointer(RelativeFixupPointer<TypeHandle> * pHandle
 
     if (pHandle->IsTagged((TADDR)pHandle))
     {
-        RestoreTypeHandlePointerRaw(pHandle->GetValuePtr((TADDR)pHandle), pContainingModule, level);
+        RestoreTypeHandlePointerRaw(pHandle->GetValuePtr(), pContainingModule, level);
     }
     else
     {
@@ -10743,7 +10743,7 @@ void Module::RestoreMethodDescPointer(RelativeFixupPointer<PTR_MethodDesc> * ppM
 
     if (ppMD->IsTagged((TADDR)ppMD))
     {
-        RestoreMethodDescPointerRaw(ppMD->GetValuePtr((TADDR)ppMD), pContainingModule, level);
+        RestoreMethodDescPointerRaw(ppMD->GetValuePtr(), pContainingModule, level);
     }
     else
     {
diff --git a/src/vm/debughelp.cpp b/src/vm/debughelp.cpp
index 3e66f14..0769feb 100644
--- a/src/vm/debughelp.cpp
+++ b/src/vm/debughelp.cpp
@@ -318,7 +318,7 @@ MethodDesc* AsMethodDesc(size_t addr)
                 // extra indirection if the address is tagged (the low bit is set).
                 // That could AV if we don't check it first.
 
-                if (!ppMT->IsTagged((TADDR)ppMT) || isMemoryReadable((TADDR)ppMT->GetValuePtr((TADDR)ppMT), sizeof(MethodTable*)))
+                if (!ppMT->IsTagged((TADDR)ppMT) || isMemoryReadable((TADDR)ppMT->GetValuePtr(), sizeof(MethodTable*)))
                 {
                     if (AsMethodTable((size_t)RelativeFixupPointer<PTR_MethodTable>::GetValueAtPtr((TADDR)ppMT)) != 0)
                     {
-- 
2.7.4