Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.71 KB | None | 0 0
  1. /***
  2. *throw.cpp - Implementation of the 'throw' command.
  3. *
  4. * Copyright (c) Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Implementation of the exception handling 'throw' command.
  8. *
  9. * Entry points:
  10. * * _CxxThrowException - does the throw.
  11. ****/
  12.  
  13. #include <ehdata.h>
  14. #include <ehassert.h>
  15. #include <trnsctrl.h>
  16.  
  17. #include <Windows.h>
  18.  
  19. //
  20. // Make sure PULONG_PTR is available
  21. //
  22.  
  23. #if !defined(PULONG_PTR)
  24. #if defined(_WIN64)
  25. typedef unsigned __int64 * PULONG_PTR;
  26. #else
  27. typedef unsigned long * PULONG_PTR;
  28. #endif
  29. #endif
  30.  
  31. #if defined(_M_X64)
  32. extern "C" PVOID _ReturnAddress(VOID);
  33. #pragma intrinsic(_ReturnAddress)
  34. #endif
  35.  
  36. /////////////////////////////////////////////////////////////////////////////
  37. //
  38. // _CxxThrowException - implementation of 'throw'
  39. //
  40. // Description:
  41. // Builds the NT Exception record, and calls the NT runtime to initiate
  42. // exception processing.
  43. //
  44. // Why is pThrowInfo defined as _ThrowInfo? Because _ThrowInfo is secretly
  45. // snuck into the compiler, as is the prototype for _CxxThrowException, so
  46. // we have to use the same type to keep the compiler happy.
  47. //
  48. // Another result of this is that _CRTIMP can't be used here. Instead, we
  49. // synthesisze the -export directive below.
  50. //
  51. // Returns:
  52. // NEVER. (until we implement resumable exceptions, that is)
  53. //
  54. extern "C" void __stdcall
  55. _CxxThrowException(
  56. void* pExceptionObject, // The object thrown
  57. _ThrowInfo* pThrowInfo // Everything we need to know about it
  58. ) {
  59. EHTRACE_ENTER_FMT1("Throwing object @ 0x%p", pExceptionObject);
  60.  
  61. static const EHExceptionRecord ExceptionTemplate = { // A generic exception record
  62. EH_EXCEPTION_NUMBER, // Exception number
  63. EXCEPTION_NONCONTINUABLE, // Exception flags (we don't do resume)
  64. nullptr, // Additional record (none)
  65. nullptr, // Address of exception (OS fills in)
  66. EH_EXCEPTION_PARAMETERS, // Number of parameters
  67. { EH_MAGIC_NUMBER1, // Our version control magic number
  68. nullptr, // pExceptionObject
  69. nullptr,
  70. #if _EH_RELATIVE_TYPEINFO
  71. nullptr // Image base of thrown object
  72. #endif
  73. } // pThrowInfo
  74. };
  75. EHExceptionRecord ThisException = ExceptionTemplate; // This exception
  76.  
  77. ThrowInfo* pTI = (ThrowInfo*)pThrowInfo;
  78. if (pTI && (THROW_ISWINRT( (*pTI) ) ) )
  79. {
  80. ULONG_PTR *exceptionInfoPointer = *reinterpret_cast<ULONG_PTR**>(pExceptionObject);
  81. exceptionInfoPointer--; // The pointer to the ExceptionInfo structure is stored sizeof(void*) infront of each WinRT Exception Info.
  82.  
  83. WINRTEXCEPTIONINFO** ppWei = reinterpret_cast<WINRTEXCEPTIONINFO**>(exceptionInfoPointer);
  84. pTI = (*ppWei)->throwInfo;
  85.  
  86. (*ppWei)->PrepareThrow( ppWei );
  87. }
  88.  
  89. //
  90. // Fill in the blanks:
  91. //
  92. ThisException.params.pExceptionObject = pExceptionObject;
  93. ThisException.params.pThrowInfo = pTI;
  94. #if _EH_RELATIVE_TYPEINFO
  95. PVOID ThrowImageBase = RtlPcToFileHeader((PVOID)pTI, &ThrowImageBase);
  96. ThisException.params.pThrowImageBase = ThrowImageBase;
  97. #endif
  98.  
  99. //
  100. // If the throw info indicates this throw is from a pure region,
  101. // set the magic number to the Pure one, so only a pure-region
  102. // catch will see it.
  103. //
  104. // Also use the Pure magic number on Win64 if we were unable to
  105. // determine an image base, since that was the old way to determine
  106. // a pure throw, before the TI_IsPure bit was added to the FuncInfo
  107. // attributes field.
  108. //
  109. if (pTI != nullptr)
  110. {
  111. if (THROW_ISPURE(*pTI))
  112. {
  113. ThisException.params.magicNumber = EH_PURE_MAGIC_NUMBER1;
  114. }
  115. #if _EH_RELATIVE_TYPEINFO
  116. else if (ThrowImageBase == nullptr)
  117. {
  118. ThisException.params.magicNumber = EH_PURE_MAGIC_NUMBER1;
  119. }
  120. #endif
  121. }
  122.  
  123. //
  124. // Hand it off to the OS:
  125. //
  126.  
  127. EHTRACE_EXIT;
  128. #if defined(_M_X64) && defined(_NTSUBSET_)
  129. RtlRaiseException( (PEXCEPTION_RECORD) &ThisException );
  130. #else
  131. RaiseException( ThisException.ExceptionCode,
  132. ThisException.ExceptionFlags,
  133. ThisException.NumberParameters,
  134. (PULONG_PTR)&ThisException.params );
  135. #endif
  136.  
  137. <<<<<hier der breakpoint
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement