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.

158 lines
4.6 KiB

  1. //++
  2. //
  3. //extern "C"
  4. //VOID
  5. //_GetNextInstrOffset (
  6. // PVOID* ppReturnPoint
  7. // );
  8. //
  9. //Routine Description:
  10. //
  11. // This function scans the scope tables associated with the specified
  12. // procedure and calls exception and termination handlers as necessary.
  13. //
  14. //Arguments:
  15. //
  16. // ppReturnPoint (r32) - store b0 in *pReturnPoint
  17. //
  18. //Return Value:
  19. //
  20. // None
  21. //
  22. //--
  23. .global _GetNextInstrOffset#
  24. .proc _GetNextInstrOffset#
  25. .align 32
  26. _GetNextInstrOffset:
  27. alloc r2=1, 0, 0, 0
  28. mov r3 = b0;;
  29. st8 [r32]=r3
  30. br.ret.sptk.few b0
  31. .endp _GetNextInstrOffset#
  32. //++
  33. //
  34. //extern "C"
  35. //PVOID
  36. //__Cxx_ExecuteHandler (
  37. // ULONGLONG MemoryStack,
  38. // ULONGLONG BackingStore,
  39. // ULONGLONG Handler,
  40. // ULONGLONG GlobalPointer
  41. // );
  42. //
  43. //Routine Description:
  44. //
  45. // This function scans the scope tables associated with the specified
  46. // procedure and calls exception and termination handlers as necessary.
  47. //
  48. //Arguments:
  49. //
  50. // MemoryStack (r32) - memory stack pointer of establisher frame
  51. //
  52. // BackingStore (r33) - backing store pointer of establisher frame
  53. //
  54. // Handler (r34) - Entry point of handler
  55. //
  56. // GlobalPointer (r35) - GP of termination handler
  57. //
  58. //Return Value:
  59. //
  60. // Returns the continuation point
  61. //
  62. //--
  63. .global __Cxx_ExecuteHandler#
  64. .proc __Cxx_ExecuteHandler#
  65. .align 32
  66. __Cxx_ExecuteHandler:
  67. mov gp = r35 // set new GP
  68. mov b6 = r34 // handler address
  69. br b6 // branch to handler
  70. .endp __Cxx_ExecuteHandler#
  71. //++
  72. //
  73. //extern "C" void* _CallSettingFrame(
  74. // void* handler,
  75. // EHRegistrationNode *pEstablisher,
  76. // ULONG NLG_CODE)
  77. //
  78. //--
  79. .global _NLG_Notify
  80. .type _NLG_Notify, @function
  81. .global _GetTargetGP
  82. .type _GetTargetGP, @function
  83. .global _GetImageBase
  84. .type _GetImageBase, @function
  85. .global _SetImageBase
  86. .type _SetImageBase, @function
  87. .global _CallSettingFrame
  88. .global __NLG_Return
  89. .proc _CallSettingFrame
  90. .align 32
  91. .prologue
  92. _CallSettingFrame:
  93. .save ar.pfs,r35
  94. alloc loc0 = ar.pfs, 3, 8, 4, 0
  95. .save rp,loc1
  96. mov loc1 = b0 // save important stuff
  97. .save pr,loc2
  98. mov loc2 = pr
  99. mov loc3 = gp
  100. .body
  101. ld8 loc5 = [in1],0x8 // pEstablisher->MemoryStackBP
  102. ;;
  103. ld8 loc6 = [in1] // pEstablisher->BackingStoreBP
  104. mov out0 = in0 // pass the target address
  105. br.call.sptk b0 = _GetTargetGP // Get target's GP
  106. ;;
  107. mov loc4 = ret0
  108. br.call.sptk b0 = _GetImageBase //Get current image base
  109. ;;
  110. mov loc7 = ret0 // save current image base
  111. mov out0 = in0 // handler address
  112. mov out1 = loc5 // pEstablisher->MemoryStackBP
  113. mov out2 = loc6 // pEstablisher->BackingStoreBP
  114. mov out3 = in2 // NLG_CODE
  115. br.call.sptk b0 = _NLG_Notify // Notify debugger about transferring control to the handler
  116. ;;
  117. mov gp = loc4 // set hanlder's GP
  118. mov out0 = loc5 // pEstablisher->MemoryStackBP
  119. mov out1 = loc6 // pEstablisher->BackingStoreBP
  120. mov b6 = in0 // hanlder address
  121. br.call.sptk b0 = b6 // call the handler (pEstablisher->MemoryStackBP, pEstablisher->BackingStoreBP)
  122. ;;
  123. __NLG_Return:
  124. mov gp = loc3 // restore gp
  125. cmp.eq p14,p5 = ret0, r0 // did the handler return a continuation address?
  126. ;;
  127. (p14) mov loc3 = 0 // if it didn'just return 0
  128. (p5) mov loc3 = ret0 // if it did then it was image base relative for 2.5, so fix it up
  129. mov out0 = loc7 // Restore image base in TLS, the handler could call an other dll with different image base
  130. br.call.sptk b0 = _SetImageBase
  131. ;;
  132. (p5) add loc3 = loc7, loc3 // ImageBase + handler's return for 2.5
  133. ;;
  134. mov loc4 = 0x100 // NLG_CATCH_ENTER
  135. ;;
  136. cmp.eq p14,p15 = loc4, in2 // if NLG_CODE == NLG_CATCH_ENTER notify debugger again about continuing mainstream
  137. ;;
  138. mov out3 = 0x2 // NLG_CATCH_LEAVE
  139. mov out1 = loc5 // pEstablisher->MemoryStackBP
  140. mov out2 = loc6 // pEstablisher->BackingStoreBP
  141. mov out0 = loc3 // handler continuation address
  142. (p14) br.call.sptk b0 = _NLG_Notify
  143. ;;
  144. mov ret0 = loc3
  145. mov b0 = loc1 // restore stuff
  146. mov pr = loc2
  147. mov ar.pfs = loc0
  148. br.ret.sptk b0
  149. .endp _CallSettingFrame