} \
ELEMENT_SIZE_IMPL(NativeSize, AlignmentReq)
+#define COPY_TO_IMPL_BASE_STRUCT_ONLY() \
+ VOID CopyToImpl(VOID *pDest, SIZE_T destSize) \
+ { \
+ static_assert(sizeof(*this) == sizeof(FieldMarshaler), \
+ "Please, implement CopyToImpl for correct copy of field values"); \
+ \
+ FieldMarshaler::CopyToImpl(pDest, destSize); \
+ }
+
+#define START_COPY_TO_IMPL(CLASS_NAME) \
+ VOID CopyToImpl(VOID *pDest, SIZE_T destSize) const \
+ { \
+ FieldMarshaler::CopyToImpl(pDest, destSize); \
+ \
+ CLASS_NAME *pDestFieldMarshaller = (std::remove_const<std::remove_pointer<decltype(this)>::type>::type *) pDest; \
+ _ASSERTE(sizeof(*pDestFieldMarshaller) <= destSize); \
+
+#define END_COPY_TO_IMPL(CLASS_NAME) \
+ static_assert(std::is_same<CLASS_NAME *, decltype(pDestFieldMarshaller)>::value, \
+ "Structure's name is required"); \
+ }
+
//=======================================================================
//
VOID ScalarUpdateCLR(const VOID *pNative, LPVOID pCLR) const;
VOID NestedValueClassUpdateNative(const VOID **ppProtectedCLR, SIZE_T startoffset, LPVOID pNative, OBJECTREF *ppCleanupWorkListOnStack) const;
VOID NestedValueClassUpdateCLR(const VOID *pNative, LPVOID *ppProtectedCLR, SIZE_T startoffset) const;
+ VOID CopyTo(VOID *pDest, SIZE_T destSize) const;
#ifdef FEATURE_PREJIT
void Save(DataImage *image);
void Fixup(DataImage *image);
#endif // FEATURE_PREJIT
}
+ void CopyToImpl(VOID *pDest, SIZE_T destSize) const
+ {
+ FieldMarshaler *pDestFieldMarshaller = (FieldMarshaler *) pDest;
+
+ _ASSERTE(sizeof(*pDestFieldMarshaller) <= destSize);
+
+ pDestFieldMarshaller->SetFieldDesc(GetFieldDesc());
+ pDestFieldMarshaller->SetExternalOffset(GetExternalOffset());
+ pDestFieldMarshaller->SetNStructFieldType(GetNStructFieldType());
+ }
+
void SetFieldDesc(FieldDesc* pFD)
{
LIMITED_METHOD_CONTRACT;
- m_pFD.SetValue(pFD);
+ m_pFD.SetValueMaybeNull(pFD);
}
FieldDesc* GetFieldDesc() const
}
CONTRACT_END;
- RETURN m_pFD.GetValue();
+ RETURN m_pFD.GetValueMaybeNull();
}
void SetExternalOffset(UINT32 dwExternalOffset)
#endif
}
- static inline void RestoreHelper(FixupPointer<PTR_MethodTable> *ppMT)
+ static inline void RestoreHelper(RelativeFixupPointer<PTR_MethodTable> *ppMT)
{
CONTRACTL
{
}
#ifdef _DEBUG
- static inline BOOL IsRestoredHelper(FixupPointer<PTR_MethodTable> pMT)
+ static inline BOOL IsRestoredHelper(const RelativeFixupPointer<PTR_MethodTable> &pMT)
{
WRAPPER_NO_CONTRACT;
#endif // _DEBUG
- FixupPointer<PTR_FieldDesc> m_pFD; // FieldDesc
+ RelativeFixupPointer<PTR_FieldDesc> m_pFD; // FieldDesc
UINT32 m_dwExternalOffset; // offset of field in the fixed portion
NStructFieldType m_nft;
};
VOID DestroyNativeImpl(LPVOID pNativeValue) const;
ELEMENT_SIZE_IMPL(sizeof(BSTR), sizeof(BSTR))
+ COPY_TO_IMPL_BASE_STRUCT_ONLY()
};
//=======================================================================
VOID DestroyNativeImpl(LPVOID pNativeValue) const;
ELEMENT_SIZE_IMPL(sizeof(HSTRING), sizeof(HSTRING))
+ COPY_TO_IMPL_BASE_STRUCT_ONLY()
};
//=======================================================================
FieldMarshaler_Nullable(MethodTable* pMT)
{
- m_pNullableTypeMT.SetValue(pMT);
+ m_pNullableTypeMT.SetValueMaybeNull(pMT);
}
BOOL IsNullableMarshalerImpl() const
FieldMarshaler::RestoreImpl();
}
+ START_COPY_TO_IMPL(FieldMarshaler_Nullable)
+ {
+ pDestFieldMarshaller->m_pNullableTypeMT.SetValueMaybeNull(GetMethodTable());
+ }
+ END_COPY_TO_IMPL(FieldMarshaler_Nullable)
+
#ifdef _DEBUG
BOOL IsRestored() const
{
}
private:
- FixupPointer<PTR_MethodTable> m_pNullableTypeMT;
+ RelativeFixupPointer<PTR_MethodTable> m_pNullableTypeMT;
};
VOID DestroyNativeImpl(LPVOID pNativeValue) const;
ELEMENT_SIZE_IMPL(sizeof(HSTRING), sizeof(HSTRING))
+ COPY_TO_IMPL_BASE_STRUCT_ONLY()
};
//=======================================================================
VOID UpdateCLRImpl(const VOID * pNativeValue, OBJECTREF * ppProtectedCLRValue, OBJECTREF * ppProtectedOldCLRValue) const;
ELEMENT_SIZE_IMPL(sizeof(HRESULT), sizeof(HRESULT))
+ COPY_TO_IMPL_BASE_STRUCT_ONLY()
};
#endif // FEATURE_COMINTEROP
FieldMarshaler_NestedLayoutClass(MethodTable *pMT)
{
WRAPPER_NO_CONTRACT;
- m_pNestedMethodTable.SetValue(pMT);
+ m_pNestedMethodTable.SetValueMaybeNull(pMT);
}
VOID UpdateNativeImpl(OBJECTREF* pCLRValue, LPVOID pNativeValue, OBJECTREF *ppCleanupWorkListOnStack) const;
FieldMarshaler::RestoreImpl();
}
+ START_COPY_TO_IMPL(FieldMarshaler_NestedLayoutClass)
+ {
+ pDestFieldMarshaller->m_pNestedMethodTable.SetValueMaybeNull(GetMethodTable());
+ }
+ END_COPY_TO_IMPL(FieldMarshaler_NestedLayoutClass)
+
#ifdef _DEBUG
BOOL IsRestored() const
{
}
CONTRACTL_END;
- return m_pNestedMethodTable.GetValue();
+ return m_pNestedMethodTable.GetValueMaybeNull();
}
private:
// MethodTable of nested FieldMarshaler.
- FixupPointer<PTR_MethodTable> m_pNestedMethodTable;
+ RelativeFixupPointer<PTR_MethodTable> m_pNestedMethodTable;
};
FieldMarshaler_NestedValueClass(MethodTable *pMT)
{
WRAPPER_NO_CONTRACT;
- m_pNestedMethodTable.SetValue(pMT);
+ m_pNestedMethodTable.SetValueMaybeNull(pMT);
}
BOOL IsNestedValueClassMarshalerImpl() const
FieldMarshaler::RestoreImpl();
}
+ START_COPY_TO_IMPL(FieldMarshaler_NestedValueClass)
+ {
+ pDestFieldMarshaller->m_pNestedMethodTable.SetValueMaybeNull(GetMethodTable());
+ }
+ END_COPY_TO_IMPL(FieldMarshaler_NestedValueClass)
+
#ifdef _DEBUG
BOOL IsRestored() const
{
}
CONTRACTL_END;
- return m_pNestedMethodTable.GetValue();
+ return m_pNestedMethodTable.GetValueMaybeNull();
}
private:
// MethodTable of nested NStruct.
- FixupPointer<PTR_MethodTable> m_pNestedMethodTable;
+ RelativeFixupPointer<PTR_MethodTable> m_pNestedMethodTable;
};
VOID DestroyNativeImpl(LPVOID pNativeValue) const;
ELEMENT_SIZE_IMPL(sizeof(LPWSTR), sizeof(LPWSTR))
+ COPY_TO_IMPL_BASE_STRUCT_ONLY()
};
//=======================================================================
VOID DestroyNativeImpl(LPVOID pNativeValue) const;
ELEMENT_SIZE_IMPL(sizeof(LPSTR), sizeof(LPSTR))
+ COPY_TO_IMPL_BASE_STRUCT_ONLY()
};
//=======================================================================
return m_ThrowOnUnmappableChar;
}
+ START_COPY_TO_IMPL(FieldMarshaler_StringAnsi)
+ {
+ pDestFieldMarshaller->m_BestFitMap = m_BestFitMap;
+ pDestFieldMarshaller->m_ThrowOnUnmappableChar = m_ThrowOnUnmappableChar;
+ }
+ END_COPY_TO_IMPL(FieldMarshaler_StringAnsi)
+
private:
bool m_BestFitMap:1;
bool m_ThrowOnUnmappableChar:1;
m_numchar = numChar;
}
+ START_COPY_TO_IMPL(FieldMarshaler_FixedStringUni)
+ {
+ pDestFieldMarshaller->m_numchar = m_numchar;
+ }
+ END_COPY_TO_IMPL(FieldMarshaler_FixedStringUni)
+
private:
// # of characters for fixed strings
UINT32 m_numchar;
return m_ThrowOnUnmappableChar;
}
+ START_COPY_TO_IMPL(FieldMarshaler_FixedStringAnsi)
+ {
+ pDestFieldMarshaller->m_numchar = m_numchar;
+ pDestFieldMarshaller->m_BestFitMap = m_BestFitMap;
+ pDestFieldMarshaller->m_ThrowOnUnmappableChar = m_ThrowOnUnmappableChar;
+ }
+ END_COPY_TO_IMPL(FieldMarshaler_FixedStringAnsi)
+
private:
// # of characters for fixed strings
UINT32 m_numchar;
return m_ThrowOnUnmappableChar;
}
+ START_COPY_TO_IMPL(FieldMarshaler_FixedCharArrayAnsi)
+ {
+ pDestFieldMarshaller->m_numElems = m_numElems;
+ pDestFieldMarshaller->m_BestFitMap = m_BestFitMap;
+ pDestFieldMarshaller->m_ThrowOnUnmappableChar = m_ThrowOnUnmappableChar;
+ }
+ END_COPY_TO_IMPL(FieldMarshaler_FixedCharArrayAnsi)
+
private:
// # of elements for fixedchararray
UINT32 m_numElems;
FieldMarshaler::RestoreImpl();
}
+ START_COPY_TO_IMPL(FieldMarshaler_FixedArray)
+ {
+ pDestFieldMarshaller->m_arrayType.SetValueMaybeNull(m_arrayType.GetValueMaybeNull());
+ pDestFieldMarshaller->m_numElems = m_numElems;
+ pDestFieldMarshaller->m_vt = m_vt;
+ pDestFieldMarshaller->m_BestFitMap = m_BestFitMap;
+ pDestFieldMarshaller->m_ThrowOnUnmappableChar = m_ThrowOnUnmappableChar;
+ }
+ END_COPY_TO_IMPL(FieldMarshaler_FixedArray)
+
#ifdef _DEBUG
BOOL IsRestored() const
{
#endif
private:
- FixupPointer<TypeHandle> m_arrayType;
+ RelativeFixupPointer<TypeHandle> m_arrayType;
UINT32 m_numElems;
VARTYPE m_vt;
bool m_BestFitMap:1; // Note: deliberately use small bools to save on working set - this is the largest FieldMarshaler and dominates the cost of the FieldMarshaler array
{
WRAPPER_NO_CONTRACT;
m_vt = vt;
- m_pMT.SetValue(pMT);
+ m_pMT.SetValueMaybeNull(pMT);
}
#ifdef FEATURE_PREJIT
FieldMarshaler::RestoreImpl();
}
+ START_COPY_TO_IMPL(FieldMarshaler_SafeArray)
+ {
+ pDestFieldMarshaller->m_pMT.SetValueMaybeNull(m_pMT.GetValueMaybeNull());
+ pDestFieldMarshaller->m_vt = m_vt;
+ }
+ END_COPY_TO_IMPL(FieldMarshaler_SafeArray)
+
#ifdef _DEBUG
BOOL IsRestored() const
{
}
private:
- FixupPointer<PTR_MethodTable> m_pMT;
+ RelativeFixupPointer<PTR_MethodTable> m_pMT;
VARTYPE m_vt;
};
#endif //FEATURE_CLASSIC_COMINTEROP
FieldMarshaler_Delegate(MethodTable* pMT)
{
WRAPPER_NO_CONTRACT;
- m_pNestedMethodTable.SetValue(pMT);
+ m_pNestedMethodTable.SetValueMaybeNull(pMT);
}
VOID UpdateNativeImpl(OBJECTREF* pCLRValue, LPVOID pNativeValue, OBJECTREF *ppCleanupWorkListOnStack) const;
FieldMarshaler::RestoreImpl();
}
+ START_COPY_TO_IMPL(FieldMarshaler_Delegate)
+ {
+ pDestFieldMarshaller->m_pNestedMethodTable.SetValueMaybeNull(m_pNestedMethodTable.GetValueMaybeNull());
+ }
+ END_COPY_TO_IMPL(FieldMarshaler_Delegate)
+
#ifdef _DEBUG
BOOL IsRestored() const
{
}
CONTRACTL_END;
- return m_pNestedMethodTable.GetValue();
+ return m_pNestedMethodTable.GetValueMaybeNull();
}
- FixupPointer<PTR_MethodTable> m_pNestedMethodTable;
+ RelativeFixupPointer<PTR_MethodTable> m_pNestedMethodTable;
};
VOID UpdateCLRImpl(const VOID *pNativeValue, OBJECTREF *ppProtectedCLRValue, OBJECTREF *ppProtectedOldCLRValue) const;
ELEMENT_SIZE_IMPL(sizeof(LPVOID), sizeof(LPVOID))
+ COPY_TO_IMPL_BASE_STRUCT_ONLY()
};
VOID UpdateCLRImpl(const VOID *pNativeValue, OBJECTREF *ppProtectedCLRValue, OBJECTREF *ppProtectedOldCLRValue) const;
ELEMENT_SIZE_IMPL(sizeof(LPVOID), sizeof(LPVOID))
+ COPY_TO_IMPL_BASE_STRUCT_ONLY()
};
#ifdef FEATURE_COMINTEROP
FieldMarshaler_Interface(MethodTable *pClassMT, MethodTable *pItfMT, DWORD dwFlags)
{
WRAPPER_NO_CONTRACT;
- m_pClassMT.SetValue(pClassMT);
- m_pItfMT.SetValue(pItfMT);
+ m_pClassMT.SetValueMaybeNull(pClassMT);
+ m_pItfMT.SetValueMaybeNull(pItfMT);
m_dwFlags = dwFlags;
}
FieldMarshaler::RestoreImpl();
}
+ START_COPY_TO_IMPL(FieldMarshaler_Interface)
+ {
+ pDestFieldMarshaller->m_pClassMT.SetValueMaybeNull(m_pClassMT.GetValueMaybeNull());
+ pDestFieldMarshaller->m_pItfMT.SetValueMaybeNull(m_pItfMT.GetValueMaybeNull());
+ pDestFieldMarshaller->m_dwFlags = m_dwFlags;
+ }
+ END_COPY_TO_IMPL(FieldMarshaler_Interface)
+
#ifdef _DEBUG
BOOL IsRestored() const
{
}
CONTRACTL_END;
- return m_pClassMT.GetValue();
+ return m_pClassMT.GetValueMaybeNull();
}
MethodTable *GetInterfaceMethodTable() const
}
CONTRACTL_END;
- return m_pItfMT.GetValue();
+ return m_pItfMT.GetValueMaybeNull();
}
private:
- FixupPointer<PTR_MethodTable> m_pClassMT;
- FixupPointer<PTR_MethodTable> m_pItfMT;
+ RelativeFixupPointer<PTR_MethodTable> m_pClassMT;
+ RelativeFixupPointer<PTR_MethodTable> m_pItfMT;
DWORD m_dwFlags;
};
VOID DestroyNativeImpl(LPVOID pNativeValue) const;
ELEMENT_SIZE_IMPL(sizeof(VARIANT), 8)
+ COPY_TO_IMPL_BASE_STRUCT_ONLY()
};
#endif // FEATURE_COMINTEROP
VOID ScalarUpdateCLRImpl(const VOID *pNative, LPVOID pCLR) const;
SCALAR_MARSHALER_IMPL(1, 1)
-
+
+ START_COPY_TO_IMPL(FieldMarshaler_Illegal)
+ {
+ pDestFieldMarshaller->m_resIDWhy = m_resIDWhy;
+ }
+ END_COPY_TO_IMPL(FieldMarshaler_Illegal)
+
private:
UINT m_resIDWhy;
};
UNUSED_METHOD_IMPL(VOID UpdateCLRImpl(const VOID *pNativeValue, OBJECTREF *ppProtectedCLRValue, OBJECTREF *ppProtectedOldCLRValue) const)
SCALAR_MARSHALER_IMPL(1, 1)
+ COPY_TO_IMPL_BASE_STRUCT_ONLY()
VOID ScalarUpdateNativeImpl(LPVOID pCLR, LPVOID pNative) const
{
UNUSED_METHOD_IMPL(VOID UpdateCLRImpl(const VOID *pNativeValue, OBJECTREF *ppProtectedCLRValue, OBJECTREF *ppProtectedOldCLRValue) const)
SCALAR_MARSHALER_IMPL(2, 2)
+ COPY_TO_IMPL_BASE_STRUCT_ONLY()
VOID ScalarUpdateNativeImpl(LPVOID pCLR, LPVOID pNative) const
{
UNUSED_METHOD_IMPL(VOID UpdateCLRImpl(const VOID *pNativeValue, OBJECTREF *ppProtectedCLRValue, OBJECTREF *ppProtectedOldCLRValue) const)
SCALAR_MARSHALER_IMPL(4, 4)
+ COPY_TO_IMPL_BASE_STRUCT_ONLY()
VOID ScalarUpdateNativeImpl(LPVOID pCLR, LPVOID pNative) const
{
UNUSED_METHOD_IMPL(VOID UpdateCLRImpl(const VOID *pNativeValue, OBJECTREF *ppProtectedCLRValue, OBJECTREF *ppProtectedOldCLRValue) const)
SCALAR_MARSHALER_IMPL(8, 8)
+ COPY_TO_IMPL_BASE_STRUCT_ONLY()
VOID ScalarUpdateNativeImpl(LPVOID pCLR, LPVOID pNative) const
{
return m_ThrowOnUnmappableChar;
}
+ START_COPY_TO_IMPL(FieldMarshaler_Ansi)
+ {
+ pDestFieldMarshaller->m_BestFitMap = m_BestFitMap;
+ pDestFieldMarshaller->m_ThrowOnUnmappableChar = m_ThrowOnUnmappableChar;
+ }
+ END_COPY_TO_IMPL(FieldMarshaler_Ansi)
+
private:
bool m_BestFitMap:1;
bool m_ThrowOnUnmappableChar:1;
UNUSED_METHOD_IMPL(VOID UpdateCLRImpl(const VOID *pNativeValue, OBJECTREF *ppProtectedCLRValue, OBJECTREF *ppProtectedOldCLRValue) const)
SCALAR_MARSHALER_IMPL(sizeof(BOOL), sizeof(BOOL))
+ COPY_TO_IMPL_BASE_STRUCT_ONLY()
VOID ScalarUpdateNativeImpl(LPVOID pCLR, LPVOID pNative) const
{
UNUSED_METHOD_IMPL(VOID UpdateCLRImpl(const VOID *pNativeValue, OBJECTREF *ppProtectedCLRValue, OBJECTREF *ppProtectedOldCLRValue) const)
SCALAR_MARSHALER_IMPL(sizeof(VARIANT_BOOL), sizeof(VARIANT_BOOL))
+ COPY_TO_IMPL_BASE_STRUCT_ONLY()
VOID ScalarUpdateNativeImpl(LPVOID pCLR, LPVOID pNative) const
{
UNUSED_METHOD_IMPL(VOID UpdateCLRImpl(const VOID *pNativeValue, OBJECTREF *ppProtectedCLRValue, OBJECTREF *ppProtectedOldCLRValue) const)
SCALAR_MARSHALER_IMPL(1, 1)
+ COPY_TO_IMPL_BASE_STRUCT_ONLY()
VOID ScalarUpdateNativeImpl(LPVOID pCLR, LPVOID pNative) const
{
UNUSED_METHOD_IMPL(VOID UpdateCLRImpl(const VOID *pNativeValue, OBJECTREF *ppProtectedCLRValue, OBJECTREF *ppProtectedOldCLRValue) const)
SCALAR_MARSHALER_IMPL(sizeof(DECIMAL), 8);
+ COPY_TO_IMPL_BASE_STRUCT_ONLY()
VOID ScalarUpdateNativeImpl(LPVOID pCLR, LPVOID pNative) const
{
UNUSED_METHOD_IMPL(VOID UpdateCLRImpl(const VOID *pNativeValue, OBJECTREF *ppProtectedCLRValue, OBJECTREF *ppProtectedOldCLRValue) const)
SCALAR_MARSHALER_IMPL(sizeof(DATE), sizeof(DATE))
+ COPY_TO_IMPL_BASE_STRUCT_ONLY()
VOID ScalarUpdateNativeImpl(LPVOID pCLR, LPVOID pNative) const;
VOID ScalarUpdateCLRImpl(const VOID *pNative, LPVOID pCLR) const;
UNUSED_METHOD_IMPL(VOID UpdateCLRImpl(const VOID *pNativeValue, OBJECTREF *ppProtectedCLRValue, OBJECTREF *ppProtectedOldCLRValue) const)
SCALAR_MARSHALER_IMPL(sizeof(CURRENCY), sizeof(CURRENCY))
+ COPY_TO_IMPL_BASE_STRUCT_ONLY()
VOID ScalarUpdateNativeImpl(LPVOID pCLR, LPVOID pNative) const;
VOID ScalarUpdateCLRImpl(const VOID *pNative, LPVOID pCLR) const;
UNUSED_METHOD_IMPL(VOID UpdateCLRImpl(const VOID *pNativeValue, OBJECTREF *ppProtectedCLRValue, OBJECTREF *ppProtectedOldCLRValue) const)
SCALAR_MARSHALER_IMPL(sizeof(INT64), sizeof(INT64))
+ COPY_TO_IMPL_BASE_STRUCT_ONLY()
VOID ScalarUpdateNativeImpl(LPVOID pCLR, LPVOID pNative) const;
VOID ScalarUpdateCLRImpl(const VOID *pNative, LPVOID pCLR) const;