IFACEMETHODIMP CanvasCommandList::CreateDrawingSession( ICanvasDrawingSession** drawingSession) { return ExceptionBoundary( [&] { CheckAndClearOutPointer(drawingSession); if (m_d2dCommandListIsClosed) ThrowHR(E_INVALIDARG, Strings::CommandListCannotBeDrawnToAfterItHasBeenUsed); if (*m_hasActiveDrawingSession) ThrowHR(E_FAIL, Strings::CannotCreateDrawingSessionUntilPreviousOneClosed); auto& d2dCommandList = GetResource(); auto& device = m_device.EnsureNotClosed(); auto deviceContext = As<ICanvasDeviceInternal>(device)->CreateDeviceContextForDrawingSession(); deviceContext->SetTarget(d2dCommandList.Get()); auto adapter = std::make_shared<SimpleCanvasDrawingSessionAdapter>(deviceContext.Get()); auto ds = CanvasDrawingSession::CreateNew(deviceContext.Get(), adapter, device.Get(), m_hasActiveDrawingSession); ThrowIfFailed(ds.CopyTo(drawingSession)); }); }
static void ThrowIfInvalidTrimmingDelimiter(HSTRING value) { // The delimiter must be a single code point and so cannot be more than // 2 UTF-16 code units long if (WindowsGetStringLen(value) > 2) ThrowHR(E_INVALIDARG); }
static void ThrowIfInvalidFontWeight(ABI::Windows::UI::Text::FontWeight value) { if (value.Weight >= 1 && value.Weight <= 999) return; ThrowHR(E_INVALIDARG); }
// Set the stackwalker to the specified CONTEXT. void DacDbiInterfaceImpl::SetStackWalkCurrentContext(VMPTR_Thread vmThread, StackWalkHandle pSFIHandle, CorDebugSetContextFlag flag, DT_CONTEXT * pContext) { DD_ENTER_MAY_THROW; StackFrameIterator * pIter = GetIteratorFromHandle(pSFIHandle); REGDISPLAY * pRD = GetRegDisplayFromHandle(pSFIHandle); #if defined(_DEBUG) // The caller should have checked this already. _ASSERTE(CheckContext(vmThread, pContext) == S_OK); #endif // _DEBUG // DD can't keep pointers back into the RS address space. // Allocate a context in DDImpl's memory space. DDImpl can't contain raw pointers back into // the client space since that may not marshal. T_CONTEXT * pContext2 = GetContextBufferFromHandle(pSFIHandle); *pContext2 = *reinterpret_cast<T_CONTEXT *>(pContext); // memcpy // update the REGDISPLAY with the given CONTEXT. // Be sure that the context is in DDImpl's memory space and not the Right-sides. FillRegDisplay(pRD, pContext2); BOOL fSuccess = pIter->ResetRegDisp(pRD, (flag == SET_CONTEXT_FLAG_ACTIVE_FRAME)); if (!fSuccess) { // ResetRegDisp() may fail for the same reason Init() may fail, i.e. // because the stackwalker tries to unwind one frame ahead of time, // or because the stackwalker needs to filter out some frames based on the stackwalk flags. ThrowHR(E_FAIL); } }
ComPtr<ID2D1Image> CanvasCommandList::GetD2DImage( ICanvasDevice*, ID2D1DeviceContext*, GetImageFlags, float /*targetDpi*/, float* realizedDpi) { auto& commandList = GetResource(); if (!m_d2dCommandListIsClosed) { HRESULT hr = commandList->Close(); // D2DERR_WRONG_STATE means that this CL was already closed. This // might happen if we were interopping with an existing // D2D1CommandList. We ignore this error. if (hr != D2DERR_WRONG_STATE && FAILED(hr)) ThrowHR(hr); m_d2dCommandListIsClosed = true; } if (realizedDpi) *realizedDpi = 0; return commandList; }
// in DAC builds, we don't actually acquire the lock, we just determine whether the LS // already holds it. If so, we assume the data is inconsistent and throw an exception. // Argument: // input: s - the lock to be checked. // Note: Throws static void AcquireReadLock(SimpleRWLock *s) { SUPPORTS_DAC; if (s->IsWriterLock()) { ThrowHR(CORDBG_E_PROCESS_NOT_SYNCHRONIZED); } };
// Gets a CordbModule that has the given metadata interface // // Arguments: // pIMetaData - metadata interface // // Returns: // CordbModule whose associated metadata matches the metadata interface provided here // Throws on error. Returns non-null // CordbModule * CordbAppDomain::GetModuleFromMetaDataInterface(IUnknown *pIMetaData) { HRESULT hr = S_OK; RSExtSmartPtr<IMetaDataImport> pImport; RSLockHolder lockHolder(GetProcess()->GetProcessLock()); // need for module enumeration // Grab the interface we need... hr = pIMetaData->QueryInterface(IID_IMetaDataImport, (void**)&pImport); if (FAILED(hr)) { ThrowHR(E_INVALIDARG); } // Get the mvid of the given module. GUID matchMVID; hr = pImport->GetScopeProps(NULL, 0, 0, &matchMVID); IfFailThrow(hr); CordbModule* pModule; HASHFIND findmodule; PrepopulateModules(); for (pModule = m_modules.FindFirst(&findmodule); pModule != NULL; pModule = m_modules.FindNext(&findmodule)) { IMetaDataImport * pImportCurrent = pModule->GetMetaDataImporter(); // throws _ASSERTE(pImportCurrent != NULL); // Get the mvid of this module GUID MVID; hr = pImportCurrent->GetScopeProps(NULL, 0, 0, &MVID); IfFailThrow(hr); if (MVID == matchMVID) { return pModule; } } ThrowHR(E_INVALIDARG); }
// Called by ResourceWrapper::Close, to remove itself from the interop mapping table. void ResourceManager::Remove(IUnknown* resource) { ComPtr<IUnknown> resourceIdentity = AsUnknown(resource); std::lock_guard<std::recursive_mutex> lock(m_mutex); auto result = m_resources.erase(resourceIdentity.Get()); if (result != 1) ThrowHR(E_UNEXPECTED); }
// Called by the ResourceWrapper constructor, to add itself to the interop mapping table. void ResourceManager::Add(IUnknown* resource, IInspectable* wrapper) { ComPtr<IUnknown> resourceIdentity = AsUnknown(resource); std::lock_guard<std::recursive_mutex> lock(m_mutex); auto result = m_resources.insert(std::make_pair(resourceIdentity.Get(), AsWeak(wrapper))); if (!result.second) ThrowHR(E_UNEXPECTED); }
DWRITE_TEXT_ALIGNMENT ToTextAlignment(ABI::Windows::UI::Text::ParagraphAlignment value) { switch (value) { case ABI::Windows::UI::Text::ParagraphAlignment_Left: return DWRITE_TEXT_ALIGNMENT_LEADING; case ABI::Windows::UI::Text::ParagraphAlignment_Center: return DWRITE_TEXT_ALIGNMENT_CENTER; case ABI::Windows::UI::Text::ParagraphAlignment_Right: return DWRITE_TEXT_ALIGNMENT_TRAILING; case ABI::Windows::UI::Text::ParagraphAlignment_Justify: return DWRITE_TEXT_ALIGNMENT_JUSTIFIED; default: ThrowHR(E_INVALIDARG); } }
static CanvasTextDirection ToCanvasTextDirection(DWRITE_READING_DIRECTION value) { switch (value) { case DWRITE_READING_DIRECTION_LEFT_TO_RIGHT: return CanvasTextDirection::LeftToRight; case DWRITE_READING_DIRECTION_RIGHT_TO_LEFT: return CanvasTextDirection::RightToLeft; case DWRITE_READING_DIRECTION_TOP_TO_BOTTOM: return CanvasTextDirection::TopToBottom; case DWRITE_READING_DIRECTION_BOTTOM_TO_TOP: return CanvasTextDirection::BottomToTop; default: ThrowHR(E_INVALIDARG); } }
static ABI::Windows::UI::Text::ParagraphAlignment ToWindowsParagraphAlignment(DWRITE_TEXT_ALIGNMENT value) { switch (value) { case DWRITE_TEXT_ALIGNMENT_LEADING: return ABI::Windows::UI::Text::ParagraphAlignment_Left; case DWRITE_TEXT_ALIGNMENT_CENTER: return ABI::Windows::UI::Text::ParagraphAlignment_Center; case DWRITE_TEXT_ALIGNMENT_TRAILING: return ABI::Windows::UI::Text::ParagraphAlignment_Right; case DWRITE_TEXT_ALIGNMENT_JUSTIFIED: return ABI::Windows::UI::Text::ParagraphAlignment_Justify; default: ThrowHR(E_INVALIDARG); } }
static DWRITE_READING_DIRECTION ToReadingDirection(CanvasTextDirection value) { switch (value) { case CanvasTextDirection::LeftToRight: return DWRITE_READING_DIRECTION_LEFT_TO_RIGHT; case CanvasTextDirection::RightToLeft: return DWRITE_READING_DIRECTION_RIGHT_TO_LEFT; case CanvasTextDirection::TopToBottom: return DWRITE_READING_DIRECTION_TOP_TO_BOTTOM; case CanvasTextDirection::BottomToTop: return DWRITE_READING_DIRECTION_BOTTOM_TO_TOP; default: ThrowHR(E_INVALIDARG); } }
static void ThrowIfInvalid(CanvasLineSpacingMethod value) { switch (value) { case CanvasLineSpacingMethod::Default: case CanvasLineSpacingMethod::Uniform: return; default: ThrowHR(E_INVALIDARG); } }
static void ThrowIfInvalid(CanvasTextTrimmingGranularity value) { switch (value) { case CanvasTextTrimmingGranularity::None: case CanvasTextTrimmingGranularity::Character: case CanvasTextTrimmingGranularity::Word: return; default: ThrowHR(E_INVALIDARG); } }
static void ThrowIfInvalid(ABI::Windows::UI::Text::FontStyle value) { switch (value) { case ABI::Windows::UI::Text::FontStyle_Normal: case ABI::Windows::UI::Text::FontStyle_Oblique: case ABI::Windows::UI::Text::FontStyle_Italic: return; default: ThrowHR(E_INVALIDARG); } }
void ResourceManager::ValidateDpi(ICanvasResourceWrapperWithDpi* wrapper, float dpi) { if (dpi != 0) { float wrapperDpi; ThrowIfFailed(wrapper->get_Dpi(&wrapperDpi)); if (dpi != wrapperDpi) { ThrowHR(E_INVALIDARG, Strings::ResourceManagerWrongDpi); } } }
void ResourceManager::ValidateDevice(ICanvasResourceWrapperWithDevice* wrapper, ICanvasDevice* device) { if (device) { ComPtr<ICanvasDevice> wrapperDevice; ThrowIfFailed(wrapper->get_Device(&wrapperDevice)); if (device != wrapperDevice.Get()) { ThrowHR(E_INVALIDARG, Strings::ResourceManagerWrongDevice); } } }
static void ThrowIfInvalid(CanvasVerticalAlignment value) { switch (value) { case CanvasVerticalAlignment::Top: case CanvasVerticalAlignment::Bottom: case CanvasVerticalAlignment::Center: return; default: ThrowHR(E_INVALIDARG); } }
int GetVersionResilientTypeHashCode(IMDInternalImport *pMDImport, mdExportedType token) { _ASSERTE(TypeFromToken(token) == mdtTypeDef || TypeFromToken(token) == mdtTypeRef || TypeFromToken(token) == mdtExportedType); _ASSERTE(!IsNilToken(token)); HRESULT hr; LPCUTF8 szNamespace; LPCUTF8 szName; bool hasTypeToken = true; int hashcode = 0; while (hasTypeToken) { if (IsNilToken(token)) ThrowHR(COR_E_BADIMAGEFORMAT); switch (TypeFromToken(token)) { case mdtTypeDef: if (FAILED(pMDImport->GetNameOfTypeDef(token, &szName, &szNamespace))) ThrowHR(COR_E_BADIMAGEFORMAT); hr = pMDImport->GetNestedClassProps(token, &token); if (hr == CLDB_E_RECORD_NOTFOUND) hasTypeToken = false; else if (FAILED(hr)) ThrowHR(COR_E_BADIMAGEFORMAT); break; case mdtTypeRef: if (FAILED(pMDImport->GetNameOfTypeRef(token, &szNamespace, &szName))) ThrowHR(COR_E_BADIMAGEFORMAT); if (FAILED(pMDImport->GetResolutionScopeOfTypeRef(token, &token))) ThrowHR(COR_E_BADIMAGEFORMAT); hasTypeToken = (TypeFromToken(token) == mdtTypeRef); break; case mdtExportedType: if (FAILED(pMDImport->GetExportedTypeProps(token, &szNamespace, &szName, &token, NULL, NULL))) ThrowHR(COR_E_BADIMAGEFORMAT); hasTypeToken = (TypeFromToken(token) == mdtExportedType); break; default: ThrowHR(COR_E_BADIMAGEFORMAT); } hashcode ^= ComputeNameHashCode(szNamespace, szName); } return hashcode; }
static void ThrowIfInvalid(CanvasTextDirection value) { switch (value) { case CanvasTextDirection::TopToBottom: case CanvasTextDirection::BottomToTop: case CanvasTextDirection::LeftToRight: case CanvasTextDirection::RightToLeft: return; default: ThrowHR(E_INVALIDARG); } }
ZapBlobWithRelocs * ZapBlobWithRelocs::NewBlob(ZapWriter * pWriter, PVOID pData, SIZE_T cbSize) { S_SIZE_T cbAllocSize = S_SIZE_T(sizeof(ZapBlobWithRelocs)) + S_SIZE_T(cbSize); if(cbAllocSize.IsOverflow()) ThrowHR(COR_E_OVERFLOW); void * pMemory = new (pWriter->GetHeap()) BYTE[cbAllocSize.Value()]; ZapBlobWithRelocs * pZapBlobWithRelocs = new (pMemory) ZapBlobWithRelocs(cbSize); if (pData != NULL) memcpy((void*)(pZapBlobWithRelocs + 1), pData, cbSize); return pZapBlobWithRelocs; }
static void ThrowIfInvalid(ABI::Windows::UI::Text::ParagraphAlignment value) { switch (value) { case ABI::Windows::UI::Text::ParagraphAlignment_Undefined: case ABI::Windows::UI::Text::ParagraphAlignment_Left: case ABI::Windows::UI::Text::ParagraphAlignment_Center: case ABI::Windows::UI::Text::ParagraphAlignment_Right: case ABI::Windows::UI::Text::ParagraphAlignment_Justify: return; default: ThrowHR(E_INVALIDARG); } }
static ZapBlobWithRelocs * NewBlob(ZapWriter * pWriter, PVOID pData, SIZE_T cbSize) { S_SIZE_T cbAllocSize = S_SIZE_T(sizeof(ZapAlignedBlobWithRelocsConst<alignment>)) + S_SIZE_T(cbSize); if(cbAllocSize.IsOverflow()) ThrowHR(COR_E_OVERFLOW); void * pMemory = new (pWriter->GetHeap()) BYTE[cbAllocSize.Value()]; ZapAlignedBlobWithRelocsConst<alignment> * pZapBlob = new (pMemory) ZapAlignedBlobWithRelocsConst<alignment>(cbSize); if (pData != NULL) memcpy((void*)(pZapBlob + 1), pData, cbSize); return pZapBlob; }
static void ThrowIfInvalid(CanvasWordWrapping value) { switch (value) { case CanvasWordWrapping::Wrap: case CanvasWordWrapping::NoWrap: case CanvasWordWrapping::EmergencyBreak: case CanvasWordWrapping::WholeWord: case CanvasWordWrapping::Character: return; default: ThrowHR(E_INVALIDARG); } }
FCIMPLEND #endif // !FEATURE_CORECLR FCIMPL4(void, AssemblyNameNative::Init, Object * refThisUNSAFE, OBJECTREF * pAssemblyRef, CLR_BOOL fForIntrospection, CLR_BOOL fRaiseResolveEvent) { FCALL_CONTRACT; ASSEMBLYNAMEREF pThis = (ASSEMBLYNAMEREF) (OBJECTREF) refThisUNSAFE; HRESULT hr = S_OK; HELPER_METHOD_FRAME_BEGIN_1(pThis); *pAssemblyRef = NULL; if (pThis == NULL) COMPlusThrow(kNullReferenceException, W("NullReference_This")); Thread * pThread = GetThread(); CheckPointHolder cph(pThread->m_MarshalAlloc.GetCheckpoint()); //hold checkpoint for autorelease AssemblySpec spec; hr = spec.InitializeSpec(&(pThread->m_MarshalAlloc), (ASSEMBLYNAMEREF *) &pThis, TRUE, FALSE); if (SUCCEEDED(hr)) { spec.AssemblyNameInit(&pThis,NULL); } else if ((hr == FUSION_E_INVALID_NAME) && fRaiseResolveEvent) { Assembly * pAssembly = GetAppDomain()->RaiseAssemblyResolveEvent(&spec, fForIntrospection, FALSE); if (pAssembly == NULL) { EEFileLoadException::Throw(&spec, hr); } else { *((OBJECTREF *) (&(*pAssemblyRef))) = pAssembly->GetExposedObject(); } } else { ThrowHR(hr); } HELPER_METHOD_FRAME_END(); }
IFACEMETHODIMP CanvasTextFormat::put_Options(CanvasDrawTextOptions value) { return ExceptionBoundary( [&] { ThrowIfClosed(); auto validOptions = CanvasDrawTextOptions::NoSnap | CanvasDrawTextOptions::Clip | CanvasDrawTextOptions::EnableColorFont; if ((value & ~validOptions) != CanvasDrawTextOptions::Default) ThrowHR(E_INVALIDARG); m_drawTextOptions = value; }); }
STDMETHOD (GetAssemblyDependencies)( BSTR pAssemblyName, SAFEARRAY **pDependencies, DWORD *assemblyNGenSetting, BSTR *pNativeImageIdentity, BSTR *pAssemblyDisplayName, SAFEARRAY **pDependencyLoadSetting, SAFEARRAY **pDependencyNGenSetting ) { SO_NOT_MAINLINE_FUNCTION; _ASSERTE(zapper != NULL); _ASSERTE(pNativeImageIdentity); HRESULT hr = S_OK; EX_TRY { GUID nativeImageSign = INVALID_NGEN_SIGNATURE; zapper->ComputeDependencies(pAssemblyName, &nativeImageSign); BSTRHolder displayNameHolder(::SysAllocString(zapper->m_assemblyDependencies.GetDisplayName())); *pDependencies = zapper->m_assemblyDependencies.GetSAFEARRAY(); *assemblyNGenSetting = zapper->m_assemblyDependencies.GetNGenHint(); *pDependencyLoadSetting = zapper->m_assemblyDependencies.GetLoadHintSAFEARRAY(); *pDependencyNGenSetting = zapper->m_assemblyDependencies.GetNGenHintSAFEARRAY(); if (nativeImageSign != INVALID_NGEN_SIGNATURE) { WCHAR szGuid[64]; if (GuidToLPWSTR(nativeImageSign, szGuid, sizeof(szGuid) / sizeof(WCHAR)) == 0) { ThrowHR(E_UNEXPECTED); } *pNativeImageIdentity = ::SysAllocString(szGuid); } *pAssemblyDisplayName = displayNameHolder.Extract(); } EX_CATCH_HRESULT_AND_NGEN_CLEAN(hr); return hr; }
static void ThrowIfInvalid(ABI::Windows::UI::Text::FontStretch value) { switch (value) { case ABI::Windows::UI::Text::FontStretch_Undefined: case ABI::Windows::UI::Text::FontStretch_UltraCondensed: case ABI::Windows::UI::Text::FontStretch_ExtraCondensed: case ABI::Windows::UI::Text::FontStretch_Condensed: case ABI::Windows::UI::Text::FontStretch_SemiCondensed: case ABI::Windows::UI::Text::FontStretch_Normal: case ABI::Windows::UI::Text::FontStretch_SemiExpanded: case ABI::Windows::UI::Text::FontStretch_Expanded: case ABI::Windows::UI::Text::FontStretch_ExtraExpanded: case ABI::Windows::UI::Text::FontStretch_UltraExpanded: return; default: ThrowHR(E_INVALIDARG); } }
void SvcLogger::LogHelper(SString s, CorSvcLogLevel logLevel) { CheckInit(); pss->Append(s); // Does s contain a newline? SString::Iterator i = pss->Begin(); if (pss->FindASCII(i, "\n")) { if (pCorSvcLogger) { BSTRHolder bstrHolder(::SysAllocString(pss->GetUnicode())); // Can't use the IfFailThrow macro here because in checked // builds that macros will try to log an error message // that will recursively return to this method. HRESULT hr = pCorSvcLogger->Log(logLevel, bstrHolder); if (FAILED(hr)) ThrowHR(hr); } pss->Clear(); } }