/*=============================GetArrayMethodToken============================== **Action: **Returns: **Arguments: REFLECTMODULEBASEREF refThis ** U1ARRAYREF sig ** STRINGREF methodName ** int tkTypeSpec **Exceptions: ==============================================================================*/ INT32 QCALLTYPE COMModule::GetArrayMethodToken(QCall::ModuleHandle pModule, INT32 tkTypeSpec, LPCWSTR wszMethodName, LPCBYTE pSignature, INT32 sigLength) { QCALL_CONTRACT; mdMemberRef memberRefE = mdTokenNil; BEGIN_QCALL; if (!wszMethodName) COMPlusThrow(kArgumentNullException, W("ArgumentNull_String")); if (!tkTypeSpec) COMPlusThrow(kArgumentNullException, W("ArgumentNull_Type")); RefClassWriter * pRCW = pModule->GetReflectionModule()->GetClassWriter(); _ASSERTE(pRCW); HRESULT hr = pRCW->GetEmitter()->DefineMemberRef(tkTypeSpec, wszMethodName, (PCCOR_SIGNATURE)pSignature, sigLength, &memberRefE); if (FAILED(hr)) { _ASSERTE(!"Failed on DefineMemberRef"); COMPlusThrowHR(hr); } END_QCALL; return (INT32)memberRefE; }
FCIMPLEND FCIMPL0(StringObject*, SystemNative::GetRuntimeDirectory) { FCALL_CONTRACT; STRINGREF refRetVal = NULL; DWORD dwFile = MAX_LONGPATH+1; HELPER_METHOD_FRAME_BEGIN_RET_1(refRetVal); SString wszFilePathString; WCHAR * wszFile = wszFilePathString.OpenUnicodeBuffer(dwFile); HRESULT hr = GetInternalSystemDirectory(wszFile, &dwFile); wszFilePathString.CloseBuffer(dwFile); if(FAILED(hr)) COMPlusThrowHR(hr); dwFile--; // remove the trailing NULL if(dwFile) refRetVal = StringObject::NewString(wszFile, dwFile); HELPER_METHOD_FRAME_END(); return (StringObject*)OBJECTREFToObject(refRetVal); }
INT32 QCALLTYPE COMDynamicWrite::DefineType(QCall::ModuleHandle pModule, LPCWSTR wszFullName, INT32 tkParent, INT32 attributes, INT32 tkEnclosingType, INT32 * pInterfaceTokens) { QCALL_CONTRACT; mdTypeDef classE = mdTokenNil; BEGIN_QCALL; RefClassWriter * pRCW = pModule->GetReflectionModule()->GetClassWriter(); _ASSERTE(pRCW); HRESULT hr; if (RidFromToken(tkEnclosingType)) { // defining nested type hr = pRCW->GetEmitter()->DefineNestedType(wszFullName, attributes, tkParent == 0 ? mdTypeRefNil : tkParent, (mdToken *)pInterfaceTokens, tkEnclosingType, &classE); } else { // top level type hr = pRCW->GetEmitter()->DefineTypeDef(wszFullName, attributes, tkParent == 0 ? mdTypeRefNil : tkParent, (mdToken *)pInterfaceTokens, &classE); } if (hr == META_S_DUPLICATE) { COMPlusThrow(kArgumentException, W("Argument_DuplicateTypeName")); } if (FAILED(hr)) { _ASSERTE(hr == E_OUTOFMEMORY || !"DefineTypeDef Failed"); COMPlusThrowHR(hr); } AllocMemTracker amTracker; pModule->GetClassLoader()->AddAvailableClassDontHaveLock(pModule, classE, &amTracker); amTracker.SuppressRelease(); END_QCALL; return (INT32)classE; }
void DECLSPEC_NORETURN COMIsolatedStorage::ThrowISS(HRESULT hr) { STANDARD_VM_CONTRACT; if ((hr >= ISS_E_ISOSTORE_START) && (hr <= ISS_E_ISOSTORE_END)) { switch (hr) { case ISS_E_ISOSTORE : case ISS_E_OPEN_STORE_FILE : case ISS_E_OPEN_FILE_MAPPING : case ISS_E_MAP_VIEW_OF_FILE : case ISS_E_GET_FILE_SIZE : case ISS_E_CREATE_MUTEX : case ISS_E_LOCK_FAILED : case ISS_E_FILE_WRITE : case ISS_E_SET_FILE_POINTER : case ISS_E_CREATE_DIR : case ISS_E_CORRUPTED_STORE_FILE : case ISS_E_STORE_VERSION : case ISS_E_FILE_NOT_MAPPED : case ISS_E_BLOCK_SIZE_TOO_SMALL : case ISS_E_ALLOC_TOO_LARGE : case ISS_E_USAGE_WILL_EXCEED_QUOTA : case ISS_E_TABLE_ROW_NOT_FOUND : case ISS_E_DEPRECATE : case ISS_E_CALLER : case ISS_E_PATH_LENGTH : case ISS_E_MACHINE : case ISS_E_STORE_NOT_OPEN : case ISS_E_MACHINE_DACL : COMPlusThrowHR(hr); break; default : _ASSERTE(!"Unknown hr"); } } COMPlusThrowHR(hr); }
FCIMPLEND //************************************************** // LoadInMemoryTypeByName // Explicitly loading an in memory type // <TODO>@todo: this function is not dealing with nested type correctly yet. // We will need to parse the full name by finding "+" for enclosing type, etc.</TODO> //************************************************** void QCALLTYPE COMModule::LoadInMemoryTypeByName(QCall::ModuleHandle pModule, LPCWSTR wszFullName) { QCALL_CONTRACT; TypeHandle typeHnd; BEGIN_QCALL; if (!pModule->IsReflection()) COMPlusThrow(kNotSupportedException, W("NotSupported_NonReflectedType")); RefClassWriter * pRCW = pModule->GetReflectionModule()->GetClassWriter(); _ASSERTE(pRCW); // it is ok to use public import API because this is a dynamic module anyway. We are also receiving Unicode full name as // parameter. IMetaDataImport * pImport = pRCW->GetRWImporter(); if (wszFullName == NULL) IfFailThrow( E_FAIL ); // look up the handle mdTypeDef td; HRESULT hr = pImport->FindTypeDefByName(wszFullName, mdTokenNil, &td); if (FAILED(hr)) { if (hr != CLDB_E_RECORD_NOTFOUND) COMPlusThrowHR(hr); // Get the UTF8 version of strFullName MAKE_UTF8PTR_FROMWIDE(szFullName, wszFullName); pModule->GetAssembly()->ThrowTypeLoadException(szFullName, IDS_CLASSLOAD_GENERAL); } TypeKey typeKey(pModule, td); typeHnd = pModule->GetClassLoader()->LoadTypeHandleForTypeKey(&typeKey, TypeHandle()); END_QCALL; return; }
FCIMPLEND #ifndef FEATURE_CORECLR FCIMPL1(Object*, AssemblyNameNative::EscapeCodeBase, StringObject* filenameUNSAFE) { FCALL_CONTRACT; STRINGREF rv = NULL; STRINGREF filename = (STRINGREF) filenameUNSAFE; HELPER_METHOD_FRAME_BEGIN_RET_1(filename); LPWSTR pCodeBase = NULL; DWORD dwCodeBase = 0; CQuickBytes qb; if (filename != NULL) { WCHAR* pString; int iString; filename->RefInterpretGetStringValuesDangerousForGC(&pString, &iString); dwCodeBase = (DWORD) iString; pCodeBase = (LPWSTR) qb.AllocThrows((++dwCodeBase) * sizeof(WCHAR)); memcpy(pCodeBase, pString, dwCodeBase*sizeof(WCHAR)); } if(pCodeBase) { CQuickBytes qb2; DWORD dwEscaped = 1; DWORD flags = 0; if (RunningOnWin7()) flags |= URL_ESCAPE_AS_UTF8; UrlEscape(pCodeBase, (LPWSTR) qb2.Ptr(), &dwEscaped, flags); LPWSTR result = (LPWSTR)qb2.AllocThrows((++dwEscaped) * sizeof(WCHAR)); HRESULT hr = UrlEscape(pCodeBase, result, &dwEscaped, flags); if (SUCCEEDED(hr)) rv = StringObject::NewString(result); else COMPlusThrowHR(hr); } HELPER_METHOD_FRAME_END(); return OBJECTREFToObject(rv); }
FCIMPLEND FCIMPL1(Object*, AssemblyNameNative::GetPublicKeyToken, Object* refThisUNSAFE) { FCALL_CONTRACT; OBJECTREF orOutputArray = NULL; OBJECTREF refThis = (OBJECTREF) refThisUNSAFE; HELPER_METHOD_FRAME_BEGIN_RET_1(refThis); if (refThis == NULL) COMPlusThrow(kNullReferenceException, W("NullReference_This")); ASSEMBLYNAMEREF orThis = (ASSEMBLYNAMEREF)refThis; U1ARRAYREF orPublicKey = orThis->GetPublicKey(); if (orPublicKey != NULL) { DWORD cb = orPublicKey->GetNumComponents(); StrongNameBufferHolder<BYTE> pbToken; if (cb) { CQuickBytes qb; BYTE *pbKey = (BYTE*) qb.AllocThrows(cb); memcpy(pbKey, orPublicKey->GetDataPtr(), cb); { GCX_PREEMP(); if (!StrongNameTokenFromPublicKey(pbKey, cb, &pbToken, &cb)) COMPlusThrowHR(StrongNameErrorInfo()); } } Security::CopyEncodingToByteArray(pbToken, cb, &orOutputArray); } HELPER_METHOD_FRAME_END(); return OBJECTREFToObject(orOutputArray); }
FCIMPL2(void, COMCurrency::DoToDecimal, DECIMAL * result, CY c) { FCALL_CONTRACT; // GC could only happen when exception is thrown, no need to protect result HELPER_METHOD_FRAME_BEGIN_0(); _ASSERTE(result); HRESULT hr = VarDecFromCy(c, result); if (FAILED(hr)) { // Didn't expect to get here. Update code for this HR. _ASSERTE(S_OK == hr); COMPlusThrowHR(hr); } if (FAILED(DecimalCanonicalize(result))) COMPlusThrow(kOverflowException, W("Overflow_Currency")); result->wReserved = 0; HELPER_METHOD_FRAME_END(); }