| 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 | |
| 6 | // |
| 7 | // --------------------------------------------------------------------------- |
| 8 | // Ex.cpp |
| 9 | // --------------------------------------------------------------------------- |
| 10 | |
| 11 | #include "stdafx.h" |
| 12 | #include "string.h" |
| 13 | #include "ex.h" |
| 14 | #include "holder.h" |
| 15 | |
| 16 | // error codes |
| 17 | #include "corerror.h" |
| 18 | |
| 19 | #include "../dlls/mscorrc/resource.h" |
| 20 | |
| 21 | #include "olectl.h" |
| 22 | |
| 23 | #include "corexcep.h" |
| 24 | |
| 25 | #define MAX_EXCEPTION_MSG 200 |
| 26 | |
| 27 | // Set if fatal error (like stack overflow or out of memory) occurred in this process. |
| 28 | GVAL_IMPL_INIT(HRESULT, g_hrFatalError, S_OK); |
| 29 | |
| 30 | // Helper function to get an exception object from outside the exception. In |
| 31 | // the CLR, it may be from the Thread object. Non-CLR users have no thread object, |
| 32 | // and it will do nothing. |
| 33 | void GetLastThrownObjectExceptionFromThread(void **ppvException); |
| 34 | |
| 35 | Exception *Exception::g_OOMException = NULL; |
| 36 | |
| 37 | // avoid global constructors |
| 38 | static BYTE g_OOMExceptionInstance[sizeof(OutOfMemoryException)]; |
| 39 | |
| 40 | Exception * Exception::GetOOMException() |
| 41 | { |
| 42 | LIMITED_METHOD_CONTRACT; |
| 43 | |
| 44 | if (!g_OOMException) { |
| 45 | // Create a local copy on the stack and then copy it over to the static instance. |
| 46 | // This avoids race conditions caused by multiple initializations of vtable in the constructor |
| 47 | |
| 48 | OutOfMemoryException local(TRUE); // Construct a "preallocated" instance. |
| 49 | memcpy((void*)&g_OOMExceptionInstance, (void*)&local, sizeof(OutOfMemoryException)); |
| 50 | |
| 51 | g_OOMException = (OutOfMemoryException*)&g_OOMExceptionInstance; |
| 52 | } |
| 53 | |
| 54 | return g_OOMException; |
| 55 | } |
| 56 | |
| 57 | /*virtual*/ Exception *OutOfMemoryException::Clone() |
| 58 | { |
| 59 | LIMITED_METHOD_CONTRACT; |
| 60 | |
| 61 | return GetOOMException(); |
| 62 | } |
| 63 | |
| 64 | //------------------------------------------------------------------------------ |
| 65 | void Exception::Delete(Exception* pvMemory) |
| 66 | { |
| 67 | CONTRACTL |
| 68 | { |
| 69 | GC_NOTRIGGER; |
| 70 | NOTHROW; |
| 71 | SO_TOLERANT; |
| 72 | SUPPORTS_DAC_HOST_ONLY; // Exceptions aren't currently marshalled by DAC - just used in the host |
| 73 | } |
| 74 | CONTRACTL_END; |
| 75 | |
| 76 | if ((pvMemory == 0) || pvMemory->IsPreallocatedException()) |
| 77 | { |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | ::delete((Exception *) pvMemory); |
| 82 | } |
| 83 | |
| 84 | void Exception::GetMessage(SString &result) |
| 85 | { |
| 86 | WRAPPER_NO_CONTRACT; |
| 87 | |
| 88 | return GenerateTopLevelHRExceptionMessage(GetHR(), result); |
| 89 | } |
| 90 | |
| 91 | void HRMsgException::GetMessage(SString &result) |
| 92 | { |
| 93 | WRAPPER_NO_CONTRACT; |
| 94 | |
| 95 | if (m_msg.IsEmpty()) |
| 96 | HRException::GetMessage(result); |
| 97 | else |
| 98 | result = m_msg; |
| 99 | } |
| 100 | |
| 101 | Exception *Exception::Clone() |
| 102 | { |
| 103 | CONTRACTL |
| 104 | { |
| 105 | GC_NOTRIGGER; |
| 106 | THROWS; |
| 107 | } |
| 108 | CONTRACTL_END; |
| 109 | |
| 110 | NewHolder<Exception> retExcep(CloneHelper()); |
| 111 | if (m_innerException) |
| 112 | { |
| 113 | retExcep->m_innerException = m_innerException->Clone(); |
| 114 | } |
| 115 | |
| 116 | retExcep.SuppressRelease(); |
| 117 | return retExcep; |
| 118 | } |
| 119 | |
| 120 | Exception *Exception::CloneHelper() |
| 121 | { |
| 122 | StackSString s; |
| 123 | GetMessage(s); |
| 124 | return new HRMsgException(GetHR(), s); |
| 125 | } |
| 126 | |
| 127 | Exception *Exception::DomainBoundClone() |
| 128 | { |
| 129 | CONTRACTL |
| 130 | { |
| 131 | // Because we may call DomainBoundCloneHelper() of ObjrefException or CLRLastThrownObjectException |
| 132 | // this should be GC_TRIGGERS, but we can not include EE contracts in Utilcode. |
| 133 | THROWS; |
| 134 | } |
| 135 | CONTRACTL_END; |
| 136 | |
| 137 | NewHolder<Exception> retExcep(DomainBoundCloneHelper()); |
| 138 | if (m_innerException) |
| 139 | { |
| 140 | retExcep->m_innerException = m_innerException->DomainBoundClone(); |
| 141 | } |
| 142 | |
| 143 | retExcep.SuppressRelease(); |
| 144 | return retExcep; |
| 145 | } |
| 146 | |
| 147 | BOOL Exception::IsTerminal() |
| 148 | { |
| 149 | CONTRACTL |
| 150 | { |
| 151 | GC_NOTRIGGER; |
| 152 | NOTHROW; |
| 153 | |
| 154 | // CLRException::GetHR() can eventually call BaseDomain::CreateHandle(), |
| 155 | // which can indirectly cause a lock if we get a miss in the handle table |
| 156 | // cache (TableCacheMissOnAlloc). Since CLRException::GetHR() is virtual, |
| 157 | // SCAN won't find this for you (though 40 minutes of one of the sql stress |
| 158 | // tests will :-)) |
| 159 | CAN_TAKE_LOCK; |
| 160 | } |
| 161 | CONTRACTL_END; |
| 162 | |
| 163 | HRESULT hr = GetHR(); |
| 164 | return (COR_E_THREADABORTED == hr); |
| 165 | } |
| 166 | |
| 167 | BOOL Exception::IsTransient() |
| 168 | { |
| 169 | WRAPPER_NO_CONTRACT; |
| 170 | |
| 171 | return IsTransient(GetHR()); |
| 172 | } |
| 173 | |
| 174 | /* static */ |
| 175 | BOOL Exception::IsTransient(HRESULT hr) |
| 176 | { |
| 177 | LIMITED_METHOD_CONTRACT; |
| 178 | |
| 179 | return (hr == COR_E_THREADABORTED |
| 180 | || hr == COR_E_THREADINTERRUPTED |
| 181 | || hr == COR_E_THREADSTOP |
| 182 | || hr == COR_E_APPDOMAINUNLOADED |
| 183 | || hr == E_OUTOFMEMORY |
| 184 | || hr == HRESULT_FROM_WIN32(ERROR_COMMITMENT_LIMIT) // ran out of room in pagefile |
| 185 | || hr == HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY) |
| 186 | || hr == (HRESULT)STATUS_NO_MEMORY |
| 187 | || hr == COR_E_STACKOVERFLOW |
| 188 | || hr == MSEE_E_ASSEMBLYLOADINPROGRESS); |
| 189 | } |
| 190 | |
| 191 | //------------------------------------------------------------------------------ |
| 192 | // Functions to manage the preallocated exceptions. |
| 193 | // Virtual |
| 194 | BOOL Exception::IsPreallocatedException() |
| 195 | { // Most exceptions can't be preallocated. If they can be, their class |
| 196 | // should provide a virtual override of this function. |
| 197 | return FALSE; |
| 198 | } |
| 199 | |
| 200 | BOOL Exception::IsPreallocatedOOMException() |
| 201 | { // This is the preallocated OOM if it is preallocated and is OOM. |
| 202 | return IsPreallocatedException() && (GetInstanceType() == OutOfMemoryException::GetType()); |
| 203 | } |
| 204 | |
| 205 | //------------------------------------------------------------------------------ |
| 206 | #ifdef _PREFAST_ |
| 207 | #pragma warning(push) |
| 208 | #pragma warning(disable:21000) // Suppress PREFast warning about overly large function |
| 209 | #endif |
| 210 | LPCSTR Exception::GetHRSymbolicName(HRESULT hr) |
| 211 | { |
| 212 | LIMITED_METHOD_CONTRACT; |
| 213 | |
| 214 | #define CASE_HRESULT(hrname) case hrname: return #hrname; |
| 215 | |
| 216 | switch (hr) |
| 217 | { |
| 218 | CASE_HRESULT(S_OK)// 0x00000000L |
| 219 | CASE_HRESULT(S_FALSE)// 0x00000001L |
| 220 | |
| 221 | CASE_HRESULT(E_UNEXPECTED)// 0x8000FFFFL |
| 222 | CASE_HRESULT(E_NOTIMPL)// 0x80004001L |
| 223 | CASE_HRESULT(E_OUTOFMEMORY)// 0x8007000EL |
| 224 | CASE_HRESULT(E_INVALIDARG)// 0x80070057L |
| 225 | CASE_HRESULT(E_NOINTERFACE)// 0x80004002L |
| 226 | CASE_HRESULT(E_POINTER)// 0x80004003L |
| 227 | CASE_HRESULT(E_HANDLE)// 0x80070006L |
| 228 | CASE_HRESULT(E_ABORT)// 0x80004004L |
| 229 | CASE_HRESULT(E_FAIL)// 0x80004005L |
| 230 | CASE_HRESULT(E_ACCESSDENIED)// 0x80070005L |
| 231 | |
| 232 | #ifdef FEATURE_COMINTEROP |
| 233 | CASE_HRESULT(CO_E_INIT_TLS)// 0x80004006L |
| 234 | CASE_HRESULT(CO_E_INIT_SHARED_ALLOCATOR)// 0x80004007L |
| 235 | CASE_HRESULT(CO_E_INIT_MEMORY_ALLOCATOR)// 0x80004008L |
| 236 | CASE_HRESULT(CO_E_INIT_CLASS_CACHE)// 0x80004009L |
| 237 | CASE_HRESULT(CO_E_INIT_RPC_CHANNEL)// 0x8000400AL |
| 238 | CASE_HRESULT(CO_E_INIT_TLS_SET_CHANNEL_CONTROL)// 0x8000400BL |
| 239 | CASE_HRESULT(CO_E_INIT_TLS_CHANNEL_CONTROL)// 0x8000400CL |
| 240 | CASE_HRESULT(CO_E_INIT_UNACCEPTED_USER_ALLOCATOR)// 0x8000400DL |
| 241 | CASE_HRESULT(CO_E_INIT_SCM_MUTEX_EXISTS)// 0x8000400EL |
| 242 | CASE_HRESULT(CO_E_INIT_SCM_FILE_MAPPING_EXISTS)// 0x8000400FL |
| 243 | CASE_HRESULT(CO_E_INIT_SCM_MAP_VIEW_OF_FILE)// 0x80004010L |
| 244 | CASE_HRESULT(CO_E_INIT_SCM_EXEC_FAILURE)// 0x80004011L |
| 245 | CASE_HRESULT(CO_E_INIT_ONLY_SINGLE_THREADED)// 0x80004012L |
| 246 | |
| 247 | // ****************** |
| 248 | // FACILITY_ITF |
| 249 | // ****************** |
| 250 | |
| 251 | CASE_HRESULT(OLE_E_OLEVERB)// 0x80040000L |
| 252 | CASE_HRESULT(OLE_E_ADVF)// 0x80040001L |
| 253 | CASE_HRESULT(OLE_E_ENUM_NOMORE)// 0x80040002L |
| 254 | CASE_HRESULT(OLE_E_ADVISENOTSUPPORTED)// 0x80040003L |
| 255 | CASE_HRESULT(OLE_E_NOCONNECTION)// 0x80040004L |
| 256 | CASE_HRESULT(OLE_E_NOTRUNNING)// 0x80040005L |
| 257 | CASE_HRESULT(OLE_E_NOCACHE)// 0x80040006L |
| 258 | CASE_HRESULT(OLE_E_BLANK)// 0x80040007L |
| 259 | CASE_HRESULT(OLE_E_CLASSDIFF)// 0x80040008L |
| 260 | CASE_HRESULT(OLE_E_CANT_GETMONIKER)// 0x80040009L |
| 261 | CASE_HRESULT(OLE_E_CANT_BINDTOSOURCE)// 0x8004000AL |
| 262 | CASE_HRESULT(OLE_E_STATIC)// 0x8004000BL |
| 263 | CASE_HRESULT(OLE_E_PROMPTSAVECANCELLED)// 0x8004000CL |
| 264 | CASE_HRESULT(OLE_E_INVALIDRECT)// 0x8004000DL |
| 265 | CASE_HRESULT(OLE_E_WRONGCOMPOBJ)// 0x8004000EL |
| 266 | CASE_HRESULT(OLE_E_INVALIDHWND)// 0x8004000FL |
| 267 | CASE_HRESULT(OLE_E_NOT_INPLACEACTIVE)// 0x80040010L |
| 268 | CASE_HRESULT(OLE_E_CANTCONVERT)// 0x80040011L |
| 269 | CASE_HRESULT(OLE_E_NOSTORAGE)// 0x80040012L |
| 270 | CASE_HRESULT(DV_E_FORMATETC)// 0x80040064L |
| 271 | CASE_HRESULT(DV_E_DVTARGETDEVICE)// 0x80040065L |
| 272 | CASE_HRESULT(DV_E_STGMEDIUM)// 0x80040066L |
| 273 | CASE_HRESULT(DV_E_STATDATA)// 0x80040067L |
| 274 | CASE_HRESULT(DV_E_LINDEX)// 0x80040068L |
| 275 | CASE_HRESULT(DV_E_TYMED)// 0x80040069L |
| 276 | CASE_HRESULT(DV_E_CLIPFORMAT)// 0x8004006AL |
| 277 | CASE_HRESULT(DV_E_DVASPECT)// 0x8004006BL |
| 278 | CASE_HRESULT(DV_E_DVTARGETDEVICE_SIZE)// 0x8004006CL |
| 279 | CASE_HRESULT(DV_E_NOIVIEWOBJECT)// 0x8004006DL |
| 280 | CASE_HRESULT(DRAGDROP_E_NOTREGISTERED)// 0x80040100L |
| 281 | CASE_HRESULT(DRAGDROP_E_ALREADYREGISTERED)// 0x80040101L |
| 282 | CASE_HRESULT(DRAGDROP_E_INVALIDHWND)// 0x80040102L |
| 283 | CASE_HRESULT(CLASS_E_NOAGGREGATION)// 0x80040110L |
| 284 | CASE_HRESULT(CLASS_E_CLASSNOTAVAILABLE)// 0x80040111L |
| 285 | CASE_HRESULT(VIEW_E_DRAW)// 0x80040140L |
| 286 | CASE_HRESULT(REGDB_E_READREGDB)// 0x80040150L |
| 287 | CASE_HRESULT(REGDB_E_WRITEREGDB)// 0x80040151L |
| 288 | CASE_HRESULT(REGDB_E_KEYMISSING)// 0x80040152L |
| 289 | CASE_HRESULT(REGDB_E_INVALIDVALUE)// 0x80040153L |
| 290 | CASE_HRESULT(REGDB_E_CLASSNOTREG)// 0x80040154L |
| 291 | CASE_HRESULT(CACHE_E_NOCACHE_UPDATED)// 0x80040170L |
| 292 | CASE_HRESULT(OLEOBJ_E_NOVERBS)// 0x80040180L |
| 293 | CASE_HRESULT(INPLACE_E_NOTUNDOABLE)// 0x800401A0L |
| 294 | CASE_HRESULT(INPLACE_E_NOTOOLSPACE)// 0x800401A1L |
| 295 | CASE_HRESULT(CONVERT10_E_OLESTREAM_GET)// 0x800401C0L |
| 296 | CASE_HRESULT(CONVERT10_E_OLESTREAM_PUT)// 0x800401C1L |
| 297 | CASE_HRESULT(CONVERT10_E_OLESTREAM_FMT)// 0x800401C2L |
| 298 | CASE_HRESULT(CONVERT10_E_OLESTREAM_BITMAP_TO_DIB)// 0x800401C3L |
| 299 | CASE_HRESULT(CONVERT10_E_STG_FMT)// 0x800401C4L |
| 300 | CASE_HRESULT(CONVERT10_E_STG_NO_STD_STREAM)// 0x800401C5L |
| 301 | CASE_HRESULT(CONVERT10_E_STG_DIB_TO_BITMAP)// 0x800401C6L |
| 302 | CASE_HRESULT(CLIPBRD_E_CANT_OPEN)// 0x800401D0L |
| 303 | CASE_HRESULT(CLIPBRD_E_CANT_EMPTY)// 0x800401D1L |
| 304 | CASE_HRESULT(CLIPBRD_E_CANT_SET)// 0x800401D2L |
| 305 | CASE_HRESULT(CLIPBRD_E_BAD_DATA)// 0x800401D3L |
| 306 | CASE_HRESULT(CLIPBRD_E_CANT_CLOSE)// 0x800401D4L |
| 307 | CASE_HRESULT(MK_E_CONNECTMANUALLY)// 0x800401E0L |
| 308 | CASE_HRESULT(MK_E_EXCEEDEDDEADLINE)// 0x800401E1L |
| 309 | CASE_HRESULT(MK_E_NEEDGENERIC)// 0x800401E2L |
| 310 | CASE_HRESULT(MK_E_UNAVAILABLE)// 0x800401E3L |
| 311 | CASE_HRESULT(MK_E_SYNTAX)// 0x800401E4L |
| 312 | CASE_HRESULT(MK_E_NOOBJECT)// 0x800401E5L |
| 313 | CASE_HRESULT(MK_E_INVALIDEXTENSION)// 0x800401E6L |
| 314 | CASE_HRESULT(MK_E_INTERMEDIATEINTERFACENOTSUPPORTED)// 0x800401E7L |
| 315 | CASE_HRESULT(MK_E_NOTBINDABLE)// 0x800401E8L |
| 316 | CASE_HRESULT(MK_E_NOTBOUND)// 0x800401E9L |
| 317 | CASE_HRESULT(MK_E_CANTOPENFILE)// 0x800401EAL |
| 318 | CASE_HRESULT(MK_E_MUSTBOTHERUSER)// 0x800401EBL |
| 319 | CASE_HRESULT(MK_E_NOINVERSE)// 0x800401ECL |
| 320 | CASE_HRESULT(MK_E_NOSTORAGE)// 0x800401EDL |
| 321 | CASE_HRESULT(MK_E_NOPREFIX)// 0x800401EEL |
| 322 | CASE_HRESULT(MK_E_ENUMERATION_FAILED)// 0x800401EFL |
| 323 | CASE_HRESULT(CO_E_NOTINITIALIZED)// 0x800401F0L |
| 324 | CASE_HRESULT(CO_E_ALREADYINITIALIZED)// 0x800401F1L |
| 325 | CASE_HRESULT(CO_E_CANTDETERMINECLASS)// 0x800401F2L |
| 326 | CASE_HRESULT(CO_E_CLASSSTRING)// 0x800401F3L |
| 327 | CASE_HRESULT(CO_E_IIDSTRING)// 0x800401F4L |
| 328 | CASE_HRESULT(CO_E_APPNOTFOUND)// 0x800401F5L |
| 329 | CASE_HRESULT(CO_E_APPSINGLEUSE)// 0x800401F6L |
| 330 | CASE_HRESULT(CO_E_ERRORINAPP)// 0x800401F7L |
| 331 | CASE_HRESULT(CO_E_DLLNOTFOUND)// 0x800401F8L |
| 332 | CASE_HRESULT(CO_E_ERRORINDLL)// 0x800401F9L |
| 333 | CASE_HRESULT(CO_E_WRONGOSFORAPP)// 0x800401FAL |
| 334 | CASE_HRESULT(CO_E_OBJNOTREG)// 0x800401FBL |
| 335 | CASE_HRESULT(CO_E_OBJISREG)// 0x800401FCL |
| 336 | CASE_HRESULT(CO_E_OBJNOTCONNECTED)// 0x800401FDL |
| 337 | CASE_HRESULT(CO_E_APPDIDNTREG)// 0x800401FEL |
| 338 | CASE_HRESULT(CO_E_RELEASED)// 0x800401FFL |
| 339 | |
| 340 | CASE_HRESULT(OLE_S_USEREG)// 0x00040000L |
| 341 | CASE_HRESULT(OLE_S_STATIC)// 0x00040001L |
| 342 | CASE_HRESULT(OLE_S_MAC_CLIPFORMAT)// 0x00040002L |
| 343 | CASE_HRESULT(DRAGDROP_S_DROP)// 0x00040100L |
| 344 | CASE_HRESULT(DRAGDROP_S_CANCEL)// 0x00040101L |
| 345 | CASE_HRESULT(DRAGDROP_S_USEDEFAULTCURSORS)// 0x00040102L |
| 346 | CASE_HRESULT(DATA_S_SAMEFORMATETC)// 0x00040130L |
| 347 | CASE_HRESULT(VIEW_S_ALREADY_FROZEN)// 0x00040140L |
| 348 | CASE_HRESULT(CACHE_S_FORMATETC_NOTSUPPORTED)// 0x00040170L |
| 349 | CASE_HRESULT(CACHE_S_SAMECACHE)// 0x00040171L |
| 350 | CASE_HRESULT(CACHE_S_SOMECACHES_NOTUPDATED)// 0x00040172L |
| 351 | CASE_HRESULT(OLEOBJ_S_INVALIDVERB)// 0x00040180L |
| 352 | CASE_HRESULT(OLEOBJ_S_CANNOT_DOVERB_NOW)// 0x00040181L |
| 353 | CASE_HRESULT(OLEOBJ_S_INVALIDHWND)// 0x00040182L |
| 354 | CASE_HRESULT(INPLACE_S_TRUNCATED)// 0x000401A0L |
| 355 | CASE_HRESULT(CONVERT10_S_NO_PRESENTATION)// 0x000401C0L |
| 356 | CASE_HRESULT(MK_S_REDUCED_TO_SELF)// 0x000401E2L |
| 357 | CASE_HRESULT(MK_S_ME)// 0x000401E4L |
| 358 | CASE_HRESULT(MK_S_HIM)// 0x000401E5L |
| 359 | CASE_HRESULT(MK_S_US)// 0x000401E6L |
| 360 | CASE_HRESULT(MK_S_MONIKERALREADYREGISTERED)// 0x000401E7L |
| 361 | |
| 362 | // ****************** |
| 363 | // FACILITY_WINDOWS |
| 364 | // ****************** |
| 365 | |
| 366 | CASE_HRESULT(CO_E_CLASS_CREATE_FAILED)// 0x80080001L |
| 367 | CASE_HRESULT(CO_E_SCM_ERROR)// 0x80080002L |
| 368 | CASE_HRESULT(CO_E_SCM_RPC_FAILURE)// 0x80080003L |
| 369 | CASE_HRESULT(CO_E_BAD_PATH)// 0x80080004L |
| 370 | CASE_HRESULT(CO_E_SERVER_EXEC_FAILURE)// 0x80080005L |
| 371 | CASE_HRESULT(CO_E_OBJSRV_RPC_FAILURE)// 0x80080006L |
| 372 | CASE_HRESULT(MK_E_NO_NORMALIZED)// 0x80080007L |
| 373 | CASE_HRESULT(CO_E_SERVER_STOPPING)// 0x80080008L |
| 374 | CASE_HRESULT(MEM_E_INVALID_ROOT)// 0x80080009L |
| 375 | CASE_HRESULT(MEM_E_INVALID_LINK)// 0x80080010L |
| 376 | CASE_HRESULT(MEM_E_INVALID_SIZE)// 0x80080011L |
| 377 | |
| 378 | // ****************** |
| 379 | // FACILITY_DISPATCH |
| 380 | // ****************** |
| 381 | |
| 382 | CASE_HRESULT(DISP_E_UNKNOWNINTERFACE)// 0x80020001L |
| 383 | CASE_HRESULT(DISP_E_MEMBERNOTFOUND)// 0x80020003L |
| 384 | CASE_HRESULT(DISP_E_PARAMNOTFOUND)// 0x80020004L |
| 385 | CASE_HRESULT(DISP_E_TYPEMISMATCH)// 0x80020005L |
| 386 | CASE_HRESULT(DISP_E_UNKNOWNNAME)// 0x80020006L |
| 387 | CASE_HRESULT(DISP_E_NONAMEDARGS)// 0x80020007L |
| 388 | CASE_HRESULT(DISP_E_BADVARTYPE)// 0x80020008L |
| 389 | CASE_HRESULT(DISP_E_EXCEPTION)// 0x80020009L |
| 390 | CASE_HRESULT(DISP_E_OVERFLOW)// 0x8002000AL |
| 391 | CASE_HRESULT(DISP_E_BADINDEX)// 0x8002000BL |
| 392 | CASE_HRESULT(DISP_E_UNKNOWNLCID)// 0x8002000CL |
| 393 | CASE_HRESULT(DISP_E_ARRAYISLOCKED)// 0x8002000DL |
| 394 | CASE_HRESULT(DISP_E_BADPARAMCOUNT)// 0x8002000EL |
| 395 | CASE_HRESULT(DISP_E_PARAMNOTOPTIONAL)// 0x8002000FL |
| 396 | CASE_HRESULT(DISP_E_BADCALLEE)// 0x80020010L |
| 397 | CASE_HRESULT(DISP_E_NOTACOLLECTION)// 0x80020011L |
| 398 | CASE_HRESULT(TYPE_E_BUFFERTOOSMALL)// 0x80028016L |
| 399 | CASE_HRESULT(TYPE_E_INVDATAREAD)// 0x80028018L |
| 400 | CASE_HRESULT(TYPE_E_UNSUPFORMAT)// 0x80028019L |
| 401 | CASE_HRESULT(TYPE_E_REGISTRYACCESS)// 0x8002801CL |
| 402 | CASE_HRESULT(TYPE_E_LIBNOTREGISTERED)// 0x8002801DL |
| 403 | CASE_HRESULT(TYPE_E_UNDEFINEDTYPE)// 0x80028027L |
| 404 | CASE_HRESULT(TYPE_E_QUALIFIEDNAMEDISALLOWED)// 0x80028028L |
| 405 | CASE_HRESULT(TYPE_E_INVALIDSTATE)// 0x80028029L |
| 406 | CASE_HRESULT(TYPE_E_WRONGTYPEKIND)// 0x8002802AL |
| 407 | CASE_HRESULT(TYPE_E_ELEMENTNOTFOUND)// 0x8002802BL |
| 408 | CASE_HRESULT(TYPE_E_AMBIGUOUSNAME)// 0x8002802CL |
| 409 | CASE_HRESULT(TYPE_E_NAMECONFLICT)// 0x8002802DL |
| 410 | CASE_HRESULT(TYPE_E_UNKNOWNLCID)// 0x8002802EL |
| 411 | CASE_HRESULT(TYPE_E_DLLFUNCTIONNOTFOUND)// 0x8002802FL |
| 412 | CASE_HRESULT(TYPE_E_BADMODULEKIND)// 0x800288BDL |
| 413 | CASE_HRESULT(TYPE_E_SIZETOOBIG)// 0x800288C5L |
| 414 | CASE_HRESULT(TYPE_E_DUPLICATEID)// 0x800288C6L |
| 415 | CASE_HRESULT(TYPE_E_INVALIDID)// 0x800288CFL |
| 416 | CASE_HRESULT(TYPE_E_TYPEMISMATCH)// 0x80028CA0L |
| 417 | CASE_HRESULT(TYPE_E_OUTOFBOUNDS)// 0x80028CA1L |
| 418 | CASE_HRESULT(TYPE_E_IOERROR)// 0x80028CA2L |
| 419 | CASE_HRESULT(TYPE_E_CANTCREATETMPFILE)// 0x80028CA3L |
| 420 | CASE_HRESULT(TYPE_E_CANTLOADLIBRARY)// 0x80029C4AL |
| 421 | CASE_HRESULT(TYPE_E_INCONSISTENTPROPFUNCS)// 0x80029C83L |
| 422 | CASE_HRESULT(TYPE_E_CIRCULARTYPE)// 0x80029C84L |
| 423 | |
| 424 | // ****************** |
| 425 | // FACILITY_STORAGE |
| 426 | // ****************** |
| 427 | |
| 428 | CASE_HRESULT(STG_E_INVALIDFUNCTION)// 0x80030001L |
| 429 | CASE_HRESULT(STG_E_FILENOTFOUND)// 0x80030002L |
| 430 | CASE_HRESULT(STG_E_PATHNOTFOUND)// 0x80030003L |
| 431 | CASE_HRESULT(STG_E_TOOMANYOPENFILES)// 0x80030004L |
| 432 | CASE_HRESULT(STG_E_ACCESSDENIED)// 0x80030005L |
| 433 | CASE_HRESULT(STG_E_INVALIDHANDLE)// 0x80030006L |
| 434 | CASE_HRESULT(STG_E_INSUFFICIENTMEMORY)// 0x80030008L |
| 435 | CASE_HRESULT(STG_E_INVALIDPOINTER)// 0x80030009L |
| 436 | CASE_HRESULT(STG_E_NOMOREFILES)// 0x80030012L |
| 437 | CASE_HRESULT(STG_E_DISKISWRITEPROTECTED)// 0x80030013L |
| 438 | CASE_HRESULT(STG_E_SEEKERROR)// 0x80030019L |
| 439 | CASE_HRESULT(STG_E_WRITEFAULT)// 0x8003001DL |
| 440 | CASE_HRESULT(STG_E_READFAULT)// 0x8003001EL |
| 441 | CASE_HRESULT(STG_E_SHAREVIOLATION)// 0x80030020L |
| 442 | CASE_HRESULT(STG_E_LOCKVIOLATION)// 0x80030021L |
| 443 | CASE_HRESULT(STG_E_FILEALREADYEXISTS)// 0x80030050L |
| 444 | CASE_HRESULT(STG_E_INVALIDPARAMETER)// 0x80030057L |
| 445 | CASE_HRESULT(STG_E_MEDIUMFULL)// 0x80030070L |
| 446 | CASE_HRESULT(STG_E_ABNORMALAPIEXIT)// 0x800300FAL |
| 447 | CASE_HRESULT(STG_E_INVALIDHEADER)// 0x800300FBL |
| 448 | CASE_HRESULT(STG_E_INVALIDNAME)// 0x800300FCL |
| 449 | CASE_HRESULT(STG_E_UNKNOWN)// 0x800300FDL |
| 450 | CASE_HRESULT(STG_E_UNIMPLEMENTEDFUNCTION)// 0x800300FEL |
| 451 | CASE_HRESULT(STG_E_INVALIDFLAG)// 0x800300FFL |
| 452 | CASE_HRESULT(STG_E_INUSE)// 0x80030100L |
| 453 | CASE_HRESULT(STG_E_NOTCURRENT)// 0x80030101L |
| 454 | CASE_HRESULT(STG_E_REVERTED)// 0x80030102L |
| 455 | CASE_HRESULT(STG_E_CANTSAVE)// 0x80030103L |
| 456 | CASE_HRESULT(STG_E_OLDFORMAT)// 0x80030104L |
| 457 | CASE_HRESULT(STG_E_OLDDLL)// 0x80030105L |
| 458 | CASE_HRESULT(STG_E_SHAREREQUIRED)// 0x80030106L |
| 459 | CASE_HRESULT(STG_E_NOTFILEBASEDSTORAGE)// 0x80030107L |
| 460 | CASE_HRESULT(STG_S_CONVERTED)// 0x00030200L |
| 461 | |
| 462 | // ****************** |
| 463 | // FACILITY_RPC |
| 464 | // ****************** |
| 465 | |
| 466 | CASE_HRESULT(RPC_E_CALL_REJECTED)// 0x80010001L |
| 467 | CASE_HRESULT(RPC_E_CALL_CANCELED)// 0x80010002L |
| 468 | CASE_HRESULT(RPC_E_CANTPOST_INSENDCALL)// 0x80010003L |
| 469 | CASE_HRESULT(RPC_E_CANTCALLOUT_INASYNCCALL)// 0x80010004L |
| 470 | CASE_HRESULT(RPC_E_CANTCALLOUT_INEXTERNALCALL)// 0x80010005L |
| 471 | CASE_HRESULT(RPC_E_CONNECTION_TERMINATED)// 0x80010006L |
| 472 | CASE_HRESULT(RPC_E_SERVER_DIED)// 0x80010007L |
| 473 | CASE_HRESULT(RPC_E_CLIENT_DIED)// 0x80010008L |
| 474 | CASE_HRESULT(RPC_E_INVALID_DATAPACKET)// 0x80010009L |
| 475 | CASE_HRESULT(RPC_E_CANTTRANSMIT_CALL)// 0x8001000AL |
| 476 | CASE_HRESULT(RPC_E_CLIENT_CANTMARSHAL_DATA)// 0x8001000BL |
| 477 | CASE_HRESULT(RPC_E_CLIENT_CANTUNMARSHAL_DATA)// 0x8001000CL |
| 478 | CASE_HRESULT(RPC_E_SERVER_CANTMARSHAL_DATA)// 0x8001000DL |
| 479 | CASE_HRESULT(RPC_E_SERVER_CANTUNMARSHAL_DATA)// 0x8001000EL |
| 480 | CASE_HRESULT(RPC_E_INVALID_DATA)// 0x8001000FL |
| 481 | CASE_HRESULT(RPC_E_INVALID_PARAMETER)// 0x80010010L |
| 482 | CASE_HRESULT(RPC_E_CANTCALLOUT_AGAIN)// 0x80010011L |
| 483 | CASE_HRESULT(RPC_E_SERVER_DIED_DNE)// 0x80010012L |
| 484 | CASE_HRESULT(RPC_E_SYS_CALL_FAILED)// 0x80010100L |
| 485 | CASE_HRESULT(RPC_E_OUT_OF_RESOURCES)// 0x80010101L |
| 486 | CASE_HRESULT(RPC_E_ATTEMPTED_MULTITHREAD)// 0x80010102L |
| 487 | CASE_HRESULT(RPC_E_NOT_REGISTERED)// 0x80010103L |
| 488 | CASE_HRESULT(RPC_E_FAULT)// 0x80010104L |
| 489 | CASE_HRESULT(RPC_E_SERVERFAULT)// 0x80010105L |
| 490 | CASE_HRESULT(RPC_E_CHANGED_MODE)// 0x80010106L |
| 491 | CASE_HRESULT(RPC_E_INVALIDMETHOD)// 0x80010107L |
| 492 | CASE_HRESULT(RPC_E_DISCONNECTED)// 0x80010108L |
| 493 | CASE_HRESULT(RPC_E_RETRY)// 0x80010109L |
| 494 | CASE_HRESULT(RPC_E_SERVERCALL_RETRYLATER)// 0x8001010AL |
| 495 | CASE_HRESULT(RPC_E_SERVERCALL_REJECTED)// 0x8001010BL |
| 496 | CASE_HRESULT(RPC_E_INVALID_CALLDATA)// 0x8001010CL |
| 497 | CASE_HRESULT(RPC_E_CANTCALLOUT_ININPUTSYNCCALL)// 0x8001010DL |
| 498 | CASE_HRESULT(RPC_E_WRONG_THREAD)// 0x8001010EL |
| 499 | CASE_HRESULT(RPC_E_THREAD_NOT_INIT)// 0x8001010FL |
| 500 | CASE_HRESULT(RPC_E_UNEXPECTED)// 0x8001FFFFL |
| 501 | |
| 502 | // ****************** |
| 503 | // FACILITY_CTL |
| 504 | // ****************** |
| 505 | |
| 506 | CASE_HRESULT(CTL_E_ILLEGALFUNCTIONCALL) |
| 507 | CASE_HRESULT(CTL_E_OVERFLOW) |
| 508 | CASE_HRESULT(CTL_E_OUTOFMEMORY) |
| 509 | CASE_HRESULT(CTL_E_DIVISIONBYZERO) |
| 510 | CASE_HRESULT(CTL_E_OUTOFSTRINGSPACE) |
| 511 | CASE_HRESULT(CTL_E_OUTOFSTACKSPACE) |
| 512 | CASE_HRESULT(CTL_E_BADFILENAMEORNUMBER) |
| 513 | CASE_HRESULT(CTL_E_FILENOTFOUND) |
| 514 | CASE_HRESULT(CTL_E_BADFILEMODE) |
| 515 | CASE_HRESULT(CTL_E_FILEALREADYOPEN) |
| 516 | CASE_HRESULT(CTL_E_DEVICEIOERROR) |
| 517 | CASE_HRESULT(CTL_E_FILEALREADYEXISTS) |
| 518 | CASE_HRESULT(CTL_E_BADRECORDLENGTH) |
| 519 | CASE_HRESULT(CTL_E_DISKFULL) |
| 520 | CASE_HRESULT(CTL_E_BADRECORDNUMBER) |
| 521 | CASE_HRESULT(CTL_E_BADFILENAME) |
| 522 | CASE_HRESULT(CTL_E_TOOMANYFILES) |
| 523 | CASE_HRESULT(CTL_E_DEVICEUNAVAILABLE) |
| 524 | CASE_HRESULT(CTL_E_PERMISSIONDENIED) |
| 525 | CASE_HRESULT(CTL_E_DISKNOTREADY) |
| 526 | CASE_HRESULT(CTL_E_PATHFILEACCESSERROR) |
| 527 | CASE_HRESULT(CTL_E_PATHNOTFOUND) |
| 528 | CASE_HRESULT(CTL_E_INVALIDPATTERNSTRING) |
| 529 | CASE_HRESULT(CTL_E_INVALIDUSEOFNULL) |
| 530 | CASE_HRESULT(CTL_E_INVALIDFILEFORMAT) |
| 531 | CASE_HRESULT(CTL_E_INVALIDPROPERTYVALUE) |
| 532 | CASE_HRESULT(CTL_E_INVALIDPROPERTYARRAYINDEX) |
| 533 | CASE_HRESULT(CTL_E_SETNOTSUPPORTEDATRUNTIME) |
| 534 | CASE_HRESULT(CTL_E_SETNOTSUPPORTED) |
| 535 | CASE_HRESULT(CTL_E_NEEDPROPERTYARRAYINDEX) |
| 536 | CASE_HRESULT(CTL_E_SETNOTPERMITTED) |
| 537 | CASE_HRESULT(CTL_E_GETNOTSUPPORTEDATRUNTIME) |
| 538 | CASE_HRESULT(CTL_E_GETNOTSUPPORTED) |
| 539 | CASE_HRESULT(CTL_E_PROPERTYNOTFOUND) |
| 540 | CASE_HRESULT(CTL_E_INVALIDCLIPBOARDFORMAT) |
| 541 | CASE_HRESULT(CTL_E_INVALIDPICTURE) |
| 542 | CASE_HRESULT(CTL_E_PRINTERERROR) |
| 543 | CASE_HRESULT(CTL_E_CANTSAVEFILETOTEMP) |
| 544 | CASE_HRESULT(CTL_E_SEARCHTEXTNOTFOUND) |
| 545 | CASE_HRESULT(CTL_E_REPLACEMENTSTOOLONG) |
| 546 | #endif // FEATURE_COMINTEROP |
| 547 | |
| 548 | #ifdef _DEBUG // @todo: do we want to burn strings for this in a free build? |
| 549 | |
| 550 | CASE_HRESULT(CEE_E_CVTRES_NOT_FOUND) |
| 551 | CASE_HRESULT(COR_E_APPDOMAINUNLOADED) |
| 552 | CASE_HRESULT(COR_E_CANNOTUNLOADAPPDOMAIN) |
| 553 | CASE_HRESULT(MSEE_E_ASSEMBLYLOADINPROGRESS) |
| 554 | CASE_HRESULT(COR_E_FIXUPSINEXE) |
| 555 | CASE_HRESULT(COR_E_MODULE_HASH_CHECK_FAILED) |
| 556 | CASE_HRESULT(FUSION_E_LOADFROM_BLOCKED) |
| 557 | CASE_HRESULT(FUSION_E_CACHEFILE_FAILED) |
| 558 | CASE_HRESULT(FUSION_E_REF_DEF_MISMATCH) |
| 559 | CASE_HRESULT(FUSION_E_INVALID_PRIVATE_ASM_LOCATION) |
| 560 | CASE_HRESULT(FUSION_E_ASM_MODULE_MISSING) |
| 561 | CASE_HRESULT(FUSION_E_PRIVATE_ASM_DISALLOWED) |
| 562 | CASE_HRESULT(FUSION_E_SIGNATURE_CHECK_FAILED) |
| 563 | CASE_HRESULT(FUSION_E_INVALID_NAME) |
| 564 | CASE_HRESULT(FUSION_E_CODE_DOWNLOAD_DISABLED) |
| 565 | CASE_HRESULT(CLDB_E_FILE_BADREAD) |
| 566 | CASE_HRESULT(CLDB_E_FILE_BADWRITE) |
| 567 | CASE_HRESULT(CLDB_S_TRUNCATION) |
| 568 | CASE_HRESULT(CLDB_E_FILE_OLDVER) |
| 569 | CASE_HRESULT(CLDB_E_SMDUPLICATE) |
| 570 | CASE_HRESULT(CLDB_E_NO_DATA) |
| 571 | CASE_HRESULT(CLDB_E_INCOMPATIBLE) |
| 572 | CASE_HRESULT(CLDB_E_FILE_CORRUPT) |
| 573 | CASE_HRESULT(CLDB_E_BADUPDATEMODE) |
| 574 | CASE_HRESULT(CLDB_E_INDEX_NOTFOUND) |
| 575 | CASE_HRESULT(CLDB_E_RECORD_NOTFOUND) |
| 576 | CASE_HRESULT(CLDB_E_RECORD_OUTOFORDER) |
| 577 | CASE_HRESULT(CLDB_E_TOO_BIG) |
| 578 | CASE_HRESULT(META_E_BADMETADATA) |
| 579 | CASE_HRESULT(META_E_BAD_SIGNATURE) |
| 580 | CASE_HRESULT(META_E_BAD_INPUT_PARAMETER) |
| 581 | CASE_HRESULT(META_E_CANNOTRESOLVETYPEREF) |
| 582 | CASE_HRESULT(META_S_DUPLICATE) |
| 583 | CASE_HRESULT(META_E_STRINGSPACE_FULL) |
| 584 | CASE_HRESULT(META_E_HAS_UNMARKALL) |
| 585 | CASE_HRESULT(META_E_MUST_CALL_UNMARKALL) |
| 586 | CASE_HRESULT(META_E_CA_INVALID_TARGET) |
| 587 | CASE_HRESULT(META_E_CA_INVALID_VALUE) |
| 588 | CASE_HRESULT(META_E_CA_INVALID_BLOB) |
| 589 | CASE_HRESULT(META_E_CA_REPEATED_ARG) |
| 590 | CASE_HRESULT(META_E_CA_UNKNOWN_ARGUMENT) |
| 591 | CASE_HRESULT(META_E_CA_UNEXPECTED_TYPE) |
| 592 | CASE_HRESULT(META_E_CA_INVALID_ARGTYPE) |
| 593 | CASE_HRESULT(META_E_CA_INVALID_ARG_FOR_TYPE) |
| 594 | CASE_HRESULT(META_E_CA_INVALID_UUID) |
| 595 | CASE_HRESULT(META_E_CA_INVALID_MARSHALAS_FIELDS) |
| 596 | CASE_HRESULT(META_E_CA_NT_FIELDONLY) |
| 597 | CASE_HRESULT(META_E_CA_NEGATIVE_PARAMINDEX) |
| 598 | CASE_HRESULT(META_E_CA_NEGATIVE_CONSTSIZE) |
| 599 | CASE_HRESULT(META_E_CA_FIXEDSTR_SIZE_REQUIRED) |
| 600 | CASE_HRESULT(META_E_CA_CUSTMARSH_TYPE_REQUIRED) |
| 601 | CASE_HRESULT(META_E_CA_BAD_FRIENDS_ARGS) |
| 602 | CASE_HRESULT(VLDTR_E_RID_OUTOFRANGE) |
| 603 | CASE_HRESULT(VLDTR_E_STRING_INVALID) |
| 604 | CASE_HRESULT(VLDTR_E_GUID_INVALID) |
| 605 | CASE_HRESULT(VLDTR_E_BLOB_INVALID) |
| 606 | CASE_HRESULT(VLDTR_E_MR_BADCALLINGCONV) |
| 607 | CASE_HRESULT(VLDTR_E_SIGNULL) |
| 608 | CASE_HRESULT(VLDTR_E_MD_BADCALLINGCONV) |
| 609 | CASE_HRESULT(VLDTR_E_MD_THISSTATIC) |
| 610 | CASE_HRESULT(VLDTR_E_MD_NOTTHISNOTSTATIC) |
| 611 | CASE_HRESULT(VLDTR_E_MD_NOARGCNT) |
| 612 | CASE_HRESULT(VLDTR_E_SIG_MISSELTYPE) |
| 613 | CASE_HRESULT(VLDTR_E_SIG_MISSTKN) |
| 614 | CASE_HRESULT(VLDTR_E_SIG_TKNBAD) |
| 615 | CASE_HRESULT(VLDTR_E_SIG_MISSFPTR) |
| 616 | CASE_HRESULT(VLDTR_E_SIG_MISSFPTRARGCNT) |
| 617 | CASE_HRESULT(VLDTR_E_SIG_MISSRANK) |
| 618 | CASE_HRESULT(VLDTR_E_SIG_MISSNSIZE) |
| 619 | CASE_HRESULT(VLDTR_E_SIG_MISSSIZE) |
| 620 | CASE_HRESULT(VLDTR_E_SIG_MISSNLBND) |
| 621 | CASE_HRESULT(VLDTR_E_SIG_MISSLBND) |
| 622 | CASE_HRESULT(VLDTR_E_SIG_BADELTYPE) |
| 623 | CASE_HRESULT(VLDTR_E_TD_ENCLNOTNESTED) |
| 624 | CASE_HRESULT(VLDTR_E_FMD_PINVOKENOTSTATIC) |
| 625 | CASE_HRESULT(VLDTR_E_SIG_SENTINMETHODDEF) |
| 626 | CASE_HRESULT(VLDTR_E_SIG_SENTMUSTVARARG) |
| 627 | CASE_HRESULT(VLDTR_E_SIG_MULTSENTINELS) |
| 628 | CASE_HRESULT(VLDTR_E_SIG_MISSARG) |
| 629 | CASE_HRESULT(VLDTR_E_SIG_BYREFINFIELD) |
| 630 | CASE_HRESULT(VLDTR_E_SIG_BADVOID) |
| 631 | CASE_HRESULT(CORDBG_E_UNRECOVERABLE_ERROR) |
| 632 | CASE_HRESULT(CORDBG_E_PROCESS_TERMINATED) |
| 633 | CASE_HRESULT(CORDBG_E_PROCESS_NOT_SYNCHRONIZED) |
| 634 | CASE_HRESULT(CORDBG_E_CLASS_NOT_LOADED) |
| 635 | CASE_HRESULT(CORDBG_E_IL_VAR_NOT_AVAILABLE) |
| 636 | CASE_HRESULT(CORDBG_E_BAD_REFERENCE_VALUE) |
| 637 | CASE_HRESULT(CORDBG_E_FIELD_NOT_AVAILABLE) |
| 638 | CASE_HRESULT(CORDBG_E_NON_NATIVE_FRAME) |
| 639 | CASE_HRESULT(CORDBG_E_CODE_NOT_AVAILABLE) |
| 640 | CASE_HRESULT(CORDBG_E_FUNCTION_NOT_IL) |
| 641 | CASE_HRESULT(CORDBG_S_BAD_START_SEQUENCE_POINT) |
| 642 | CASE_HRESULT(CORDBG_S_BAD_END_SEQUENCE_POINT) |
| 643 | CASE_HRESULT(CORDBG_E_CANT_SET_IP_INTO_FINALLY) |
| 644 | CASE_HRESULT(CORDBG_E_CANT_SET_IP_OUT_OF_FINALLY) |
| 645 | CASE_HRESULT(CORDBG_E_CANT_SET_IP_INTO_CATCH) |
| 646 | CASE_HRESULT(CORDBG_E_SET_IP_NOT_ALLOWED_ON_NONLEAF_FRAME) |
| 647 | CASE_HRESULT(CORDBG_E_SET_IP_IMPOSSIBLE) |
| 648 | CASE_HRESULT(CORDBG_E_FUNC_EVAL_BAD_START_POINT) |
| 649 | CASE_HRESULT(CORDBG_E_INVALID_OBJECT) |
| 650 | CASE_HRESULT(CORDBG_E_FUNC_EVAL_NOT_COMPLETE) |
| 651 | CASE_HRESULT(CORDBG_S_FUNC_EVAL_HAS_NO_RESULT) |
| 652 | CASE_HRESULT(CORDBG_S_VALUE_POINTS_TO_VOID) |
| 653 | CASE_HRESULT(CORDBG_S_FUNC_EVAL_ABORTED) |
| 654 | CASE_HRESULT(CORDBG_E_STATIC_VAR_NOT_AVAILABLE) |
| 655 | CASE_HRESULT(CORDBG_E_CANT_SETIP_INTO_OR_OUT_OF_FILTER) |
| 656 | CASE_HRESULT(CORDBG_E_CANT_CHANGE_JIT_SETTING_FOR_ZAP_MODULE) |
| 657 | CASE_HRESULT(CORDBG_E_CANT_SET_TO_JMC) |
| 658 | CASE_HRESULT(CORDBG_E_BAD_THREAD_STATE) |
| 659 | CASE_HRESULT(CORDBG_E_DEBUGGER_ALREADY_ATTACHED) |
| 660 | CASE_HRESULT(CORDBG_E_SUPERFLOUS_CONTINUE) |
| 661 | CASE_HRESULT(CORDBG_E_SET_VALUE_NOT_ALLOWED_ON_NONLEAF_FRAME) |
| 662 | CASE_HRESULT(CORDBG_E_ENC_MODULE_NOT_ENC_ENABLED) |
| 663 | CASE_HRESULT(CORDBG_E_SET_IP_NOT_ALLOWED_ON_EXCEPTION) |
| 664 | CASE_HRESULT(CORDBG_E_VARIABLE_IS_ACTUALLY_LITERAL) |
| 665 | CASE_HRESULT(CORDBG_E_PROCESS_DETACHED) |
| 666 | CASE_HRESULT(CORDBG_E_ENC_CANT_ADD_FIELD_TO_VALUE_OR_LAYOUT_CLASS) |
| 667 | CASE_HRESULT(CORDBG_E_FIELD_NOT_STATIC) |
| 668 | CASE_HRESULT(CORDBG_E_FIELD_NOT_INSTANCE) |
| 669 | CASE_HRESULT(CORDBG_E_ENC_JIT_CANT_UPDATE) |
| 670 | CASE_HRESULT(CORDBG_E_ENC_INTERNAL_ERROR) |
| 671 | CASE_HRESULT(CORDBG_E_ENC_HANGING_FIELD) |
| 672 | CASE_HRESULT(CORDBG_E_MODULE_NOT_LOADED) |
| 673 | CASE_HRESULT(CORDBG_E_UNABLE_TO_SET_BREAKPOINT) |
| 674 | CASE_HRESULT(CORDBG_E_DEBUGGING_NOT_POSSIBLE) |
| 675 | CASE_HRESULT(CORDBG_E_KERNEL_DEBUGGER_ENABLED) |
| 676 | CASE_HRESULT(CORDBG_E_KERNEL_DEBUGGER_PRESENT) |
| 677 | CASE_HRESULT(CORDBG_E_INCOMPATIBLE_PROTOCOL) |
| 678 | CASE_HRESULT(CORDBG_E_TOO_MANY_PROCESSES) |
| 679 | CASE_HRESULT(CORDBG_E_INTEROP_NOT_SUPPORTED) |
| 680 | CASE_HRESULT(CORDBG_E_NO_REMAP_BREAKPIONT) |
| 681 | CASE_HRESULT(CORDBG_E_OBJECT_NEUTERED) |
| 682 | CASE_HRESULT(CORPROF_E_FUNCTION_NOT_COMPILED) |
| 683 | CASE_HRESULT(CORPROF_E_DATAINCOMPLETE) |
| 684 | CASE_HRESULT(CORPROF_E_FUNCTION_NOT_IL) |
| 685 | CASE_HRESULT(CORPROF_E_NOT_MANAGED_THREAD) |
| 686 | CASE_HRESULT(CORPROF_E_CALL_ONLY_FROM_INIT) |
| 687 | CASE_HRESULT(CORPROF_E_NOT_YET_AVAILABLE) |
| 688 | CASE_HRESULT(SECURITY_E_INCOMPATIBLE_SHARE) |
| 689 | CASE_HRESULT(SECURITY_E_UNVERIFIABLE) |
| 690 | CASE_HRESULT(SECURITY_E_INCOMPATIBLE_EVIDENCE) |
| 691 | CASE_HRESULT(CLDB_E_INTERNALERROR) |
| 692 | CASE_HRESULT(CORSEC_E_POLICY_EXCEPTION) |
| 693 | CASE_HRESULT(CORSEC_E_MIN_GRANT_FAIL) |
| 694 | CASE_HRESULT(CORSEC_E_NO_EXEC_PERM) |
| 695 | CASE_HRESULT(CORSEC_E_XMLSYNTAX) |
| 696 | CASE_HRESULT(CORSEC_E_INVALID_STRONGNAME) |
| 697 | CASE_HRESULT(CORSEC_E_MISSING_STRONGNAME) |
| 698 | CASE_HRESULT(CORSEC_E_INVALID_IMAGE_FORMAT) |
| 699 | CASE_HRESULT(CORSEC_E_CRYPTO) |
| 700 | CASE_HRESULT(CORSEC_E_CRYPTO_UNEX_OPER) |
| 701 | CASE_HRESULT(CORSECATTR_E_BAD_ACTION) |
| 702 | CASE_HRESULT(COR_E_APPLICATION) |
| 703 | CASE_HRESULT(COR_E_ARGUMENTOUTOFRANGE) |
| 704 | CASE_HRESULT(COR_E_ARITHMETIC) |
| 705 | CASE_HRESULT(COR_E_ARRAYTYPEMISMATCH) |
| 706 | CASE_HRESULT(COR_E_CONTEXTMARSHAL) |
| 707 | CASE_HRESULT(COR_E_TIMEOUT) |
| 708 | CASE_HRESULT(COR_E_DIVIDEBYZERO) |
| 709 | CASE_HRESULT(COR_E_EXCEPTION) |
| 710 | CASE_HRESULT(COR_E_EXECUTIONENGINE) |
| 711 | CASE_HRESULT(COR_E_FIELDACCESS) |
| 712 | CASE_HRESULT(COR_E_FORMAT) |
| 713 | CASE_HRESULT(COR_E_BADIMAGEFORMAT) |
| 714 | CASE_HRESULT(COR_E_ASSEMBLYEXPECTED) |
| 715 | CASE_HRESULT(COR_E_TYPEUNLOADED) |
| 716 | CASE_HRESULT(COR_E_INDEXOUTOFRANGE) |
| 717 | CASE_HRESULT(COR_E_INVALIDOPERATION) |
| 718 | CASE_HRESULT(COR_E_INVALIDPROGRAM) |
| 719 | CASE_HRESULT(COR_E_MEMBERACCESS) |
| 720 | CASE_HRESULT(COR_E_METHODACCESS) |
| 721 | CASE_HRESULT(COR_E_MISSINGFIELD) |
| 722 | CASE_HRESULT(COR_E_MISSINGMANIFESTRESOURCE) |
| 723 | CASE_HRESULT(COR_E_MISSINGMEMBER) |
| 724 | CASE_HRESULT(COR_E_MISSINGMETHOD) |
| 725 | CASE_HRESULT(COR_E_MULTICASTNOTSUPPORTED) |
| 726 | CASE_HRESULT(COR_E_NOTFINITENUMBER) |
| 727 | CASE_HRESULT(COR_E_DUPLICATEWAITOBJECT) |
| 728 | CASE_HRESULT(COR_E_PLATFORMNOTSUPPORTED) |
| 729 | CASE_HRESULT(COR_E_NOTSUPPORTED) |
| 730 | CASE_HRESULT(COR_E_OVERFLOW) |
| 731 | CASE_HRESULT(COR_E_RANK) |
| 732 | CASE_HRESULT(COR_E_SECURITY) |
| 733 | CASE_HRESULT(COR_E_SERIALIZATION) |
| 734 | CASE_HRESULT(COR_E_STACKOVERFLOW) |
| 735 | CASE_HRESULT(COR_E_SYNCHRONIZATIONLOCK) |
| 736 | CASE_HRESULT(COR_E_SYSTEM) |
| 737 | CASE_HRESULT(COR_E_THREADABORTED) |
| 738 | CASE_HRESULT(COR_E_THREADINTERRUPTED) |
| 739 | CASE_HRESULT(COR_E_THREADSTATE) |
| 740 | CASE_HRESULT(COR_E_THREADSTOP) |
| 741 | CASE_HRESULT(COR_E_TYPEINITIALIZATION) |
| 742 | CASE_HRESULT(COR_E_TYPELOAD) |
| 743 | CASE_HRESULT(COR_E_ENTRYPOINTNOTFOUND) |
| 744 | CASE_HRESULT(COR_E_DLLNOTFOUND) |
| 745 | CASE_HRESULT(COR_E_VERIFICATION) |
| 746 | CASE_HRESULT(COR_E_INVALIDCOMOBJECT) |
| 747 | CASE_HRESULT(COR_E_MARSHALDIRECTIVE) |
| 748 | CASE_HRESULT(COR_E_INVALIDOLEVARIANTTYPE) |
| 749 | CASE_HRESULT(COR_E_SAFEARRAYTYPEMISMATCH) |
| 750 | CASE_HRESULT(COR_E_SAFEARRAYRANKMISMATCH) |
| 751 | CASE_HRESULT(COR_E_INVALIDFILTERCRITERIA) |
| 752 | CASE_HRESULT(COR_E_REFLECTIONTYPELOAD) |
| 753 | CASE_HRESULT(COR_E_TARGET) |
| 754 | CASE_HRESULT(COR_E_TARGETINVOCATION) |
| 755 | CASE_HRESULT(COR_E_CUSTOMATTRIBUTEFORMAT) |
| 756 | CASE_HRESULT(COR_E_ENDOFSTREAM) |
| 757 | CASE_HRESULT(COR_E_FILELOAD) |
| 758 | CASE_HRESULT(COR_E_FILENOTFOUND) |
| 759 | CASE_HRESULT(COR_E_IO) |
| 760 | CASE_HRESULT(COR_E_DIRECTORYNOTFOUND) |
| 761 | CASE_HRESULT(COR_E_PATHTOOLONG) |
| 762 | CASE_HRESULT(COR_E_OBJECTDISPOSED) |
| 763 | CASE_HRESULT(COR_E_NEWER_RUNTIME) |
| 764 | CASE_HRESULT(CLR_E_SHIM_RUNTIMELOAD) |
| 765 | CASE_HRESULT(VER_E_FIELD_SIG) |
| 766 | CASE_HRESULT(CORDBG_E_THREAD_NOT_SCHEDULED) |
| 767 | #endif |
| 768 | |
| 769 | default: |
| 770 | return NULL; |
| 771 | } |
| 772 | } |
| 773 | #ifdef _PREFAST_ |
| 774 | #pragma warning(pop) |
| 775 | #endif |
| 776 | |
| 777 | |
| 778 | // --------------------------------------------------------------------------- |
| 779 | // HRException class. Implements exception API for exceptions from HRESULTS |
| 780 | // --------------------------------------------------------------------------- |
| 781 | |
| 782 | HRESULT HRException::GetHR() |
| 783 | { |
| 784 | LIMITED_METHOD_DAC_CONTRACT; |
| 785 | return m_hr; |
| 786 | } |
| 787 | |
| 788 | // --------------------------------------------------------------------------- |
| 789 | // COMException class. - moved to COMEx.cpp |
| 790 | // --------------------------------------------------------------------------- |
| 791 | |
| 792 | // --------------------------------------------------------------------------- |
| 793 | // SEHException class. Implements exception API for SEH exception info |
| 794 | // --------------------------------------------------------------------------- |
| 795 | |
| 796 | HRESULT SEHException::GetHR() |
| 797 | { |
| 798 | LIMITED_METHOD_DAC_CONTRACT; |
| 799 | |
| 800 | if (IsComPlusException(&m_exception)) // EE exception |
| 801 | return (HRESULT) m_exception.ExceptionInformation[0]; |
| 802 | else |
| 803 | return m_exception.ExceptionCode; |
| 804 | } |
| 805 | |
| 806 | IErrorInfo *SEHException::GetErrorInfo() |
| 807 | { |
| 808 | LIMITED_METHOD_CONTRACT; |
| 809 | return NULL; |
| 810 | } |
| 811 | |
| 812 | void SEHException::GetMessage(SString &string) |
| 813 | { |
| 814 | WRAPPER_NO_CONTRACT; |
| 815 | |
| 816 | if (IsComPlusException(&m_exception)) // EE exception |
| 817 | { |
| 818 | GenerateTopLevelHRExceptionMessage(GetHR(), string); |
| 819 | } |
| 820 | else |
| 821 | { |
| 822 | if (m_exception.ExceptionCode != 0) |
| 823 | { |
| 824 | string.Printf("Exception code 0x%.8x" , m_exception.ExceptionCode); |
| 825 | } |
| 826 | else |
| 827 | { |
| 828 | // If we don't have a valid exception code, then give a generic message that's a little nicer than |
| 829 | // "code 0x00000000". |
| 830 | string.Printf("Unknown exception" ); |
| 831 | } |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | //============================================================================== |
| 836 | // DelegatingException class. Implements exception API for "foreign" exceptions. |
| 837 | //============================================================================== |
| 838 | |
| 839 | DelegatingException::DelegatingException() |
| 840 | : m_delegatedException((Exception*)DELEGATE_NOT_YET_SET) |
| 841 | { |
| 842 | LIMITED_METHOD_DAC_CONTRACT; |
| 843 | } // DelegatingException::DelegatingException() |
| 844 | |
| 845 | //------------------------------------------------------------------------------ |
| 846 | DelegatingException::~DelegatingException() |
| 847 | { |
| 848 | WRAPPER_NO_CONTRACT; |
| 849 | |
| 850 | // If there is a valid delegate pointer (inited and non-NULL), delete it. |
| 851 | if (IsDelegateValid()) |
| 852 | Delete(m_delegatedException); |
| 853 | |
| 854 | // Avoid confusion. |
| 855 | m_delegatedException = NULL; |
| 856 | } // DelegatingException::~DelegatingException() |
| 857 | |
| 858 | //------------------------------------------------------------------------------ |
| 859 | // Retrieve the delegating exception, or get one from the Thread, or get NULL. |
| 860 | Exception* DelegatingException::GetDelegate() |
| 861 | { |
| 862 | WRAPPER_NO_CONTRACT; |
| 863 | |
| 864 | // If we haven't gotten the exception pointer before.. |
| 865 | if (!IsDelegateSet()) |
| 866 | { |
| 867 | // .. get it now. NULL in case there isn't one and we take default action. |
| 868 | m_delegatedException = NULL; |
| 869 | GetLastThrownObjectExceptionFromThread(reinterpret_cast<void**>(&m_delegatedException)); |
| 870 | } |
| 871 | |
| 872 | return m_delegatedException; |
| 873 | } // Exception* DelegatingException::GetDelegate() |
| 874 | |
| 875 | //------------------------------------------------------------------------------ |
| 876 | // Virtual overrides |
| 877 | HRESULT DelegatingException::GetHR() |
| 878 | { |
| 879 | WRAPPER_NO_CONTRACT; |
| 880 | SUPPORTS_DAC_HOST_ONLY; |
| 881 | |
| 882 | // Retrieve any delegating exception. |
| 883 | Exception *pDelegate = GetDelegate(); |
| 884 | |
| 885 | // If there is a delegate exception, defer to it. Otherwise, |
| 886 | // default to E_FAIL. |
| 887 | return pDelegate ? pDelegate->GetHR() : E_FAIL; |
| 888 | |
| 889 | } // HRESULT DelegatingException::GetHR() |
| 890 | |
| 891 | //------------------------------------------------------------------------------ |
| 892 | IErrorInfo *DelegatingException::GetErrorInfo() |
| 893 | { |
| 894 | WRAPPER_NO_CONTRACT; |
| 895 | |
| 896 | // Retrieve any delegating exception. |
| 897 | Exception *pDelegate = GetDelegate(); |
| 898 | |
| 899 | // If there is a delegate exception, defer to it. Otherwise, |
| 900 | // default to NULL. |
| 901 | return pDelegate ? pDelegate->GetErrorInfo() : NULL; |
| 902 | |
| 903 | } // IErrorInfo *DelegatingException::GetErrorInfo() |
| 904 | |
| 905 | //------------------------------------------------------------------------------ |
| 906 | void DelegatingException::GetMessage(SString &result) |
| 907 | { |
| 908 | WRAPPER_NO_CONTRACT; |
| 909 | |
| 910 | // Retrieve any delegating exception. |
| 911 | Exception *pDelegate = GetDelegate(); |
| 912 | |
| 913 | // If there is a delegate exception, defer to it. Otherwise, |
| 914 | // default to a generic message. |
| 915 | if (pDelegate) |
| 916 | { |
| 917 | pDelegate->GetMessage(result); |
| 918 | } |
| 919 | else |
| 920 | { |
| 921 | // If we don't have a valid exception code, then give a generic message |
| 922 | // that's a little nicer than "code 0x00000000". |
| 923 | result.Printf("Unknown exception" ); |
| 924 | } |
| 925 | } // void DelegatingException::GetMessage() |
| 926 | |
| 927 | //------------------------------------------------------------------------------ |
| 928 | Exception *DelegatingException::Clone() |
| 929 | { |
| 930 | WRAPPER_NO_CONTRACT; |
| 931 | |
| 932 | // Clone the base exception, this will also take care of cloning the inner |
| 933 | // exception if there is one. |
| 934 | NewHolder<DelegatingException> retExcep((DelegatingException*)Exception::Clone()); |
| 935 | |
| 936 | // If there is a valid delegating exception... |
| 937 | if (IsDelegateValid()) |
| 938 | { // ... clone it. |
| 939 | retExcep->m_delegatedException = m_delegatedException->Clone(); |
| 940 | } |
| 941 | else |
| 942 | { // ... but if there is not, just copy -- either NULL or DELEGATE_NOT_YET_SET |
| 943 | retExcep->m_delegatedException = m_delegatedException; |
| 944 | } |
| 945 | |
| 946 | retExcep.SuppressRelease(); |
| 947 | return retExcep; |
| 948 | } // virtual Exception *DelegatingException::Clone() |
| 949 | |
| 950 | //============================================================================== |
| 951 | //============================================================================== |
| 952 | |
| 953 | void DECLSPEC_NORETURN ThrowHR(HRESULT hr) |
| 954 | { |
| 955 | WRAPPER_NO_CONTRACT; |
| 956 | |
| 957 | STRESS_LOG1(LF_EH, LL_INFO100, "ThrowHR: HR = %x\n" , hr); |
| 958 | |
| 959 | if (hr == E_OUTOFMEMORY) |
| 960 | ThrowOutOfMemory(); |
| 961 | |
| 962 | // Catchers assume only failing hresults |
| 963 | _ASSERTE(FAILED(hr)); |
| 964 | if (hr == S_OK) |
| 965 | hr = E_FAIL; |
| 966 | |
| 967 | EX_THROW(HRException, (hr)); |
| 968 | } |
| 969 | |
| 970 | void DECLSPEC_NORETURN ThrowHR(HRESULT hr, SString const &msg) |
| 971 | { |
| 972 | STATIC_CONTRACT_SO_TOLERANT; |
| 973 | WRAPPER_NO_CONTRACT; |
| 974 | |
| 975 | STRESS_LOG1(LF_EH, LL_INFO100, "ThrowHR: HR = %x\n" , hr); |
| 976 | |
| 977 | if (hr == E_OUTOFMEMORY) |
| 978 | ThrowOutOfMemory(); |
| 979 | |
| 980 | // Catchers assume only failing hresults |
| 981 | _ASSERTE(FAILED(hr)); |
| 982 | if (hr == S_OK) |
| 983 | hr = E_FAIL; |
| 984 | |
| 985 | EX_THROW(HRMsgException, (hr, msg)); |
| 986 | } |
| 987 | |
| 988 | void DECLSPEC_NORETURN ThrowHR(HRESULT hr, UINT uText) |
| 989 | { |
| 990 | WRAPPER_NO_CONTRACT; |
| 991 | SUPPORTS_DAC_HOST_ONLY; |
| 992 | |
| 993 | if (hr == E_OUTOFMEMORY) |
| 994 | ThrowOutOfMemory(); |
| 995 | |
| 996 | // Catchers assume only failing hresults |
| 997 | _ASSERTE(FAILED(hr)); |
| 998 | if (hr == S_OK) |
| 999 | hr = E_FAIL; |
| 1000 | |
| 1001 | SString sExceptionText; |
| 1002 | |
| 1003 | // We won't check the return value here. If it fails, we'll just |
| 1004 | // throw the HR |
| 1005 | sExceptionText.LoadResource(CCompRC::Error, uText); |
| 1006 | |
| 1007 | EX_THROW(HRMsgException, (hr, sExceptionText)); |
| 1008 | } |
| 1009 | |
| 1010 | void DECLSPEC_NORETURN ThrowWin32(DWORD err) |
| 1011 | { |
| 1012 | STATIC_CONTRACT_SO_TOLERANT; |
| 1013 | WRAPPER_NO_CONTRACT; |
| 1014 | if (err == ERROR_NOT_ENOUGH_MEMORY) |
| 1015 | { |
| 1016 | ThrowOutOfMemory(); |
| 1017 | } |
| 1018 | else |
| 1019 | { |
| 1020 | ThrowHR(HRESULT_FROM_WIN32(err)); |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | void DECLSPEC_NORETURN ThrowLastError() |
| 1025 | { |
| 1026 | WRAPPER_NO_CONTRACT; |
| 1027 | SUPPORTS_DAC; |
| 1028 | |
| 1029 | ThrowWin32(GetLastError()); |
| 1030 | } |
| 1031 | |
| 1032 | void DECLSPEC_NORETURN ThrowOutOfMemory() |
| 1033 | { |
| 1034 | CONTRACTL |
| 1035 | { |
| 1036 | THROWS; |
| 1037 | GC_NOTRIGGER; |
| 1038 | SO_TOLERANT; |
| 1039 | SUPPORTS_DAC; |
| 1040 | } |
| 1041 | CONTRACTL_END; |
| 1042 | |
| 1043 | #ifndef DACCESS_COMPILE |
| 1044 | |
| 1045 | // Use volatile store to prevent compiler from optimizing the static variable away |
| 1046 | VolatileStoreWithoutBarrier<HRESULT>(&g_hrFatalError, COR_E_OUTOFMEMORY); |
| 1047 | |
| 1048 | // Regular CLR builds - throw our pre-created OOM exception object |
| 1049 | PAL_CPP_THROW(Exception *, Exception::GetOOMException()); |
| 1050 | |
| 1051 | #else |
| 1052 | |
| 1053 | // DAC builds - raise a DacError |
| 1054 | DacError(E_OUTOFMEMORY); |
| 1055 | |
| 1056 | // DacError always throws but isn't marked DECLSPEC_NORETURN so we have to |
| 1057 | // tell the compiler that this code is unreachable. We could mark DacError |
| 1058 | // (and DacNotImpl) as DECLSPEC_NORETURN, but then we've have to update a |
| 1059 | // lot of code where we do something afterwards. Also, due to inlining, |
| 1060 | // we'd sometimes have to change functions which call functions that only |
| 1061 | // call DacNotImpl. I have these changes in a bbpack and some of them look |
| 1062 | // nice, but I'm not sure if it's worth the risk of merge conflicts. |
| 1063 | UNREACHABLE(); |
| 1064 | |
| 1065 | #endif |
| 1066 | } |
| 1067 | |
| 1068 | #include "corexcep.h" |
| 1069 | |
| 1070 | #ifdef FEATURE_STACK_PROBE |
| 1071 | void DECLSPEC_NORETURN ThrowStackOverflow() |
| 1072 | { |
| 1073 | CONTRACTL |
| 1074 | { |
| 1075 | // This should be throws... But it isn't because a SO doesn't technically |
| 1076 | // fall into the same THROW/NOTHROW conventions as the rest of the contract |
| 1077 | // infrastructure. |
| 1078 | NOTHROW; |
| 1079 | |
| 1080 | GC_NOTRIGGER; |
| 1081 | SO_TOLERANT; |
| 1082 | SUPPORTS_DAC; |
| 1083 | } |
| 1084 | CONTRACTL_END; |
| 1085 | |
| 1086 | //g_hrFatalError=COR_E_STACKOVERFLOW; |
| 1087 | PTR_INT32 p_ghrFatalError = dac_cast<PTR_INT32>(GVAL_ADDR(g_hrFatalError)); |
| 1088 | _ASSERTE(p_ghrFatalError != NULL); |
| 1089 | *p_ghrFatalError = COR_E_STACKOVERFLOW; |
| 1090 | |
| 1091 | |
| 1092 | RaiseException(EXCEPTION_SOFTSO, 0, 0, NULL); |
| 1093 | UNREACHABLE(); |
| 1094 | } |
| 1095 | #endif |
| 1096 | |
| 1097 | void DECLSPEC_NORETURN ThrowMessage(LPCSTR string, ...) |
| 1098 | { |
| 1099 | CONTRACTL |
| 1100 | { |
| 1101 | THROWS; |
| 1102 | GC_NOTRIGGER; |
| 1103 | SO_TOLERANT; |
| 1104 | } |
| 1105 | CONTRACTL_END; |
| 1106 | |
| 1107 | StackSString message; |
| 1108 | |
| 1109 | va_list args; |
| 1110 | va_start(args, string); |
| 1111 | message.VPrintf(string, args); |
| 1112 | va_end(args); |
| 1113 | |
| 1114 | EX_THROW(HRMsgException, (E_FAIL, message)); |
| 1115 | } |
| 1116 | |
| 1117 | |
| 1118 | //-------------------------------------------------------------------------------- |
| 1119 | // Helper for EX_THROW_WITH_INNER() |
| 1120 | // |
| 1121 | // Clones an exception into the current domain. Also handles special cases for |
| 1122 | // OOM and other stuff. Making this a function so we don't inline all this logic |
| 1123 | // every place we call EX_THROW_WITH_INNER. |
| 1124 | // |
| 1125 | // If the "inner" is a transient exception such as OOM or ThreadAbort, this function |
| 1126 | // will just throw it rather than allow it to be wrapped in another exception. |
| 1127 | //-------------------------------------------------------------------------------- |
| 1128 | Exception *ExThrowWithInnerHelper(Exception *inner) |
| 1129 | { |
| 1130 | CONTRACTL |
| 1131 | { |
| 1132 | THROWS; |
| 1133 | GC_NOTRIGGER; |
| 1134 | } |
| 1135 | CONTRACTL_END |
| 1136 | |
| 1137 | // Yes, NULL is a legal case. Makes it easier to author uniform helpers for |
| 1138 | // both wrapped and normal exceptions. |
| 1139 | if (inner == NULL) |
| 1140 | { |
| 1141 | return NULL; |
| 1142 | } |
| 1143 | |
| 1144 | if (inner == Exception::GetOOMException()) |
| 1145 | { |
| 1146 | // We don't want to do allocations if we're already throwing an OOM! |
| 1147 | PAL_CPP_THROW(Exception*, inner); |
| 1148 | } |
| 1149 | |
| 1150 | inner = inner->DomainBoundClone(); |
| 1151 | |
| 1152 | // It isn't useful to wrap OOMs and StackOverflows in other exceptions. Just throw them now. |
| 1153 | // |
| 1154 | if (inner->IsTransient()) |
| 1155 | { |
| 1156 | PAL_CPP_THROW(Exception*, inner); |
| 1157 | } |
| 1158 | return inner; |
| 1159 | } |
| 1160 | |
| 1161 | #ifdef _DEBUG |
| 1162 | |
| 1163 | #ifdef _MSC_VER |
| 1164 | #pragma optimize("", off) |
| 1165 | #endif // _MSC_VER |
| 1166 | |
| 1167 | void ExThrowTrap(const char *fcn, const char *file, int line, const char *szType, HRESULT hr, const char *args) |
| 1168 | { |
| 1169 | SUPPORTS_DAC; |
| 1170 | return; |
| 1171 | } |
| 1172 | |
| 1173 | #ifdef _MSC_VER |
| 1174 | #pragma optimize("", on) |
| 1175 | #endif // _MSC_VER |
| 1176 | |
| 1177 | #endif |
| 1178 | |
| 1179 | |
| 1180 | |
| 1181 | |
| 1182 | //------------------------------------------------------------------------------------------- |
| 1183 | // This routine will generate the most descriptive possible error message for an hresult. |
| 1184 | // It will generate at minimum the hex value. It will also try to generate the symbolic name |
| 1185 | // (E_POINTER) and the friendly description (from the message tables.) |
| 1186 | // |
| 1187 | // bNoGeekStuff suppresses hex HR codes. Use this sparingly as most error strings generated by the |
| 1188 | // CLR are aimed at developers, not end-users. |
| 1189 | //------------------------------------------------------------------------------------------- |
| 1190 | void GetHRMsg(HRESULT hr, SString &result, BOOL bNoGeekStuff/* = FALSE*/) |
| 1191 | { |
| 1192 | CONTRACTL |
| 1193 | { |
| 1194 | GC_NOTRIGGER; |
| 1195 | THROWS; |
| 1196 | } |
| 1197 | CONTRACTL_END; |
| 1198 | |
| 1199 | result = W("" ); // Make sure this routine isn't an inadvertent data-leak exploit! |
| 1200 | |
| 1201 | |
| 1202 | |
| 1203 | SString strDescr; |
| 1204 | BOOL fHaveDescr = FALSE; |
| 1205 | |
| 1206 | if (FAILED(hr) && HRESULT_FACILITY(hr) == FACILITY_URT && HRESULT_CODE(hr) < MAX_URT_HRESULT_CODE) |
| 1207 | { |
| 1208 | fHaveDescr = strDescr.LoadResource(CCompRC::Error, MSG_FOR_URT_HR(hr)); |
| 1209 | } |
| 1210 | else |
| 1211 | { |
| 1212 | DWORD dwFlags = FORMAT_MESSAGE_FROM_SYSTEM; |
| 1213 | dwFlags |= FORMAT_MESSAGE_MAX_WIDTH_MASK; |
| 1214 | |
| 1215 | #if FEATURE_USE_LCID |
| 1216 | fHaveDescr = strDescr.FormatMessage(dwFlags, 0, hr, LANG_USER_DEFAULT); |
| 1217 | #else |
| 1218 | fHaveDescr = strDescr.FormatMessage(dwFlags, 0, hr, 0); |
| 1219 | #endif |
| 1220 | } |
| 1221 | |
| 1222 | LPCSTR name = Exception::GetHRSymbolicName(hr); |
| 1223 | |
| 1224 | // If we can't get a resource string, print the hresult regardless. |
| 1225 | if (!fHaveDescr) |
| 1226 | { |
| 1227 | bNoGeekStuff = FALSE; |
| 1228 | } |
| 1229 | |
| 1230 | if (fHaveDescr) |
| 1231 | { |
| 1232 | result.Append(strDescr); |
| 1233 | } |
| 1234 | |
| 1235 | |
| 1236 | if (!bNoGeekStuff) |
| 1237 | { |
| 1238 | if (fHaveDescr) |
| 1239 | { |
| 1240 | result.Append(W(" (" )); |
| 1241 | } |
| 1242 | |
| 1243 | SString strExcepFromHR; |
| 1244 | strExcepFromHR.LoadResource(CCompRC::Error, IDS_EE_EXCEPTION_FROM_HRESULT); |
| 1245 | result.Append(strExcepFromHR); |
| 1246 | result.AppendPrintf(W("0x%.8X" ), hr); |
| 1247 | if (name != NULL) |
| 1248 | { |
| 1249 | result.AppendPrintf(W(" (%S)" ), name); |
| 1250 | } |
| 1251 | |
| 1252 | |
| 1253 | if (fHaveDescr) |
| 1254 | { |
| 1255 | result.Append(W(")" )); |
| 1256 | } |
| 1257 | |
| 1258 | } |
| 1259 | } |
| 1260 | |
| 1261 | |
| 1262 | //------------------------------------------------------------------------------------------- |
| 1263 | // Similar to GetHRMsg but phrased for top-level exception message. |
| 1264 | //------------------------------------------------------------------------------------------- |
| 1265 | void GenerateTopLevelHRExceptionMessage(HRESULT hresult, SString &result) |
| 1266 | { |
| 1267 | CONTRACTL |
| 1268 | { |
| 1269 | GC_NOTRIGGER; |
| 1270 | THROWS; |
| 1271 | } |
| 1272 | CONTRACTL_END; |
| 1273 | |
| 1274 | result = W("" ); // Make sure this routine isn't an inadvertent data-leak exploit! |
| 1275 | |
| 1276 | GetHRMsg(hresult, result); |
| 1277 | } |
| 1278 | |
| 1279 | #if !defined(DACCESS_COMPILE) |
| 1280 | |
| 1281 | void GetCurrentExceptionPointers(PEXCEPTION_POINTERS pExceptionInfo) |
| 1282 | { |
| 1283 | WRAPPER_NO_CONTRACT; |
| 1284 | |
| 1285 | PEXCEPTION_RECORD pRecord = (PEXCEPTION_RECORD)ClrFlsGetValue(TlsIdx_PEXCEPTION_RECORD); |
| 1286 | PCONTEXT pContext = (PCONTEXT)ClrFlsGetValue(TlsIdx_PCONTEXT); |
| 1287 | |
| 1288 | pExceptionInfo->ContextRecord = pContext; |
| 1289 | pExceptionInfo->ExceptionRecord = pRecord; |
| 1290 | |
| 1291 | #ifdef _DEBUG |
| 1292 | if (pRecord != NULL) |
| 1293 | { |
| 1294 | _ASSERTE ((PVOID)(pRecord) > (PVOID)(&pRecord)); |
| 1295 | } |
| 1296 | #endif |
| 1297 | } |
| 1298 | #endif // !defined(DACCESS_COMPILE) |
| 1299 | |
| 1300 | DWORD GetCurrentExceptionCode() |
| 1301 | { |
| 1302 | WRAPPER_NO_CONTRACT; |
| 1303 | SUPPORTS_DAC_HOST_ONLY; |
| 1304 | |
| 1305 | return (DWORD)(size_t)ClrFlsGetValue(TlsIdx_EXCEPTION_CODE); |
| 1306 | } |
| 1307 | |
| 1308 | bool IsCurrentExceptionSO() |
| 1309 | { |
| 1310 | WRAPPER_NO_CONTRACT; |
| 1311 | DWORD exceptionCode = GetCurrentExceptionCode(); |
| 1312 | return IsSOExceptionCode(exceptionCode); |
| 1313 | } |
| 1314 | |
| 1315 | bool IsSOExceptionCode(DWORD exceptionCode) |
| 1316 | { |
| 1317 | if (exceptionCode == STATUS_STACK_OVERFLOW |
| 1318 | #ifdef FEATURE_STACK_PROBE |
| 1319 | || exceptionCode == EXCEPTION_SOFTSO |
| 1320 | #endif |
| 1321 | ) |
| 1322 | { |
| 1323 | return TRUE; |
| 1324 | } |
| 1325 | else |
| 1326 | return FALSE; |
| 1327 | } |
| 1328 | |
| 1329 | |
| 1330 | //=========================================================================================== |
| 1331 | // These abstractions hide the difference between legacy desktop CLR's (that don't support |
| 1332 | // side-by-side-inproc and rely on a fixed SEH code to identify managed exceptions) and |
| 1333 | // new CLR's that support side-by-side inproc. |
| 1334 | // |
| 1335 | // The new CLR's use a different set of SEH codes to avoid conflicting with the legacy CLR's. |
| 1336 | // In addition, to distinguish between EH's raised by different inproc instances of the CLR, |
| 1337 | // the module handle of the owning CLR is stored in ExceptionRecord.ExceptionInformation[4]. |
| 1338 | // |
| 1339 | // (Note: all existing SEH's use either only slot [0] or no slots at all. We are leaving |
| 1340 | // slots [1] thru [3] open for future expansion.) |
| 1341 | //=========================================================================================== |
| 1342 | |
| 1343 | // Is this exception code one of the special CLR-specific SEH codes that participate in the |
| 1344 | // instance-tagging scheme? |
| 1345 | BOOL IsInstanceTaggedSEHCode(DWORD dwExceptionCode) |
| 1346 | { |
| 1347 | LIMITED_METHOD_DAC_CONTRACT; |
| 1348 | |
| 1349 | return dwExceptionCode == EXCEPTION_COMPLUS; |
| 1350 | } |
| 1351 | |
| 1352 | // This set of overloads generates the NumberParameters and ExceptionInformation[] array to |
| 1353 | // pass to RaiseException(). |
| 1354 | // |
| 1355 | // Parameters: |
| 1356 | // exceptionArgs: a fixed-size array of size INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE. |
| 1357 | // This will get filled in by this function. (The module handle goes |
| 1358 | // in the last slot if this is a side-by-side-inproc enabled build.) |
| 1359 | // |
| 1360 | // exceptionArg1... up to four arguments that go in slots [0]..[3]. These depends |
| 1361 | // the specific requirements of your exception code. |
| 1362 | // |
| 1363 | // Returns: |
| 1364 | // The NumberParameters to pass to RaiseException(). |
| 1365 | // |
| 1366 | // Basically, this is either INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE or the count of your |
| 1367 | // fixed arguments depending on whether this tagged-SEH-enabled build. |
| 1368 | // |
| 1369 | // This function is not permitted to fail. |
| 1370 | |
| 1371 | // (the existing system can support more overloads up to 4 fixed arguments but we don't need them at this time.) |
| 1372 | |
| 1373 | static DWORD MarkAsThrownByUsWorker(UINT numArgs, /*out*/ ULONG_PTR exceptionArgs[INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE], ULONG_PTR arg0 = 0) |
| 1374 | { |
| 1375 | STATIC_CONTRACT_NOTHROW; |
| 1376 | STATIC_CONTRACT_GC_NOTRIGGER; |
| 1377 | STATIC_CONTRACT_FORBID_FAULT; |
| 1378 | |
| 1379 | |
| 1380 | _ASSERTE(numArgs < INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE); |
| 1381 | FillMemory(exceptionArgs, sizeof(ULONG_PTR) * INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE, 0); |
| 1382 | |
| 1383 | exceptionArgs[0] = arg0; |
| 1384 | |
| 1385 | #if !defined(FEATURE_UTILCODE_NO_DEPENDENCIES) |
| 1386 | exceptionArgs[INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE - 1] = (ULONG_PTR) (GetCLRModule()); |
| 1387 | #endif // !defined(FEATURE_UTILCODE_NO_DEPENDENCIES) |
| 1388 | |
| 1389 | return INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE; |
| 1390 | } |
| 1391 | |
| 1392 | DWORD MarkAsThrownByUs(/*out*/ ULONG_PTR exceptionArgs[INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE]) |
| 1393 | { |
| 1394 | STATIC_CONTRACT_NOTHROW; |
| 1395 | STATIC_CONTRACT_GC_NOTRIGGER; |
| 1396 | STATIC_CONTRACT_FORBID_FAULT; |
| 1397 | |
| 1398 | return MarkAsThrownByUsWorker(0, exceptionArgs); |
| 1399 | } |
| 1400 | |
| 1401 | DWORD MarkAsThrownByUs(/*out*/ ULONG_PTR exceptionArgs[INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE], ULONG_PTR arg0) |
| 1402 | { |
| 1403 | STATIC_CONTRACT_NOTHROW; |
| 1404 | STATIC_CONTRACT_GC_NOTRIGGER; |
| 1405 | STATIC_CONTRACT_FORBID_FAULT; |
| 1406 | |
| 1407 | return MarkAsThrownByUsWorker(1, exceptionArgs, arg0); |
| 1408 | } |
| 1409 | |
| 1410 | // Given an exception record, checks if it's exception code matches a specific exception code |
| 1411 | // *and* whether it was tagged by the calling instance of the CLR. |
| 1412 | // |
| 1413 | // If this is a non-tagged-SEH-enabled build, it is blindly assumed to be tagged by the |
| 1414 | // calling instance of the CLR. |
| 1415 | BOOL WasThrownByUs(const EXCEPTION_RECORD *pcER, DWORD dwExceptionCode) |
| 1416 | { |
| 1417 | STATIC_CONTRACT_NOTHROW; |
| 1418 | STATIC_CONTRACT_GC_NOTRIGGER; |
| 1419 | STATIC_CONTRACT_FORBID_FAULT; |
| 1420 | STATIC_CONTRACT_SO_TOLERANT; |
| 1421 | STATIC_CONTRACT_SUPPORTS_DAC; |
| 1422 | |
| 1423 | _ASSERTE(IsInstanceTaggedSEHCode(dwExceptionCode)); |
| 1424 | _ASSERTE(pcER != NULL); |
| 1425 | if (dwExceptionCode != pcER->ExceptionCode) |
| 1426 | { |
| 1427 | return FALSE; |
| 1428 | } |
| 1429 | |
| 1430 | if (pcER->NumberParameters != INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE) |
| 1431 | { |
| 1432 | return FALSE; |
| 1433 | } |
| 1434 | #if!defined(FEATURE_UTILCODE_NO_DEPENDENCIES) |
| 1435 | if ( ((ULONG_PTR)(GetCLRModule())) != pcER->ExceptionInformation[INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE - 1] ) |
| 1436 | { |
| 1437 | return FALSE; |
| 1438 | } |
| 1439 | return TRUE; |
| 1440 | #else // !(!defined(FEATURE_UTILCODE_NO_DEPENDENCIES) |
| 1441 | return FALSE; |
| 1442 | #endif // !defined(FEATURE_UTILCODE_NO_DEPENDENCIES) |
| 1443 | } |
| 1444 | |
| 1445 | |
| 1446 | |
| 1447 | //----------------------------------------------------------------------------------- |
| 1448 | // The following group wraps the basic abstracts specifically for EXCEPTION_COMPLUS. |
| 1449 | //----------------------------------------------------------------------------------- |
| 1450 | BOOL IsComPlusException(const EXCEPTION_RECORD *pcER) |
| 1451 | { |
| 1452 | STATIC_CONTRACT_WRAPPER; |
| 1453 | |
| 1454 | return WasThrownByUs(pcER, EXCEPTION_COMPLUS); |
| 1455 | } |
| 1456 | |
| 1457 | VOID RaiseComPlusException() |
| 1458 | { |
| 1459 | STATIC_CONTRACT_THROWS; |
| 1460 | STATIC_CONTRACT_GC_NOTRIGGER; |
| 1461 | STATIC_CONTRACT_FORBID_FAULT; |
| 1462 | |
| 1463 | |
| 1464 | ULONG_PTR exceptionArgs[INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE]; |
| 1465 | DWORD numParams = MarkAsThrownByUs(exceptionArgs); |
| 1466 | RaiseException(EXCEPTION_COMPLUS, 0, numParams, exceptionArgs); |
| 1467 | } |
| 1468 | |
| 1469 | //=========================================================================================== |
| 1470 | //=========================================================================================== |
| 1471 | |