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.

114 lines
3.1 KiB

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