Skip to content

Commit

Permalink
Remove helper frames from MetadataImport class FCalls (#100939)
Browse files Browse the repository at this point in the history
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
  • Loading branch information
AaronRobinsonMSFT and jkotas authored Apr 21, 2024
1 parent 7e7c1f0 commit a3dc133
Show file tree
Hide file tree
Showing 12 changed files with 551 additions and 680 deletions.
348 changes: 202 additions & 146 deletions src/coreclr/System.Private.CoreLib/src/System/Reflection/MdImport.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2257,38 +2257,7 @@ internal static bool IsDefined(RuntimeFieldInfo field, RuntimeType? caType)
if (nativeType.Length == 0)
return null;

MetadataImport.GetMarshalAs(nativeType,
out UnmanagedType unmanagedType, out VarEnum safeArraySubType, out string? safeArrayUserDefinedTypeName, out UnmanagedType arraySubType, out int sizeParamIndex,
out int sizeConst, out string? marshalTypeName, out string? marshalCookie, out int iidParamIndex);

RuntimeType? safeArrayUserDefinedType = string.IsNullOrEmpty(safeArrayUserDefinedTypeName) ? null :
TypeNameParser.GetTypeReferencedByCustomAttribute(safeArrayUserDefinedTypeName, scope);
RuntimeType? marshalTypeRef = null;

try
{
marshalTypeRef = marshalTypeName is null ? null : TypeNameParser.GetTypeReferencedByCustomAttribute(marshalTypeName, scope);
}
catch (TypeLoadException)
{
// The user may have supplied a bad type name string causing this TypeLoadException
// Regardless, we return the bad type name
Debug.Assert(marshalTypeName is not null);
}

MarshalAsAttribute attribute = new MarshalAsAttribute(unmanagedType);

attribute.SafeArraySubType = safeArraySubType;
attribute.SafeArrayUserDefinedSubType = safeArrayUserDefinedType;
attribute.IidParameterIndex = iidParamIndex;
attribute.ArraySubType = arraySubType;
attribute.SizeParamIndex = (short)sizeParamIndex;
attribute.SizeConst = sizeConst;
attribute.MarshalType = marshalTypeName;
attribute.MarshalTypeRef = marshalTypeRef;
attribute.MarshalCookie = marshalCookie;

return attribute;
return MetadataImport.GetMarshalAs(nativeType, scope);
}

