summaryrefslogtreecommitdiff
path: root/src/vm/marshalnative.cpp
diff options
context:
space:
mode:
authorJan Kotas <jkotas@microsoft.com>2019-01-20 08:16:44 -0800
committerGitHub <noreply@github.com>2019-01-20 08:16:44 -0800
commit170854b92017d709bc82d7631c6cb33dd7443078 (patch)
treee4d216f1b1be6d9207644e160f86af8846c02577 /src/vm/marshalnative.cpp
parent614966d1e179c32ce85df2791102847128390ca6 (diff)
downloadcoreclr-170854b92017d709bc82d7631c6cb33dd7443078.tar.gz
coreclr-170854b92017d709bc82d7631c6cb33dd7443078.tar.bz2
coreclr-170854b92017d709bc82d7631c6cb33dd7443078.zip
Cleanup array related FCalls (#22097)
* Cleanup Array FCalls * Disable outdated CoreFX tests https://github.com/dotnet/corefx/pull/34700
Diffstat (limited to 'src/vm/marshalnative.cpp')
-rw-r--r--src/vm/marshalnative.cpp182
1 files changed, 32 insertions, 150 deletions
diff --git a/src/vm/marshalnative.cpp b/src/vm/marshalnative.cpp
index e2b248289b..95ff46001a 100644
--- a/src/vm/marshalnative.cpp
+++ b/src/vm/marshalnative.cpp
@@ -255,6 +255,38 @@ FCIMPL2(VOID, MarshalNative::DestroyStructure, LPVOID ptr, ReflectClassBaseObjec
}
FCIMPLEND
+FCIMPL1(FC_BOOL_RET, MarshalNative::IsPinnable, Object* obj)
+{
+ FCALL_CONTRACT;
+
+ VALIDATEOBJECT(obj);
+
+ if (obj == NULL)
+ FC_RETURN_BOOL(TRUE);
+
+ if (obj->GetMethodTable() == g_pStringClass)
+ FC_RETURN_BOOL(TRUE);
+
+ if (obj->GetMethodTable()->IsArray())
+ {
+ BASEARRAYREF asArray = (BASEARRAYREF)ObjectToOBJECTREF(obj);
+ if (CorTypeInfo::IsPrimitiveType(asArray->GetArrayElementType()))
+ FC_RETURN_BOOL(TRUE);
+
+ TypeHandle th = asArray->GetArrayElementTypeHandle();
+ if (!th.IsTypeDesc())
+ {
+ MethodTable *pMT = th.AsMethodTable();
+ if (pMT->IsValueType() && pMT->IsBlittable())
+ FC_RETURN_BOOL(TRUE);
+ }
+
+ FC_RETURN_BOOL(FALSE);
+ }
+
+ FC_RETURN_BOOL(obj->GetMethodTable()->IsBlittable());
+}
+FCIMPLEND
/************************************************************************
* PInvoke.SizeOf(Class)
@@ -297,22 +329,6 @@ FCIMPLEND
/************************************************************************
- * PInvoke.UnsafeAddrOfPinnedArrayElement(Array arr, int index)
- */
-
-FCIMPL2(LPVOID, MarshalNative::FCUnsafeAddrOfPinnedArrayElement, ArrayBase *arr, INT32 index)
-{
- FCALL_CONTRACT;
-
- if (!arr)
- FCThrowArgumentNull(W("arr"));
-
- return (arr->GetDataPtr() + (index*arr->GetComponentSize()));
-}
-FCIMPLEND
-
-
-/************************************************************************
* PInvoke.OffsetOfHelper(Class, Field)
*/
FCIMPL1(UINT32, MarshalNative::OffsetOfHelper, ReflectFieldObject *pFieldUNSAFE)
@@ -474,92 +490,6 @@ FCIMPL0(UINT32, MarshalNative::GetSystemMaxDBCSCharSize)
}
FCIMPLEND
-
-/************************************************************************
- * Handles all PInvoke.Copy(array source, ....) methods.
- */
-FCIMPL4(void, MarshalNative::CopyToNative, Object* psrcUNSAFE, INT32 startindex, LPVOID pdst, INT32 length)
-{
- CONTRACTL
- {
- FCALL_CHECK;
- PRECONDITION(CheckPointer(pdst, NULL_OK));
- }
- CONTRACTL_END;
-
- // The BCL code guarantees that Array will be passed in
- _ASSERTE(!psrcUNSAFE || psrcUNSAFE->GetMethodTable()->IsArray());
-
- BASEARRAYREF psrc = (BASEARRAYREF)(OBJECTREF)psrcUNSAFE;
-
- HELPER_METHOD_FRAME_BEGIN_1(psrc);
-
- if (pdst == NULL)
- COMPlusThrowArgumentNull(W("destination"));
- if (psrc == NULL)
- COMPlusThrowArgumentNull(W("source"));
-
- SIZE_T numelem = psrc->GetNumComponents();
-
- if (startindex < 0 || length < 0 || (SIZE_T)startindex + (SIZE_T)length > numelem)
- {
- COMPlusThrow(kArgumentOutOfRangeException, IDS_EE_COPY_OUTOFRANGE);
- }
-
- SIZE_T componentsize = psrc->GetComponentSize();
-
- memcpyNoGCRefs(pdst,
- componentsize*startindex + (BYTE*)(psrc->GetDataPtr()),
- componentsize*length);
-
- HELPER_METHOD_FRAME_END();
-}
-FCIMPLEND
-
-FCIMPL4(void, MarshalNative::CopyToManaged, LPVOID psrc, Object* pdstUNSAFE, INT32 startindex, INT32 length)
-{
- CONTRACTL
- {
- FCALL_CHECK;
- PRECONDITION(CheckPointer(psrc, NULL_OK));
- }
- CONTRACTL_END;
-
- // The BCL code guarantees that Array will be passed in
- _ASSERTE(!pdstUNSAFE || pdstUNSAFE->GetMethodTable()->IsArray());
-
- BASEARRAYREF pdst = (BASEARRAYREF)(OBJECTREF)pdstUNSAFE;
-
- HELPER_METHOD_FRAME_BEGIN_1(pdst);
-
- if (pdst == NULL)
- COMPlusThrowArgumentNull(W("destination"));
- if (psrc == NULL)
- COMPlusThrowArgumentNull(W("source"));
- if (startindex < 0)
- COMPlusThrowArgumentOutOfRange(W("startIndex"), W("ArgumentOutOfRange_Count"));
- if (length < 0)
- COMPlusThrowArgumentOutOfRange(W("length"), W("ArgumentOutOfRange_NeedNonNegNum"));
-
- SIZE_T numelem = pdst->GetNumComponents();
-
- if ((SIZE_T)startindex + (SIZE_T)length > numelem)
- {
- COMPlusThrow(kArgumentOutOfRangeException, IDS_EE_COPY_OUTOFRANGE);
- }
-
- SIZE_T componentsize = pdst->GetComponentSize();
-
- _ASSERTE(CorTypeInfo::IsPrimitiveType(pdst->GetArrayElementTypeHandle().GetInternalCorElementType()));
- memcpyNoGCRefs(componentsize*startindex + (BYTE*)(pdst->GetDataPtr()),
- psrc,
- componentsize*length);
-
- HELPER_METHOD_FRAME_END();
-}
-FCIMPLEND
-
-
/************************************************************************
* PInvoke.GetLastWin32Error
*/
@@ -696,7 +626,6 @@ FCIMPL3(VOID, MarshalNative::GCHandleInternalSet, OBJECTHANDLE handle, Object *o
OBJECTREF objRef(obj);
HELPER_METHOD_FRAME_BEGIN_1(objRef);
- //<TODO>@todo: If the handle is pinned check the object type.</TODO>
if (isPinned)
{
ValidatePinnedObject(objRef);
@@ -718,7 +647,6 @@ FCIMPL4(Object*, MarshalNative::GCHandleInternalCompareExchange, OBJECTHANDLE ha
LPVOID ret = NULL;
HELPER_METHOD_FRAME_BEGIN_RET_NOPOLL();
- //<TODO>@todo: If the handle is pinned check the object type.</TODO>
if (isPinned)
ValidatePinnedObject(newObjref);
@@ -766,52 +694,6 @@ FCIMPL1(INT32, MarshalNative::GCHandleInternalGetHandleType, OBJECTHANDLE handle
}
FCIMPLEND
-FCIMPL1(INT32, MarshalNative::CalculateCount, ArrayWithOffsetData* pArrayWithOffset)
-{
- FCALL_CONTRACT;
-
- INT32 uRetVal = 0;
- BASEARRAYREF arrayObj = pArrayWithOffset->m_Array;
- HELPER_METHOD_FRAME_BEGIN_RET_1(arrayObj);
-
- SIZE_T cbTotalSize = 0;
-
- if (arrayObj != NULL)
- {
- if (!(arrayObj->GetMethodTable()->IsArray()))
- COMPlusThrow(kArgumentException, IDS_EE_NOTISOMORPHIC);
- if (arrayObj->GetMethodTable()->IsMultiDimArray())
- COMPlusThrow(kArgumentException, IDS_EE_NOTISOMORPHIC);
-
- ValidatePinnedObject(arrayObj);
- }
-
- if (arrayObj == NULL)
- {
- if (pArrayWithOffset->m_cbOffset != 0)
- COMPlusThrow(kIndexOutOfRangeException, IDS_EE_ARRAYWITHOFFSETOVERFLOW);
-
- goto lExit;
- }
-
- cbTotalSize = arrayObj->GetNumComponents() * arrayObj->GetComponentSize();
-
- if (cbTotalSize > MAX_SIZE_FOR_INTEROP)
- COMPlusThrow(kArgumentException, IDS_EE_STRUCTARRAYTOOLARGE);
-
- if (pArrayWithOffset->m_cbOffset > (INT32)cbTotalSize)
- COMPlusThrow(kIndexOutOfRangeException, IDS_EE_ARRAYWITHOFFSETOVERFLOW);
-
- uRetVal = (INT32)cbTotalSize - pArrayWithOffset->m_cbOffset;
- _ASSERTE(uRetVal >= 0);
-
-lExit: ;
- HELPER_METHOD_FRAME_END();
- return uRetVal;
-}
-FCIMPLEND
-
-
//====================================================================
// *** Interop Helpers ***
//====================================================================