summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeremy Koritzinsky <jkoritzinsky@gmail.com>2018-10-10 10:04:48 -0700
committerGitHub <noreply@github.com>2018-10-10 10:04:48 -0700
commit737d0ea7c3e8a8ab42344f14b8338a0f7ffaf60d (patch)
tree7eb6f65883cc1452be769e4a4e2645918d0c0553 /src
parent2d64c3fab5598a639d5f99083342553bcf01ff2b (diff)
downloadcoreclr-737d0ea7c3e8a8ab42344f14b8338a0f7ffaf60d.tar.gz
coreclr-737d0ea7c3e8a8ab42344f14b8338a0f7ffaf60d.tar.bz2
coreclr-737d0ea7c3e8a8ab42344f14b8338a0f7ffaf60d.zip
Throw an exception when we try to marshal a non-blittable fixed buffer. (#20263)
* Throw an exception when we try to marshal a non-blittable fixed buffer. * Move function prototype into fieldmarshaler.cpp
Diffstat (limited to 'src')
-rw-r--r--src/vm/classnames.h1
-rw-r--r--src/vm/fieldmarshaler.cpp19
2 files changed, 18 insertions, 2 deletions
diff --git a/src/vm/classnames.h b/src/vm/classnames.h
index 1c1c545451..f62f4a8e19 100644
--- a/src/vm/classnames.h
+++ b/src/vm/classnames.h
@@ -156,6 +156,7 @@
#define g_UnmanagedFunctionPointerAttribute "System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute"
#define g_DefaultDllImportSearchPathsAttribute "System.Runtime.InteropServices.DefaultDllImportSearchPathsAttribute"
#define g_NativeCallableAttribute "System.Runtime.InteropServices.NativeCallableAttribute"
+#define g_FixedBufferAttribute "System.Runtime.CompilerServices.FixedBufferAttribute"
#define g_CompilerServicesTypeDependencyAttribute "System.Runtime.CompilerServices.TypeDependencyAttribute"
diff --git a/src/vm/fieldmarshaler.cpp b/src/vm/fieldmarshaler.cpp
index 9cee183f4b..2f93130856 100644
--- a/src/vm/fieldmarshaler.cpp
+++ b/src/vm/fieldmarshaler.cpp
@@ -34,7 +34,8 @@
// forward declaration
BOOL CheckForPrimitiveType(CorElementType elemType, CQuickArray<WCHAR> *pStrPrimitiveType);
TypeHandle ArraySubTypeLoadWorker(const SString &strUserDefTypeName, Assembly* pAssembly);
-TypeHandle GetFieldTypeHandleWorker(MetaSig *pFieldSig);
+TypeHandle GetFieldTypeHandleWorker(MetaSig *pFieldSig);
+BOOL IsFixedBuffer(mdFieldDef field, IMDInternalImport *pInternalImport);
//=======================================================================
@@ -659,7 +660,14 @@ do \
{
if (IsStructMarshalable(thNestedType))
{
- INITFIELDMARSHALER(NFT_NESTEDVALUECLASS, FieldMarshaler_NestedValueClass, (thNestedType.GetMethodTable()));
+ if (IsFixedBuffer(pfwalk->m_MD, pInternalImport) && !thNestedType.GetMethodTable()->IsBlittable())
+ {
+ INITFIELDMARSHALER(NFT_ILLEGAL, FieldMarshaler_Illegal, (IDS_EE_BADMARSHAL_NOTMARSHALABLE));
+ }
+ else
+ {
+ INITFIELDMARSHALER(NFT_NESTEDVALUECLASS, FieldMarshaler_NestedValueClass, (thNestedType.GetMethodTable()));
+ }
}
else
{
@@ -1228,6 +1236,13 @@ BOOL IsStructMarshalable(TypeHandle th)
return TRUE;
}
+BOOL IsFixedBuffer(mdFieldDef field, IMDInternalImport *pInternalImport)
+{
+ HRESULT hr = pInternalImport->GetCustomAttributeByName(field, g_FixedBufferAttribute, NULL, NULL);
+
+ return hr == S_OK ? TRUE : FALSE;
+}
+
//=======================================================================
// Called from the clsloader to load up and summarize the field metadata