Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Cross-bitness regular and thread static fields offsets (#18636)
Browse files Browse the repository at this point in the history
* Define OFFSETOF__DomainLocalModule__m_pDataBlob_ OFFSETOF__DomainLocalModule__NormalDynamicEntry__m_pDataBlob in src/vm/appdomain.hpp

* Define OFFSETOF__ThreadLocalModule__m_pDataBlob OFFSETOF__ThreadLocalModule__DynamicEntry__m_pDataBlob in src/vm/threadstatics.h

* Add assertions and offsets for dynamically allocated statics

* Compensate OffsetOfDataBlob difference

* Check target specific offsets in assertions in src/vm/methodtablebuilder.cpp
  • Loading branch information
echesakov authored and jkotas committed Jun 25, 2018
1 parent df78ae7 commit 030a3ea
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/vm/appdomain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,12 @@ struct DomainLocalModule

}; // struct DomainLocalModule

#define OFFSETOF__DomainLocalModule__m_pDataBlob_ (6 * TARGET_POINTER_SIZE)
#ifdef FEATURE_64BIT_ALIGNMENT
#define OFFSETOF__DomainLocalModule__NormalDynamicEntry__m_pDataBlob (TARGET_POINTER_SIZE /* m_pGCStatics */ + TARGET_POINTER_SIZE /* m_padding */)
#else
#define OFFSETOF__DomainLocalModule__NormalDynamicEntry__m_pDataBlob TARGET_POINTER_SIZE /* m_pGCStatics */
#endif

typedef DPTR(class DomainLocalBlock) PTR_DomainLocalBlock;
class DomainLocalBlock
Expand Down
22 changes: 20 additions & 2 deletions src/vm/ceeload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2017,6 +2017,12 @@ void Module::BuildStaticsOffsets(AllocMemTracker *pamTracker)
// | Class Data (one byte per class) | pointer to gc statics | primitive type statics |
//
//
#ifndef CROSSBITNESS_COMPILE
// The assertions must hold in every non-crossbitness scenario
_ASSERTE(OFFSETOF__DomainLocalModule__m_pDataBlob_ == DomainLocalModule::OffsetOfDataBlob());
_ASSERTE(OFFSETOF__ThreadLocalModule__m_pDataBlob == ThreadLocalModule::OffsetOfDataBlob());
#endif