private static FieldOffsetAttribute? GetFieldOffsetCustomAttribute(RuntimeFieldInfo field)
Expand Down
10 changes: 4 additions & 6 deletions src/coreclr/ildasm/dis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,7 @@ void OpenScope(ISymUnmanagedScope *pIScope,
char* DumpUnicodeString(void* GUICookie,
__inout __nullterminated char* szString,
_In_reads_(cbString) WCHAR* pszString,
ULONG cbString,
bool SwapString )
ULONG cbString)
{
unsigned i,L;
char* szStr=NULL, *szRet = NULL;
Expand All @@ -750,8 +749,7 @@ char* DumpUnicodeString(void* GUICookie,
#endif

#if BIGENDIAN
if (SwapString)
SwapStringLength(pszString, cbString);
SwapStringLength(pszString, cbString);
#endif

// first, check for embedded zeros:
Expand Down Expand Up @@ -782,7 +780,7 @@ char* DumpUnicodeString(void* GUICookie,
strcat_s(szString,SZSTRING_SIZE," (");

#if BIGENDIAN
SwapStringLength(pszString, cbString);
SwapStringLength(pszString, cbString);
#endif
DumpByteArray(szString,(BYTE*)pszString,cbString*sizeof(WCHAR),GUICookie);
szRet = &szString[strlen(szString)];
Expand Down Expand Up @@ -2546,7 +2544,7 @@ void PrettyPrintToken(__inout __nullterminated char* szString, mdToken tk, IMDIn
}
if (pszString != NULL)
{
DumpUnicodeString(GUICookie,szString,(WCHAR *)pszString,cbString, true);
DumpUnicodeString(GUICookie,szString,(WCHAR *)pszString,cbString);
}
else
{
Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/ildasm/dis.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ void DumpVtable(void* GUICookie);
char* DumpUnicodeString(void* GUICookie,
__inout __nullterminated char* szString,
_In_reads_(cbString) WCHAR* pszString,
ULONG cbString,
bool SwapString = false);
ULONG cbString);

void TokenSigInit(IMDInternalImport *pImport);
void TokenSigDelete();
Expand Down
15 changes: 1 addition & 14 deletions src/coreclr/inc/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,19 +220,6 @@ struct HENUMInternal
//*****************************************
typedef struct _MDDefaultValue
{
#if BIGENDIAN
_MDDefaultValue(void)
{
m_bType = ELEMENT_TYPE_END;
}
~_MDDefaultValue(void)
{
if (m_bType == ELEMENT_TYPE_STRING)
{
delete[] m_wzValue;
}
}
#endif

// type of default value
BYTE m_bType; // CorElementType for the default value
Expand All @@ -251,7 +238,7 @@ typedef struct _MDDefaultValue
ULONGLONG m_ullValue; // ELEMENT_TYPE_UI8
FLOAT m_fltValue; // ELEMENT_TYPE_R4
DOUBLE m_dblValue; // ELEMENT_TYPE_R8
LPCWSTR m_wzValue; // ELEMENT_TYPE_STRING
LPCWSTR m_wzValue; // ELEMENT_TYPE_STRING - Little endian
IUnknown *m_unkValue; // ELEMENT_TYPE_CLASS
};
ULONG m_cbSize; // default value size (for blob)
Expand Down
13 changes: 0 additions & 13 deletions src/coreclr/md/runtime/mdinternalro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3147,7 +3147,6 @@ mdModule MDInternalRO::GetModuleFromScope(void)

//*****************************************************************************
// Fill a variant given a MDDefaultValue
// This routine will create a bstr if the ELEMENT_TYPE of default value is STRING
//*****************************************************************************
__checkReturn
HRESULT _FillMDDefaultValue(
Expand Down Expand Up @@ -3236,19 +3235,7 @@ HRESULT _FillMDDefaultValue(
if (cbValue == 0)
pValue = NULL;

#if BIGENDIAN
{
// We need to allocate and swap the string if we're on a big endian
// This allocation will be freed by the MDDefaultValue destructor.
pMDDefaultValue->m_wzValue = new WCHAR[(cbValue + 1) / sizeof (WCHAR)];
IfNullGo(pMDDefaultValue->m_wzValue);
memcpy(const_cast<WCHAR *>(pMDDefaultValue->m_wzValue), pValue, cbValue);
_ASSERTE(cbValue % sizeof(WCHAR) == 0);
SwapStringLength(const_cast<WCHAR *>(pMDDefaultValue->m_wzValue), cbValue / sizeof(WCHAR));
}
#else
pMDDefaultValue->m_wzValue = (LPWSTR) pValue;
#endif
break;
case ELEMENT_TYPE_CLASS:
//
Expand Down
5 changes: 0 additions & 5 deletions src/coreclr/vm/corelib.h
Original file line number Diff line number Diff line change
Expand Up @@ -604,11 +604,6 @@ DEFINE_METHOD(PROPERTY, GET_GETTER, GetGetMethod,

DEFINE_CLASS(PROPERTY_INFO, Reflection, PropertyInfo)



DEFINE_CLASS(METADATA_IMPORT, Reflection, MetadataImport)
DEFINE_METHOD(METADATA_IMPORT, THROW_ERROR, ThrowError, SM_Int_RetVoid)

DEFINE_CLASS(RESOLVER, System, Resolver)
DEFINE_METHOD(RESOLVER, GET_JIT_CONTEXT, GetJitContext, IM_RefInt_RetRuntimeType)
DEFINE_METHOD(RESOLVER, GET_CODE_INFO, GetCodeInfo, IM_RefInt_RefInt_RefInt_RetArrByte)
Expand Down
49 changes: 24 additions & 25 deletions src/coreclr/vm/ecalllist.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,31 +156,30 @@ FCFuncStart(gCOMTypeHandleFuncs)
FCFuncEnd()

FCFuncStart(gMetaDataImport)
FCFuncElement("_GetDefaultValue", MetaDataImport::GetDefaultValue)
FCFuncElement("_GetName", MetaDataImport::GetName)
FCFuncElement("_GetUserString", MetaDataImport::GetUserString)
FCFuncElement("_GetScopeProps", MetaDataImport::GetScopeProps)
FCFuncElement("_GetClassLayout", MetaDataImport::GetClassLayout)
FCFuncElement("_GetSignatureFromToken", MetaDataImport::GetSignatureFromToken)
FCFuncElement("_GetNamespace", MetaDataImport::GetNamespace)
FCFuncElement("_GetEventProps", MetaDataImport::GetEventProps)
FCFuncElement("_GetFieldDefProps", MetaDataImport::GetFieldDefProps)
FCFuncElement("_GetPropertyProps", MetaDataImport::GetPropertyProps)
FCFuncElement("_GetParentToken", MetaDataImport::GetParentToken)
FCFuncElement("_GetParamDefProps", MetaDataImport::GetParamDefProps)
FCFuncElement("_GetGenericParamProps", MetaDataImport::GetGenericParamProps)

FCFuncElement("_Enum", MetaDataImport::Enum)
FCFuncElement("_GetMemberRefProps", MetaDataImport::GetMemberRefProps)
FCFuncElement("_GetCustomAttributeProps", MetaDataImport::GetCustomAttributeProps)
FCFuncElement("_GetFieldOffset", MetaDataImport::GetFieldOffset)

FCFuncElement("_GetSigOfFieldDef", MetaDataImport::GetSigOfFieldDef)
FCFuncElement("_GetSigOfMethodDef", MetaDataImport::GetSigOfMethodDef)
FCFuncElement("_GetFieldMarshal", MetaDataImport::GetFieldMarshal)
FCFuncElement("_GetPInvokeMap", MetaDataImport::GetPinvokeMap)
FCFuncElement("_IsValidToken", MetaDataImport::IsValidToken)
FCFuncElement("_GetMarshalAs", MetaDataImport::GetMarshalAs)
FCFuncElement("GetDefaultValue", MetaDataImport::GetDefaultValue)
FCFuncElement("GetName", MetaDataImport::GetName)
FCFuncElement("GetUserString", MetaDataImport::GetUserString)
FCFuncElement("GetScopeProps", MetaDataImport::GetScopeProps)
FCFuncElement("GetClassLayout", MetaDataImport::GetClassLayout)
FCFuncElement("GetSignatureFromToken", MetaDataImport::GetSignatureFromToken)
FCFuncElement("GetNamespace", MetaDataImport::GetNamespace)
FCFuncElement("GetEventProps", MetaDataImport::GetEventProps)
FCFuncElement("GetFieldDefProps", MetaDataImport::GetFieldDefProps)
FCFuncElement("GetPropertyProps", MetaDataImport::GetPropertyProps)
FCFuncElement("GetParentToken", MetaDataImport::GetParentToken)
FCFuncElement("GetParamDefProps", MetaDataImport::GetParamDefProps)
FCFuncElement("GetGenericParamProps", MetaDataImport::GetGenericParamProps)

FCFuncElement("GetMemberRefProps", MetaDataImport::GetMemberRefProps)
FCFuncElement("GetCustomAttributeProps", MetaDataImport::GetCustomAttributeProps)
FCFuncElement("GetFieldOffset", MetaDataImport::GetFieldOffset)

FCFuncElement("GetSigOfFieldDef", MetaDataImport::GetSigOfFieldDef)
FCFuncElement("GetSigOfMethodDef", MetaDataImport::GetSigOfMethodDef)
FCFuncElement("GetFieldMarshal", MetaDataImport::GetFieldMarshal)
FCFuncElement("GetPInvokeMap", MetaDataImport::GetPInvokeMap)
FCFuncElement("IsValidToken", MetaDataImport::IsValidToken)
FCFuncElement("GetMarshalAs", MetaDataImport::GetMarshalAs)
FCFuncEnd()

FCFuncStart(gSignatureNative)
Expand Down
Loading

0 comments on commit a3dc133

Please sign in to comment.