Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Koritzinsky <jekoritz@microsoft.com>2021-06-16 23:55:33 +0300
committerGitHub <noreply@github.com>2021-06-16 23:55:33 +0300
commitccc3d9f1c4fd2b5d42225b6b85fca8493b5103c1 (patch)
tree97e5262d0f6a14cde4b3a879aefbe534510e3cc5 /src/coreclr/vm
parent42a764d6fc407d325c08b355990f9c9f0a5ed422 (diff)
Remove the `sealed` blittable layoutclass correctness fix because of backcompat. (#54235)
Diffstat (limited to 'src/coreclr/vm')
-rw-r--r--src/coreclr/vm/classlayoutinfo.cpp8
-rw-r--r--src/coreclr/vm/ilmarshalers.cpp8
-rw-r--r--src/coreclr/vm/mlinfo.cpp11
3 files changed, 9 insertions, 18 deletions
diff --git a/src/coreclr/vm/classlayoutinfo.cpp b/src/coreclr/vm/classlayoutinfo.cpp
index 612c119be79..07667804110 100644
--- a/src/coreclr/vm/classlayoutinfo.cpp
+++ b/src/coreclr/vm/classlayoutinfo.cpp
@@ -653,12 +653,8 @@ VOID EEClassLayoutInfo::CollectLayoutFieldMetadataThrowing(
DEBUGARG(szName)
);
- // Type is blittable only if parent is also blittable and is not empty.
- if (isBlittable && fHasNonTrivialParent)
- {
- isBlittable = pParentMT->IsBlittable() // Check parent
- && (!pParentLayoutInfo || !pParentLayoutInfo->IsZeroSized()); // Ensure non-zero size
- }
+ // Type is blittable only if parent is also blittable
+ isBlittable = isBlittable && (fHasNonTrivialParent ? pParentMT->IsBlittable() : TRUE);
pEEClassLayoutInfoOut->SetIsBlittable(isBlittable);
S_UINT32 cbSortArraySize = S_UINT32(cTotalFields) * S_UINT32(sizeof(LayoutRawFieldInfo*));
diff --git a/src/coreclr/vm/ilmarshalers.cpp b/src/coreclr/vm/ilmarshalers.cpp
index 5c7517b2884..163222d423d 100644
--- a/src/coreclr/vm/ilmarshalers.cpp
+++ b/src/coreclr/vm/ilmarshalers.cpp
@@ -2496,10 +2496,14 @@ void ILBlittablePtrMarshaler::EmitConvertContentsNativeToCLR(ILCodeStream* pslIL
bool ILBlittablePtrMarshaler::CanMarshalViaPinning()
{
+ // [COMPAT] For correctness, we can't marshal via pinning if we might need to marshal differently at runtime.
+ // See calls to EmitExactTypeCheck where we check the runtime type of the object being marshalled.
+ // However, we previously supported pinning non-sealed blittable classes, even though that could result
+ // in some data still being unmarshalled if a subclass is provided. This optimization is incorrect,
+ // but libraries like NAudio have taken a hard dependency on this incorrect behavior, so we need to preserve it.
return IsCLRToNative(m_dwMarshalFlags) &&
!IsByref(m_dwMarshalFlags) &&
- !IsFieldMarshal(m_dwMarshalFlags) &&
- m_pargs->m_pMT->IsSealed(); // We can't marshal via pinning if we might need to marshal differently at runtime. See calls to EmitExactTypeCheck where we check the runtime type of the object being marshalled.
+ !IsFieldMarshal(m_dwMarshalFlags);
}
void ILBlittablePtrMarshaler::EmitMarshalViaPinning(ILCodeStream* pslILEmit)
diff --git a/src/coreclr/vm/mlinfo.cpp b/src/coreclr/vm/mlinfo.cpp
index 57ee8a4825b..487dd236767 100644
--- a/src/coreclr/vm/mlinfo.cpp
+++ b/src/coreclr/vm/mlinfo.cpp
@@ -1138,8 +1138,6 @@ MarshalInfo::MarshalInfo(Module* pModule,
CorElementType corElemType = ELEMENT_TYPE_END;
m_pMT = NULL;
m_pMD = pMD;
- // [Compat] For backward compatibility reasons, some marshalers imply [In, Out] behavior when marked as [In], [Out], or not marked with either.
- BOOL byValAlwaysInOut = FALSE;
#ifdef FEATURE_COMINTEROP
m_fDispItf = FALSE;
@@ -1884,7 +1882,6 @@ MarshalInfo::MarshalInfo(Module* pModule,
}
m_type = IsFieldScenario() ? MARSHAL_TYPE_BLITTABLE_LAYOUTCLASS : MARSHAL_TYPE_BLITTABLEPTR;
m_args.m_pMT = m_pMT;
- byValAlwaysInOut = TRUE;
}
else if (m_pMT->HasLayout())
{
@@ -2377,13 +2374,7 @@ lExit:
}
}
- if (!m_byref && byValAlwaysInOut)
- {
- // Some marshalers expect [In, Out] behavior with [In], [Out], or no directional attributes.
- m_in = TRUE;
- m_out = TRUE;
- }
- else if (!m_in && !m_out)
+ if (!m_in && !m_out)
{
// If neither IN nor OUT are true, this signals the URT to use the default
// rules.