Source code of Windows XP (NT5)
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.

145 lines
4.0 KiB

  1. //
  2. // Created by TiborL 06/01/97
  3. //
  4. #if defined(_NTSUBSET_)
  5. extern "C" {
  6. #include <nt.h>
  7. #include <ntrtl.h>
  8. #include <nturtl.h>
  9. #include <ntstatus.h> // STATUS_UNHANDLED_EXCEPTION
  10. #include <ntos.h>
  11. #include <ex.h> // ExRaiseException
  12. }
  13. #endif
  14. extern "C" {
  15. #include "windows.h"
  16. }
  17. #include "ehassert.h"
  18. #include "ehdata.h" // Declarations of all types used for EH
  19. #include "ehstate.h"
  20. #include "eh.h"
  21. #include "ehhooks.h"
  22. #include "trnsctrl.h"
  23. #pragma hdrstop
  24. __ehstate_t _StateFromIp(
  25. FuncInfo *pFuncInfo,
  26. DispatcherContext *pDC,
  27. __int64 Ip
  28. ) {
  29. unsigned int index; // loop control variable
  30. unsigned int nIPMapEntry; // # of IpMapEntry; must be > 0
  31. DASSERT(pFuncInfo != NULL);
  32. nIPMapEntry = FUNC_NIPMAPENT(*pFuncInfo);
  33. DASSERT(FUNC_IPMAP(*pFuncInfo, pDC->ImageBase) != NULL);
  34. for (index = 0; index < nIPMapEntry; index++) {
  35. IptoStateMapEntry *pIPtoStateMap = FUNC_PIPTOSTATE(*pFuncInfo, index, pDC->ImageBase);
  36. if( Ip < (pDC->ImageBase + pIPtoStateMap->Ip) ) {
  37. break;
  38. }
  39. }
  40. if (index == 0) {
  41. // We are at the first entry, could be an error
  42. return EH_EMPTY_STATE;
  43. }
  44. // We over-shot one iteration; return state from the previous slot
  45. return FUNC_IPTOSTATE(*pFuncInfo, index - 1, pDC->ImageBase).State;
  46. }
  47. __ehstate_t _StateFromControlPc(
  48. FuncInfo *pFuncInfo,
  49. DispatcherContext *pDC
  50. ) {
  51. return _StateFromIp(pFuncInfo, pDC, pDC->ControlPc);
  52. }
  53. #if 0
  54. //
  55. // Given a state, return the corresponding IP
  56. //
  57. ULONG _GetIpFromState(FuncInfo *pFuncInfo, __ehstate_t state)
  58. {
  59. unsigned int index; // loop control variable
  60. unsigned int nIPMapEntry; // # of IpMapEntry; must be > 0
  61. DASSERT(pFuncInfo != NULL);
  62. nIPMapEntry = FUNC_NIPMAPENT(*pFuncInfo);
  63. DASSERT(FUNC_IPMAP(*pFuncInfo) != NULL);
  64. for (index = 0; index < nIPMapEntry; index++) {
  65. if (state == FUNC_IPTOSTATE(*pFuncInfo, index).State) {
  66. return FUNC_IPTOSTATE(*pFuncInfo, index).Ip;
  67. }
  68. }
  69. return EH_EMPTY_STATE;
  70. }
  71. #endif
  72. //
  73. // This routine is a replacement for the corresponding macro in 'ehdata.h'
  74. //
  75. __ehstate_t GetCurrentState(
  76. EHRegistrationNode *pFrame,
  77. DispatcherContext *pDC,
  78. FuncInfo *pFuncInfo
  79. ) {
  80. if( _ExecutionInCatch(pDC,pFuncInfo) ) {
  81. if( UNWINDSTATE(pDC->EstablisherFrame.MemoryStackFp, -16) == -2 )
  82. return _StateFromControlPc(pFuncInfo, pDC);
  83. else
  84. return UNWINDSTATE(pDC->EstablisherFrame.MemoryStackFp, -16);
  85. }
  86. else if( UNWINDSTATE(pFrame->MemoryStackFp, FUNC_DISPUNWINDHELP(*pFuncInfo)) == -2 ) {
  87. return _StateFromControlPc(pFuncInfo, pDC);
  88. }
  89. else {
  90. return UNWINDSTATE(pFrame->MemoryStackFp, FUNC_DISPUNWINDHELP(*pFuncInfo));
  91. }
  92. }
  93. VOID SetState(
  94. EHRegistrationNode *pRN,
  95. DispatcherContext *pDC,
  96. FuncInfo *pFuncInfo,
  97. __ehstate_t newState
  98. ){
  99. if( _ExecutionInCatch(pDC,pFuncInfo) ) {
  100. UNWINDSTATE(pDC->EstablisherFrame.MemoryStackFp, -16) = newState;
  101. }
  102. else {
  103. UNWINDSTATE(pRN->MemoryStackFp, FUNC_DISPUNWINDHELP(*pFuncInfo)) = newState;
  104. }
  105. }
  106. VOID SetUnwindTryBlock(
  107. EHRegistrationNode *pRN,
  108. DispatcherContext *pDC,
  109. FuncInfo *pFuncInfo,
  110. INT curState
  111. ){
  112. EHRegistrationNode EstablisherFramePointers;
  113. _GetEstablisherFrame(pRN, pDC, pFuncInfo, &EstablisherFramePointers);
  114. if( curState > UNWINDTRYBLOCK(EstablisherFramePointers.MemoryStackFp, FUNC_DISPUNWINDHELP(*pFuncInfo)) ) {
  115. UNWINDTRYBLOCK(EstablisherFramePointers.MemoryStackFp, FUNC_DISPUNWINDHELP(*pFuncInfo)) = curState;
  116. }
  117. }
  118. INT GetUnwindTryBlock(
  119. EHRegistrationNode *pRN,
  120. DispatcherContext *pDC,
  121. FuncInfo *pFuncInfo
  122. ){
  123. EHRegistrationNode EstablisherFramePointers;
  124. _GetEstablisherFrame(pRN, pDC, pFuncInfo, &EstablisherFramePointers);
  125. return UNWINDTRYBLOCK(EstablisherFramePointers.MemoryStackFp, FUNC_DISPUNWINDHELP(*pFuncInfo));
  126. }