summaryrefslogtreecommitdiff
path: root/packaging/0021-Additional-fixes-for-RelativePointer-FixupPointer-Re.patch
diff options
context:
space:
mode:
Diffstat (limited to 'packaging/0021-Additional-fixes-for-RelativePointer-FixupPointer-Re.patch')
-rw-r--r--packaging/0021-Additional-fixes-for-RelativePointer-FixupPointer-Re.patch332
1 files changed, 332 insertions, 0 deletions
diff --git a/packaging/0021-Additional-fixes-for-RelativePointer-FixupPointer-Re.patch b/packaging/0021-Additional-fixes-for-RelativePointer-FixupPointer-Re.patch
new file mode 100644
index 0000000000..d3599f03e7
--- /dev/null
+++ b/packaging/0021-Additional-fixes-for-RelativePointer-FixupPointer-Re.patch
@@ -0,0 +1,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
+