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.

103 lines
2.9 KiB

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