DWORD dwNonGCBytes[2] = {
DomainLocalModule::OffsetOfDataBlob() + sizeof(BYTE)*dwNumTypes,
ThreadLocalModule::OffsetOfDataBlob() + sizeof(BYTE)*dwNumTypes
Expand Down Expand Up @@ -2233,11 +2239,14 @@ void Module::GetOffsetsForRegularStaticData(
return;
}

#ifndef CROSSBITNESS_COMPILE
_ASSERTE(OFFSETOF__DomainLocalModule__NormalDynamicEntry__m_pDataBlob == DomainLocalModule::DynamicEntry::GetOffsetOfDataBlob());
#endif
// Statics for instantiated types are allocated dynamically per-instantiation
if (bDynamic)
{
// Non GC statics are embedded in the Dynamic Entry.
*pOutNonGCStaticOffset = DomainLocalModule::DynamicEntry::GetOffsetOfDataBlob();
*pOutNonGCStaticOffset = OFFSETOF__DomainLocalModule__NormalDynamicEntry__m_pDataBlob;
return;
}

Expand All @@ -2253,6 +2262,9 @@ void Module::GetOffsetsForRegularStaticData(
*pOutStaticHandleOffset = m_pRegularStaticOffsets[index*2];

*pOutNonGCStaticOffset = m_pRegularStaticOffsets[index*2 + 1];
#ifdef CROSSBITNESS_COMPILE
*pOutNonGCStaticOffset += OFFSETOF__DomainLocalModule__m_pDataBlob_ - DomainLocalModule::OffsetOfDataBlob();
#endif

// Check we didnt go out of what we predicted we would need for the class
if (*pOutStaticHandleOffset + TARGET_POINTER_SIZE*dwGCStaticHandles >
Expand Down Expand Up @@ -2291,11 +2303,14 @@ void Module::GetOffsetsForThreadStaticData(
return;
}

#ifndef CROSSBITNESS_COMPILE
_ASSERTE(OFFSETOF__ThreadLocalModule__DynamicEntry__m_pDataBlob == ThreadLocalModule::DynamicEntry::GetOffsetOfDataBlob());
#endif
// Statics for instantiated types are allocated dynamically per-instantiation
if (bDynamic)
{
// Non GC thread statics are embedded in the Dynamic Entry.
*pOutNonGCStaticOffset = ThreadLocalModule::DynamicEntry::GetOffsetOfDataBlob();
*pOutNonGCStaticOffset = OFFSETOF__ThreadLocalModule__DynamicEntry__m_pDataBlob;
return;
}

Expand All @@ -2311,6 +2326,9 @@ void Module::GetOffsetsForThreadStaticData(
*pOutStaticHandleOffset = m_pThreadStaticOffsets[index*2];

*pOutNonGCStaticOffset = m_pThreadStaticOffsets[index*2 + 1];
#ifdef CROSSBITNESS_COMPILE
*pOutNonGCStaticOffset += OFFSETOF__ThreadLocalModule__m_pDataBlob - ThreadLocalModule::GetOffsetOfDataBlob();
#endif

// Check we didnt go out of what we predicted we would need for the class
if (*pOutStaticHandleOffset + TARGET_POINTER_SIZE*dwGCStaticHandles >
Expand Down
4 changes: 2 additions & 2 deletions src/vm/methodtablebuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7719,7 +7719,7 @@ VOID MethodTableBuilder::PlaceRegularStaticFields()
if (bmtProp->fDynamicStatics)
{
_ASSERTE(dwNonGCOffset == 0 || // no statics at all
dwNonGCOffset == DomainLocalModule::DynamicEntry::GetOffsetOfDataBlob()); // We need space to point to the GC statics
dwNonGCOffset == OFFSETOF__DomainLocalModule__NormalDynamicEntry__m_pDataBlob); // We need space to point to the GC statics
bmtProp->dwNonGCRegularStaticFieldBytes = dwCumulativeStaticFieldPos;
}
else
Expand Down Expand Up @@ -7841,7 +7841,7 @@ VOID MethodTableBuilder::PlaceThreadStaticFields()
if (bmtProp->fDynamicStatics)
{
_ASSERTE(dwNonGCOffset == 0 || // no thread statics at all
dwNonGCOffset == ThreadLocalModule::DynamicEntry::GetOffsetOfDataBlob()); // We need space to point to the GC statics
dwNonGCOffset == OFFSETOF__ThreadLocalModule__DynamicEntry__m_pDataBlob); // We need space to point to the GC statics
bmtProp->dwNonGCThreadStaticFieldBytes = dwCumulativeStaticFieldPos;
}
else
Expand Down
6 changes: 6 additions & 0 deletions src/vm/threadstatics.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,12 @@ struct ThreadLocalModule
}; // struct ThreadLocalModule


#define OFFSETOF__ThreadLocalModule__m_pDataBlob (3 * TARGET_POINTER_SIZE /* m_pDynamicClassTable + m_aDynamicEntries + m_pGCStatics */)
#ifdef FEATURE_64BIT_ALIGNMENT
#define OFFSETOF__ThreadLocalModule__DynamicEntry__m_pDataBlob (TARGET_POINTER_SIZE /* m_pGCStatics */ + TARGET_POINTER_SIZE /* m_padding */)
#else
#define OFFSETOF__ThreadLocalModule__DynamicEntry__m_pDataBlob TARGET_POINTER_SIZE /* m_pGCStatics */
#endif

typedef DPTR(struct TLMTableEntry) PTR_TLMTableEntry;

Expand Down

0 comments on commit 030a3ea

Please sign in to comment.