| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | |
| 5 | // TODO: Re-implement with MC++ if we ever compile any mscorlib code with that |
| 6 | |
| 7 | |
| 8 | |
| 9 | #include "common.h" |
| 10 | #include "mlinfo.h" |
| 11 | #include "managedmdimport.hpp" |
| 12 | #include "wrappers.h" |
| 13 | |
| 14 | void ThrowMetaDataImportException(HRESULT hr) |
| 15 | { |
| 16 | WRAPPER_NO_CONTRACT; |
| 17 | |
| 18 | if (hr == CLDB_E_RECORD_NOTFOUND) |
| 19 | return; |
| 20 | |
| 21 | MethodDescCallSite throwError(METHOD__METADATA_IMPORT__THROW_ERROR); |
| 22 | |
| 23 | ARG_SLOT args[] = { hr }; |
| 24 | throwError.Call(args); |
| 25 | } |
| 26 | |
| 27 | // |
| 28 | // MetaDataImport |
| 29 | // |
| 30 | extern BOOL ParseNativeTypeInfo(NativeTypeParamInfo* pInfo, PCCOR_SIGNATURE pvNativeType, ULONG cbNativeType); |
| 31 | |
| 32 | FCIMPL11(void, MetaDataImport::GetMarshalAs, |
| 33 | BYTE* pvNativeType, |
| 34 | ULONG cbNativeType, |
| 35 | INT32* unmanagedType, |
| 36 | INT32* safeArraySubType, |
| 37 | STRINGREF* safeArrayUserDefinedSubType, |
| 38 | INT32* arraySubType, |
| 39 | INT32* sizeParamIndex, |
| 40 | INT32* sizeConst, |
| 41 | STRINGREF* marshalType, |
| 42 | STRINGREF* marshalCookie, |
| 43 | INT32* iidParamIndex) |
| 44 | { |
| 45 | FCALL_CONTRACT; |
| 46 | |
| 47 | HELPER_METHOD_FRAME_BEGIN_0(); |
| 48 | { |
| 49 | NativeTypeParamInfo info; |
| 50 | |
| 51 | ZeroMemory(&info, sizeof(NativeTypeParamInfo)); |
| 52 | |
| 53 | if (!ParseNativeTypeInfo(&info, pvNativeType, cbNativeType)) |
| 54 | { |
| 55 | ThrowMetaDataImportException(E_FAIL); |
| 56 | } |
| 57 | |
| 58 | *unmanagedType = info.m_NativeType; |
| 59 | *sizeParamIndex = info.m_CountParamIdx; |
| 60 | *sizeConst = info.m_Additive; |
| 61 | *arraySubType = info.m_ArrayElementType; |
| 62 | |
| 63 | #ifdef FEATURE_COMINTEROP |
| 64 | *iidParamIndex = info.m_IidParamIndex; |
| 65 | |
| 66 | *safeArraySubType = info.m_SafeArrayElementVT; |
| 67 | |
| 68 | *safeArrayUserDefinedSubType = info.m_strSafeArrayUserDefTypeName == NULL ? NULL : |
| 69 | StringObject::NewString(info.m_strSafeArrayUserDefTypeName, info.m_cSafeArrayUserDefTypeNameBytes); |
| 70 | #else |
| 71 | *iidParamIndex = 0; |
| 72 | |
| 73 | *safeArraySubType = VT_EMPTY; |
| 74 | |
| 75 | *safeArrayUserDefinedSubType = NULL; |
| 76 | #endif |
| 77 | |
| 78 | *marshalType = info.m_strCMMarshalerTypeName == NULL ? NULL : |
| 79 | StringObject::NewString(info.m_strCMMarshalerTypeName, info.m_cCMMarshalerTypeNameBytes); |
| 80 | |
| 81 | *marshalCookie = info.m_strCMCookie == NULL ? NULL : |
| 82 | StringObject::NewString(info.m_strCMCookie, info.m_cCMCookieStrBytes); |
| 83 | } |
| 84 | HELPER_METHOD_FRAME_END(); |
| 85 | } |
| 86 | FCIMPLEND |
| 87 | |
| 88 | MDImpl4(Object *, MetaDataImport::GetDefaultValue, mdToken tk, INT64* pDefaultValue, INT32* pLength, INT32* pCorElementType) |
| 89 | { |
| 90 | FCALL_CONTRACT; |
| 91 | |
| 92 | HRESULT hr = S_OK; |
| 93 | Object *pRetVal = NULL; |
| 94 | |
| 95 | BEGIN_SO_INTOLERANT_CODE_NOTHROW(GetThread(), FCThrow(kStackOverflowException)); |
| 96 | |
| 97 | IMDInternalImport *_pScope = pScope; |
| 98 | |
| 99 | MDDefaultValue value; |
| 100 | IfFailGo(_pScope->GetDefaultValue(tk, &value)); |
| 101 | |
| 102 | // We treat string values differently. That's because on big-endian architectures we can't return a |
| 103 | // pointer to static string data in the metadata, we have to buffer the string in order to byte-swap |
| 104 | // all the unicode characters. MDDefaultValue therefore has a destructor on big-endian machines which |
| 105 | // reclaims this buffer, implying we can't safely return the embedded pointer to managed code. |
| 106 | // The easiest thing for us to do is to construct the managed string object here, in the context of |
| 107 | // the still valid MDDefaultValue. We can't return a managed object via the normal out parameter |
| 108 | // because it won't be GC protected, so in this special case null the output parameter and return |
| 109 | // the string via the protected return result (which is null for all other cases). |
| 110 | if (value.m_bType == ELEMENT_TYPE_STRING) |
| 111 | { |
| 112 | HELPER_METHOD_FRAME_BEGIN_RET_0(); |
| 113 | *pDefaultValue = 0; |
| 114 | STRINGREF refRetval = StringObject::NewString(value.m_wzValue, value.m_cbSize / sizeof(WCHAR)); |
| 115 | pRetVal = STRINGREFToObject(refRetval); |
| 116 | HELPER_METHOD_FRAME_END(); |
| 117 | } |
| 118 | else |
| 119 | { |
| 120 | *pDefaultValue = value.m_ullValue; |
| 121 | } |
| 122 | |
| 123 | *pCorElementType = (UINT32)value.m_bType; |
| 124 | *pLength = (INT32)value.m_cbSize; |
| 125 | ErrExit: |
| 126 | END_SO_INTOLERANT_CODE; |
| 127 | |
| 128 | if (FAILED(hr)) |
| 129 | { |
| 130 | FCThrow(kBadImageFormatException); |
| 131 | } |
| 132 | |
| 133 | return pRetVal; |
| 134 | } |
| 135 | FCIMPLEND |
| 136 | |
| 137 | MDImpl3(void, MetaDataImport::GetCustomAttributeProps, mdCustomAttribute cv, mdToken* ptkType, ConstArray* ppBlob) |
| 138 | { |
| 139 | FCALL_CONTRACT; |
| 140 | |
| 141 | HRESULT hr = S_OK; |
| 142 | IMDInternalImport *_pScope = pScope; |
| 143 | |
| 144 | BEGIN_SO_INTOLERANT_CODE_NOTHROW(GetThread(), FCThrowVoid(kStackOverflowException)); |
| 145 | IfFailGo(_pScope->GetCustomAttributeProps(cv, ptkType)); |
| 146 | IfFailGo(_pScope->GetCustomAttributeAsBlob(cv, (const void **)&ppBlob->m_array, (ULONG *)&ppBlob->m_count)); |
| 147 | ErrExit: |
| 148 | END_SO_INTOLERANT_CODE; |
| 149 | |
| 150 | if (FAILED(hr)) |
| 151 | { |
| 152 | FCThrowVoid(kBadImageFormatException); |
| 153 | } |
| 154 | } |
| 155 | FCIMPLEND |
| 156 | |
| 157 | static int * EnsureResultSize(MetadataEnumResult * pResult, ULONG length) |
| 158 | { |
| 159 | CONTRACTL |
| 160 | { |
| 161 | THROWS; |
| 162 | GC_TRIGGERS; |
| 163 | MODE_COOPERATIVE; |
| 164 | } |
| 165 | CONTRACTL_END; |
| 166 | |
| 167 | int * p; |
| 168 | |
| 169 | if (length >= NumItems(pResult->smallResult) || DbgRandomOnExe(.01)) |
| 170 | { |
| 171 | pResult->largeResult = (I4Array *)OBJECTREFToObject(AllocatePrimitiveArray(ELEMENT_TYPE_I4, length)); |
| 172 | p = pResult->largeResult->GetDirectPointerToNonObjectElements(); |
| 173 | } |
| 174 | else |
| 175 | { |
| 176 | ZeroMemory(pResult->smallResult, sizeof(pResult->smallResult)); |
| 177 | p = pResult->smallResult; |
| 178 | } |
| 179 | |
| 180 | pResult->length = length; |
| 181 | return p; |
| 182 | } |
| 183 | |
| 184 | MDImpl3(void, MetaDataImport::Enum, mdToken type, mdToken tkParent, MetadataEnumResult * pResult) |
| 185 | { |
| 186 | CONTRACTL { |
| 187 | FCALL_CHECK; |
| 188 | PRECONDITION(pResult != NULL); |
| 189 | } |
| 190 | CONTRACTL_END; |
| 191 | |
| 192 | HELPER_METHOD_FRAME_BEGIN_0(); |
| 193 | { |
| 194 | IMDInternalImport *_pScope = pScope; |
| 195 | |
| 196 | if (type == mdtTypeDef) |
| 197 | { |
| 198 | ULONG nestedClassesCount; |
| 199 | IfFailThrow(_pScope->GetCountNestedClasses(tkParent, &nestedClassesCount)); |
| 200 | |
| 201 | mdTypeDef* arToken = (mdTypeDef*)EnsureResultSize(pResult, nestedClassesCount); |
| 202 | IfFailThrow(_pScope->GetNestedClasses(tkParent, arToken, nestedClassesCount, &nestedClassesCount)); |
| 203 | } |
| 204 | else if (type == mdtMethodDef && (TypeFromToken(tkParent) == mdtProperty || TypeFromToken(tkParent) == mdtEvent)) |
| 205 | { |
| 206 | HENUMInternalHolder hEnum(pScope); |
| 207 | hEnum.EnumAssociateInit(tkParent); |
| 208 | |
| 209 | ULONG associatesCount = hEnum.EnumGetCount(); |
| 210 | |
| 211 | static_assert_no_msg(sizeof(ASSOCIATE_RECORD) == 2 * sizeof(int)); |
| 212 | |
| 213 | ASSOCIATE_RECORD* arAssocRecord = (ASSOCIATE_RECORD*)EnsureResultSize(pResult, 2 * associatesCount); |
| 214 | IfFailThrow(_pScope->GetAllAssociates(&hEnum, arAssocRecord, associatesCount)); |
| 215 | } |
| 216 | else |
| 217 | { |
| 218 | HENUMInternalHolder hEnum(pScope); |
| 219 | hEnum.EnumInit(type, tkParent); |
| 220 | |
| 221 | ULONG count = hEnum.EnumGetCount(); |
| 222 | |
| 223 | mdToken* arToken = (mdToken*)EnsureResultSize(pResult, count); |
| 224 | for(COUNT_T i = 0; i < count && _pScope->EnumNext(&hEnum, &arToken[i]); i++); |
| 225 | } |
| 226 | } |
| 227 | HELPER_METHOD_FRAME_END(); |
| 228 | } |
| 229 | FCIMPLEND |
| 230 | |
| 231 | #if defined(_MSC_VER) && defined(_TARGET_X86_) |
| 232 | #pragma optimize("y", on) // Small critical routines, don't put in EBP frame |
| 233 | #endif |
| 234 | |
| 235 | MDImpl1(FC_BOOL_RET, MetaDataImport::IsValidToken, mdToken tk) |
| 236 | { |
| 237 | FCALL_CONTRACT; |
| 238 | |
| 239 | IMDInternalImport *_pScope = pScope; |
| 240 | |
| 241 | FC_RETURN_BOOL(_pScope->IsValidToken(tk)); |
| 242 | } |
| 243 | FCIMPLEND |
| 244 | |
| 245 | |
| 246 | MDImpl3(void, MetaDataImport::GetClassLayout, mdTypeDef td, DWORD* pdwPackSize, ULONG* pulClassSize) |
| 247 | { |
| 248 | FCALL_CONTRACT; |
| 249 | |
| 250 | HRESULT hr = S_OK; |
| 251 | |
| 252 | BEGIN_SO_INTOLERANT_CODE_NOTHROW(GetThread(), FCThrowVoid(kStackOverflowException)); |
| 253 | { |
| 254 | IMDInternalImport *_pScope = pScope; |
| 255 | |
| 256 | if (pdwPackSize != NULL) |
| 257 | { |
| 258 | hr = _pScope->GetClassPackSize(td, (ULONG *)pdwPackSize); |
| 259 | if (hr == CLDB_E_RECORD_NOTFOUND) |
| 260 | { |
| 261 | *pdwPackSize = 0; |
| 262 | hr = S_OK; |
| 263 | } |
| 264 | IfFailGo(hr); |
| 265 | } |
| 266 | |
| 267 | if (pulClassSize != NULL) |
| 268 | { |
| 269 | hr = _pScope->GetClassTotalSize(td, pulClassSize); |
| 270 | if (hr == CLDB_E_RECORD_NOTFOUND) |
| 271 | { |
| 272 | *pulClassSize = 0; |
| 273 | hr = S_OK; |
| 274 | } |
| 275 | IfFailGo(hr); |
| 276 | } |
| 277 | } |
| 278 | ErrExit: |
| 279 | END_SO_INTOLERANT_CODE; |
| 280 | |
| 281 | if (FAILED(hr)) |
| 282 | { |
| 283 | FCThrowVoid(kBadImageFormatException); |
| 284 | } |
| 285 | } |
| 286 | FCIMPLEND |
| 287 | |
| 288 | MDImpl3(FC_BOOL_RET, MetaDataImport::GetFieldOffset, mdTypeDef td, mdFieldDef target, DWORD* pdwFieldOffset) |
| 289 | { |
| 290 | FCALL_CONTRACT; |
| 291 | |
| 292 | HRESULT hr = S_OK; |
| 293 | IMDInternalImport *_pScope = pScope; |
| 294 | MD_CLASS_LAYOUT layout; |
| 295 | BOOL retVal = FALSE; |
| 296 | |
| 297 | BEGIN_SO_INTOLERANT_CODE_NOTHROW(GetThread(), FCThrow(kStackOverflowException)); |
| 298 | IfFailGo(_pScope->GetClassLayoutInit(td, &layout)); |
| 299 | |
| 300 | ULONG cFieldOffset; |
| 301 | cFieldOffset = layout.m_ridFieldEnd - layout.m_ridFieldCur; |
| 302 | |
| 303 | for (COUNT_T i = 0; i < cFieldOffset; i ++) |
| 304 | { |
| 305 | mdFieldDef fd; |
| 306 | ULONG offset; |
| 307 | IfFailGo(_pScope->GetClassLayoutNext(&layout, &fd, &offset)); |
| 308 | |
| 309 | if (fd == target) |
| 310 | { |
| 311 | *pdwFieldOffset = offset; |
| 312 | retVal = TRUE; |
| 313 | break; |
| 314 | } |
| 315 | } |
| 316 | ErrExit: |
| 317 | END_SO_INTOLERANT_CODE; |
| 318 | |
| 319 | if (FAILED(hr)) |
| 320 | { |
| 321 | FCThrow(kBadImageFormatException); |
| 322 | } |
| 323 | FC_RETURN_BOOL(retVal); |
| 324 | } |
| 325 | FCIMPLEND |
| 326 | |
| 327 | MDImpl3(void, MetaDataImport::GetUserString, mdToken tk, LPCSTR* pszName, ULONG* pCount) |
| 328 | { |
| 329 | FCALL_CONTRACT; |
| 330 | |
| 331 | HRESULT hr; |
| 332 | IMDInternalImport *_pScope = pScope; |
| 333 | BOOL bHasExtendedChars; |
| 334 | |
| 335 | BEGIN_SO_INTOLERANT_CODE_NOTHROW(GetThread(), FCThrowVoid(kStackOverflowException)); |
| 336 | hr = _pScope->GetUserString(tk, pCount, &bHasExtendedChars, (LPCWSTR *)pszName); |
| 337 | END_SO_INTOLERANT_CODE; |
| 338 | |
| 339 | if (FAILED(hr)) |
| 340 | { |
| 341 | FCThrowVoid(kBadImageFormatException); |
| 342 | } |
| 343 | } |
| 344 | FCIMPLEND |
| 345 | |
| 346 | MDImpl2(void, MetaDataImport::GetName, mdToken tk, LPCSTR* pszName) |
| 347 | { |
| 348 | FCALL_CONTRACT; |
| 349 | |
| 350 | HRESULT hr = S_OK; |
| 351 | IMDInternalImport *_pScope = pScope; |
| 352 | |
| 353 | BEGIN_SO_INTOLERANT_CODE_NOTHROW(GetThread(), FCThrowVoid(kStackOverflowException)); |
| 354 | if (TypeFromToken(tk) == mdtMethodDef) |
| 355 | { |
| 356 | hr = _pScope->GetNameOfMethodDef(tk, pszName); |
| 357 | } |
| 358 | else if (TypeFromToken(tk) == mdtParamDef) |
| 359 | { |
| 360 | USHORT seq; |
| 361 | DWORD attr; |
| 362 | hr = _pScope->GetParamDefProps(tk, &seq, &attr, pszName); |
| 363 | } |
| 364 | else if (TypeFromToken(tk) == mdtFieldDef) |
| 365 | { |
| 366 | hr = _pScope->GetNameOfFieldDef(tk, pszName); |
| 367 | } |
| 368 | else if (TypeFromToken(tk) == mdtProperty) |
| 369 | { |
| 370 | hr = _pScope->GetPropertyProps(tk, pszName, NULL, NULL, NULL); |
| 371 | } |
| 372 | else if (TypeFromToken(tk) == mdtEvent) |
| 373 | { |
| 374 | hr = _pScope->GetEventProps(tk, pszName, NULL, NULL); |
| 375 | } |
| 376 | else if (TypeFromToken(tk) == mdtModule) |
| 377 | { |
| 378 | hr = _pScope->GetModuleRefProps(tk, pszName); |
| 379 | } |
| 380 | else if (TypeFromToken(tk) == mdtTypeDef) |
| 381 | { |
| 382 | LPCSTR szNamespace = NULL; |
| 383 | hr = _pScope->GetNameOfTypeDef(tk, pszName, &szNamespace); |
| 384 | } |
| 385 | else |
| 386 | { |
| 387 | hr = E_FAIL; |
| 388 | } |
| 389 | END_SO_INTOLERANT_CODE; |
| 390 | |
| 391 | if (FAILED(hr)) |
| 392 | { |
| 393 | FCThrowVoid(kBadImageFormatException); |
| 394 | } |
| 395 | } |
| 396 | FCIMPLEND |
| 397 | |
| 398 | MDImpl2(void, MetaDataImport::GetNamespace, mdToken tk, LPCSTR* pszName) |
| 399 | { |
| 400 | FCALL_CONTRACT; |
| 401 | |
| 402 | HRESULT hr; |
| 403 | IMDInternalImport *_pScope = pScope; |
| 404 | LPCSTR szName = NULL; |
| 405 | |
| 406 | BEGIN_SO_INTOLERANT_CODE_NOTHROW(GetThread(), FCThrowVoid(kStackOverflowException)); |
| 407 | hr = _pScope->GetNameOfTypeDef(tk, &szName, pszName); |
| 408 | END_SO_INTOLERANT_CODE; |
| 409 | |
| 410 | if (FAILED(hr)) |
| 411 | { |
| 412 | FCThrowVoid(kBadImageFormatException); |
| 413 | } |
| 414 | } |
| 415 | FCIMPLEND |
| 416 | |
| 417 | |
| 418 | MDImpl2(void, MetaDataImport::GetGenericParamProps, mdToken tk, DWORD* pAttributes) |
| 419 | { |
| 420 | FCALL_CONTRACT; |
| 421 | |
| 422 | HRESULT hr; |
| 423 | IMDInternalImport *_pScope = pScope; |
| 424 | |
| 425 | BEGIN_SO_INTOLERANT_CODE_NOTHROW(GetThread(), FCThrowVoid(kStackOverflowException)); |
| 426 | hr = _pScope->GetGenericParamProps(tk, NULL, pAttributes, NULL, NULL, NULL); |
| 427 | END_SO_INTOLERANT_CODE; |
| 428 | |
| 429 | if (FAILED(hr)) |
| 430 | { |
| 431 | FCThrowVoid(kBadImageFormatException); |
| 432 | } |
| 433 | } |
| 434 | FCIMPLEND |
| 435 | |
| 436 | MDImpl3(void, MetaDataImport::GetEventProps, mdToken tk, LPCSTR* pszName, INT32 *pdwEventFlags) |
| 437 | { |
| 438 | FCALL_CONTRACT; |
| 439 | |
| 440 | HRESULT hr; |
| 441 | IMDInternalImport *_pScope = pScope; |
| 442 | |
| 443 | BEGIN_SO_INTOLERANT_CODE_NOTHROW(GetThread(), FCThrowVoid(kStackOverflowException)); |
| 444 | hr = _pScope->GetEventProps(tk, pszName, (DWORD*)pdwEventFlags, NULL); |
| 445 | END_SO_INTOLERANT_CODE; |
| 446 | |
| 447 | if (FAILED(hr)) |
| 448 | { |
| 449 | FCThrowVoid(kBadImageFormatException); |
| 450 | } |
| 451 | } |
| 452 | FCIMPLEND |
| 453 | |
| 454 | MDImpl4(void, MetaDataImport::GetPinvokeMap, mdToken tk, DWORD* pMappingFlags, LPCSTR* pszImportName, LPCSTR* pszImportDll) |
| 455 | { |
| 456 | FCALL_CONTRACT; |
| 457 | |
| 458 | HRESULT hr; |
| 459 | IMDInternalImport *_pScope = pScope; |
| 460 | mdModule tkModule; |
| 461 | |
| 462 | BEGIN_SO_INTOLERANT_CODE_NOTHROW(GetThread(), FCThrowVoid(kStackOverflowException)); |
| 463 | hr = _pScope->GetPinvokeMap(tk, pMappingFlags, pszImportName, &tkModule); |
| 464 | if (FAILED(hr)) |
| 465 | { |
| 466 | *pMappingFlags = 0; |
| 467 | *pszImportName = NULL; |
| 468 | *pszImportDll = NULL; |
| 469 | hr = S_OK; |
| 470 | } |
| 471 | else |
| 472 | { |
| 473 | hr = _pScope->GetModuleRefProps(tkModule, pszImportDll); |
| 474 | } |
| 475 | END_SO_INTOLERANT_CODE; |
| 476 | |
| 477 | if (FAILED(hr)) |
| 478 | { |
| 479 | FCThrowVoid(kBadImageFormatException); |
| 480 | } |
| 481 | } |
| 482 | FCIMPLEND |
| 483 | |
| 484 | MDImpl3(void, MetaDataImport::GetParamDefProps, mdToken tk, INT32* pSequence, INT32* pAttributes) |
| 485 | { |
| 486 | FCALL_CONTRACT; |
| 487 | |
| 488 | HRESULT hr; |
| 489 | IMDInternalImport *_pScope = pScope; |
| 490 | USHORT usSequence = 0; |
| 491 | |
| 492 | BEGIN_SO_INTOLERANT_CODE_NOTHROW(GetThread(), FCThrowVoid(kStackOverflowException)); |
| 493 | |
| 494 | // Is this a valid token? |
| 495 | if (_pScope->IsValidToken((mdParamDef)tk)) |
| 496 | { |
| 497 | LPCSTR szParamName; |
| 498 | hr = _pScope->GetParamDefProps(tk, &usSequence, (DWORD *)pAttributes, &szParamName); |
| 499 | } |
| 500 | else |
| 501 | { |
| 502 | // Invalid token - throw an exception |
| 503 | hr = COR_E_BADIMAGEFORMAT; |
| 504 | } |
| 505 | *pSequence = (INT32) usSequence; |
| 506 | END_SO_INTOLERANT_CODE; |
| 507 | |
| 508 | if (FAILED(hr)) |
| 509 | { |
| 510 | FCThrowVoid(kBadImageFormatException); |
| 511 | } |
| 512 | } |
| 513 | FCIMPLEND |
| 514 | |
| 515 | MDImpl2(void, MetaDataImport::GetFieldDefProps, mdToken tk, INT32 *pdwFieldFlags) |
| 516 | { |
| 517 | FCALL_CONTRACT; |
| 518 | |
| 519 | HRESULT hr; |
| 520 | IMDInternalImport *_pScope = pScope; |
| 521 | |
| 522 | BEGIN_SO_INTOLERANT_CODE_NOTHROW(GetThread(), FCThrowVoid(kStackOverflowException)); |
| 523 | hr = _pScope->GetFieldDefProps(tk, (DWORD *)pdwFieldFlags); |
| 524 | END_SO_INTOLERANT_CODE; |
| 525 | |
| 526 | if (FAILED(hr)) |
| 527 | { |
| 528 | FCThrowVoid(kBadImageFormatException); |
| 529 | } |
| 530 | } |
| 531 | FCIMPLEND |
| 532 | |
| 533 | MDImpl4(void, MetaDataImport::GetPropertyProps, mdToken tk, LPCSTR* pszName, INT32 *pdwPropertyFlags, ConstArray* ppValue) |
| 534 | { |
| 535 | FCALL_CONTRACT; |
| 536 | |
| 537 | HRESULT hr; |
| 538 | IMDInternalImport *_pScope = pScope; |
| 539 | |
| 540 | BEGIN_SO_INTOLERANT_CODE_NOTHROW(GetThread(), FCThrowVoid(kStackOverflowException)); |
| 541 | hr = _pScope->GetPropertyProps(tk, pszName, (DWORD*)pdwPropertyFlags, (PCCOR_SIGNATURE*)&ppValue->m_array, (ULONG*)&ppValue->m_count); |
| 542 | END_SO_INTOLERANT_CODE; |
| 543 | |
| 544 | if (FAILED(hr)) |
| 545 | { |
| 546 | FCThrowVoid(kBadImageFormatException); |
| 547 | } |
| 548 | } |
| 549 | FCIMPLEND |
| 550 | |
| 551 | MDImpl2(void, MetaDataImport::GetFieldMarshal, mdToken tk, ConstArray* ppValue) |
| 552 | { |
| 553 | FCALL_CONTRACT; |
| 554 | |
| 555 | HRESULT hr; |
| 556 | IMDInternalImport *_pScope = pScope; |
| 557 | |
| 558 | BEGIN_SO_INTOLERANT_CODE_NOTHROW(GetThread(), FCThrowVoid(kStackOverflowException)); |
| 559 | hr = _pScope->GetFieldMarshal(tk, (PCCOR_SIGNATURE *)&ppValue->m_array, (ULONG *)&ppValue->m_count); |
| 560 | if (hr == CLDB_E_RECORD_NOTFOUND) |
| 561 | { |
| 562 | ppValue->m_array = NULL; |
| 563 | ppValue->m_count = 0; |
| 564 | hr = S_OK; |
| 565 | } |
| 566 | END_SO_INTOLERANT_CODE; |
| 567 | |
| 568 | if (FAILED(hr)) |
| 569 | { |
| 570 | FCThrowVoid(kBadImageFormatException); |
| 571 | } |
| 572 | } |
| 573 | FCIMPLEND |
| 574 | |
| 575 | MDImpl2(void, MetaDataImport::GetSigOfMethodDef, mdToken tk, ConstArray* ppValue) |
| 576 | { |
| 577 | FCALL_CONTRACT; |
| 578 | |
| 579 | HRESULT hr; |
| 580 | IMDInternalImport *_pScope = pScope; |
| 581 | |
| 582 | BEGIN_SO_INTOLERANT_CODE(GetThread()) |
| 583 | hr = _pScope->GetSigOfMethodDef(tk, (ULONG*)&ppValue->m_count, (PCCOR_SIGNATURE *)&ppValue->m_array); |
| 584 | END_SO_INTOLERANT_CODE; |
| 585 | |
| 586 | if (FAILED(hr)) |
| 587 | { |
| 588 | FCThrowVoid(kBadImageFormatException); |
| 589 | } |
| 590 | } |
| 591 | FCIMPLEND |
| 592 | |
| 593 | MDImpl2(void, MetaDataImport::GetSignatureFromToken, mdToken tk, ConstArray* ppValue) |
| 594 | { |
| 595 | FCALL_CONTRACT; |
| 596 | |
| 597 | HRESULT hr; |
| 598 | IMDInternalImport *_pScope = pScope; |
| 599 | |
| 600 | BEGIN_SO_INTOLERANT_CODE_NOTHROW(GetThread(), FCThrowVoid(kStackOverflowException)); |
| 601 | hr = _pScope->GetSigFromToken(tk, (ULONG*)&ppValue->m_count, (PCCOR_SIGNATURE *)&(ppValue->m_array)); |
| 602 | END_SO_INTOLERANT_CODE; |
| 603 | |
| 604 | if (FAILED(hr)) |
| 605 | { |
| 606 | FCThrowVoid(kBadImageFormatException); |
| 607 | } |
| 608 | } |
| 609 | FCIMPLEND |
| 610 | |
| 611 | MDImpl2(void, MetaDataImport::GetSigOfFieldDef, mdToken tk, ConstArray* ppValue) |
| 612 | { |
| 613 | FCALL_CONTRACT; |
| 614 | |
| 615 | HRESULT hr; |
| 616 | IMDInternalImport *_pScope = pScope; |
| 617 | |
| 618 | BEGIN_SO_INTOLERANT_CODE_NOTHROW(GetThread(), FCThrowVoid(kStackOverflowException)); |
| 619 | hr = _pScope->GetSigOfFieldDef(tk, (ULONG*)&ppValue->m_count, (PCCOR_SIGNATURE *)&ppValue->m_array); |
| 620 | END_SO_INTOLERANT_CODE; |
| 621 | |
| 622 | if (FAILED(hr)) |
| 623 | { |
| 624 | FCThrowVoid(kBadImageFormatException); |
| 625 | } |
| 626 | } |
| 627 | FCIMPLEND |
| 628 | |
| 629 | MDImpl2(void, MetaDataImport::GetParentToken, mdToken tk, mdToken* ptk) |
| 630 | { |
| 631 | FCALL_CONTRACT; |
| 632 | |
| 633 | HRESULT hr; |
| 634 | IMDInternalImport *_pScope = pScope; |
| 635 | |
| 636 | BEGIN_SO_INTOLERANT_CODE_NOTHROW(GetThread(), FCThrowVoid(kStackOverflowException)); |
| 637 | |
| 638 | switch (TypeFromToken(tk)) |
| 639 | { |
| 640 | case mdtTypeDef: |
| 641 | hr = _pScope->GetNestedClassProps(tk, ptk); |
| 642 | if (hr == CLDB_E_RECORD_NOTFOUND) |
| 643 | { |
| 644 | *ptk = mdTypeDefNil; |
| 645 | hr = S_OK; |
| 646 | } |
| 647 | break; |
| 648 | |
| 649 | case mdtGenericParam: |
| 650 | hr = _pScope->GetGenericParamProps(tk, NULL, NULL, ptk, NULL, NULL); |
| 651 | break; |
| 652 | |
| 653 | case mdtMethodDef: |
| 654 | case mdtMethodSpec: |
| 655 | case mdtFieldDef: |
| 656 | case mdtParamDef: |
| 657 | case mdtMemberRef: |
| 658 | case mdtCustomAttribute: |
| 659 | case mdtEvent: |
| 660 | case mdtProperty: |
| 661 | hr = _pScope->GetParentToken(tk, ptk); |
| 662 | break; |
| 663 | |
| 664 | default: |
| 665 | hr = COR_E_BADIMAGEFORMAT; |
| 666 | break; |
| 667 | } |
| 668 | |
| 669 | END_SO_INTOLERANT_CODE; |
| 670 | |
| 671 | if (FAILED(hr)) |
| 672 | { |
| 673 | FCThrowVoid(kBadImageFormatException); |
| 674 | } |
| 675 | } |
| 676 | FCIMPLEND |
| 677 | |
| 678 | MDImpl1(void, MetaDataImport::GetScopeProps, GUID* pmvid) |
| 679 | { |
| 680 | FCALL_CONTRACT; |
| 681 | |
| 682 | HRESULT hr; |
| 683 | LPCSTR szName; |
| 684 | |
| 685 | BEGIN_SO_INTOLERANT_CODE_NOTHROW(GetThread(), FCThrowVoid(kStackOverflowException)); |
| 686 | IMDInternalImport *_pScope = pScope; |
| 687 | hr = _pScope->GetScopeProps(&szName, pmvid); |
| 688 | END_SO_INTOLERANT_CODE; |
| 689 | |
| 690 | if (FAILED(hr)) |
| 691 | { |
| 692 | FCThrowVoid(kBadImageFormatException); |
| 693 | } |
| 694 | } |
| 695 | FCIMPLEND |
| 696 | |
| 697 | |
| 698 | MDImpl2(void, MetaDataImport::GetMemberRefProps, |
| 699 | mdMemberRef mr, |
| 700 | ConstArray* ppvSigBlob) |
| 701 | { |
| 702 | FCALL_CONTRACT; |
| 703 | |
| 704 | HRESULT hr; |
| 705 | IMDInternalImport *_pScope = pScope; |
| 706 | LPCSTR szName_Ignore; |
| 707 | |
| 708 | BEGIN_SO_INTOLERANT_CODE_NOTHROW(GetThread(), FCThrowVoid(kStackOverflowException)); |
| 709 | hr = _pScope->GetNameAndSigOfMemberRef(mr, (PCCOR_SIGNATURE*)&ppvSigBlob->m_array, (ULONG*)&ppvSigBlob->m_count, &szName_Ignore); |
| 710 | END_SO_INTOLERANT_CODE; |
| 711 | |
| 712 | if (FAILED(hr)) |
| 713 | { |
| 714 | FCThrowVoid(kBadImageFormatException); |
| 715 | } |
| 716 | } |
| 717 | FCIMPLEND |
| 718 | |
| 719 | #if defined(_MSC_VER) && defined(_TARGET_X86_) |
| 720 | #pragma optimize("", on) // restore command line optimization defaults |
| 721 | #endif |
| 722 | |
| 723 | |