Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
4.5 KiB

  1. /***
  2. *throw.cxx - Implementation of the 'throw' command.
  3. *
  4. * Copyright (c) 1993-2001, 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. *Revision History:
  13. * 05-25-93 BS Module created
  14. * 09-29-94 GJF Made (__)pMyUnhandledExceptionFilter global so the
  15. * compiler (DEC Alpha) wouldn't optimize it away.
  16. * 10-17-94 BWT Disable code for PPC.
  17. * 02-03-95 BWT Remove Alpha export hack.
  18. * 02-09-95 JWM Mac merge.
  19. * 04-13-95 DAK Add NT Kernel EH support
  20. * 04-25-95 DAK More Kernel work
  21. * 03-02-98 RKP Add 64 bit support
  22. * 05-17-99 PML Remove all Macintosh support.
  23. * 03-15-00 PML Remove CC_P7_SOFT25, which is now on permanently.
  24. * 12-07-01 BWT Remove NTSUBSET
  25. *
  26. ****/
  27. #include <stddef.h>
  28. #include <windows.h>
  29. #include <mtdll.h>
  30. #include <ehdata.h>
  31. #include <eh.h>
  32. #include <ehhooks.h>
  33. #include <ehassert.h>
  34. #pragma hdrstop
  35. //
  36. // Make sure PULONG_PTR is available
  37. //
  38. #if defined(_X86_) && _MSC_VER >= 1300
  39. #define _W64 __w64
  40. #else
  41. #define _W64
  42. #endif
  43. #if !defined(PULONG_PTR)
  44. #if defined(_WIN64)
  45. typedef unsigned __int64 * PULONG_PTR;
  46. #else
  47. typedef _W64 unsigned long * PULONG_PTR;
  48. #endif
  49. #endif
  50. #if defined(_M_IA64) || defined(_M_AMD64)
  51. extern "C" PVOID RtlPcToFileHeader(PVOID, PVOID*);
  52. extern "C" PVOID _ReturnAddress(VOID);
  53. #pragma intrinsic(_ReturnAddress)
  54. #endif
  55. //
  56. // Make sure the terminate wrapper is dragged in:
  57. //
  58. void * __pMyUnhandledExceptionFilter = &__CxxUnhandledExceptionFilter;
  59. /////////////////////////////////////////////////////////////////////////////
  60. //
  61. // _CxxThrowException - implementation of 'throw'
  62. //
  63. // Description:
  64. // Builds the NT Exception record, and calls the NT runtime to initiate
  65. // exception processing.
  66. //
  67. // Why is pThrowInfo defined as _ThrowInfo? Because _ThrowInfo is secretly
  68. // snuck into the compiler, as is the prototype for _CxxThrowException, so
  69. // we have to use the same type to keep the compiler happy.
  70. //
  71. // Another result of this is that _CRTIMP can't be used here. Instead, we
  72. // synthesisze the -export directive below.
  73. //
  74. // Returns:
  75. // NEVER. (until we implement resumable exceptions, that is)
  76. //
  77. extern "C" void __stdcall _CxxThrowException(
  78. void* pExceptionObject, // The object thrown
  79. #if _MSC_VER >= 900 /*IFSTRIP=IGN*/
  80. _ThrowInfo* pThrowInfo // Everything we need to know about it
  81. #else
  82. ThrowInfo* pThrowInfo // Everything we need to know about it
  83. #endif
  84. ) {
  85. EHTRACE_ENTER_FMT1("Throwing object @ 0x%p", pExceptionObject);
  86. static const EHExceptionRecord ExceptionTemplate = { // A generic exception record
  87. EH_EXCEPTION_NUMBER, // Exception number
  88. EXCEPTION_NONCONTINUABLE, // Exception flags (we don't do resume)
  89. NULL, // Additional record (none)
  90. NULL, // Address of exception (OS fills in)
  91. EH_EXCEPTION_PARAMETERS, // Number of parameters
  92. { EH_MAGIC_NUMBER1, // Our version control magic number
  93. NULL, // pExceptionObject
  94. NULL,
  95. #if defined(_M_IA64) || defined (_M_AMD64)
  96. NULL // Image base of thrown object
  97. #endif
  98. } // pThrowInfo
  99. };
  100. EHExceptionRecord ThisException = ExceptionTemplate; // This exception
  101. //
  102. // Fill in the blanks:
  103. //
  104. ThisException.params.pExceptionObject = pExceptionObject;
  105. ThisException.params.pThrowInfo = (ThrowInfo*)pThrowInfo;
  106. #if defined(_M_IA64) || defined(_M_AMD64)
  107. PVOID ThrowImageBase = RtlPcToFileHeader(_ReturnAddress(), &ThrowImageBase);
  108. ThisException.params.pThrowImageBase = ThrowImageBase;
  109. #endif
  110. //
  111. // Hand it off to the OS:
  112. //
  113. EHTRACE_EXIT;
  114. #if defined(_M_AMD64)
  115. RtlRaiseException( (PEXCEPTION_RECORD) &ThisException );
  116. #else
  117. RaiseException( ThisException.ExceptionCode,
  118. ThisException.ExceptionFlags,
  119. ThisException.NumberParameters,
  120. (PULONG_PTR)&ThisException.params );
  121. #endif
  122. }