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.

253 lines
8.4 KiB

  1. title "Exception Handling Support Routines"
  2. ;++
  3. ;
  4. ; Copyright (c) 2000 Microsoft Corporation
  5. ;
  6. ; Module Name:
  7. ;
  8. ; xcptmisc.asm
  9. ;
  10. ; Abstract:
  11. ;
  12. ; This module implements stub routines to call language specific handlers
  13. ; for exception dispatching and temrination handling.
  14. ;
  15. ; Author:
  16. ;
  17. ; David N. Cutler (davec) 4-Jul-2000
  18. ;
  19. ; Environment:
  20. ;
  21. ; Any mode.
  22. ;
  23. ;--
  24. include ksamd64.inc
  25. subttl "Local Exception Handler"
  26. ;++
  27. ;
  28. ; EXCEPTION_DISPOSITION
  29. ; RtlpExceptionHandler (
  30. ; IN PEXCEPTION_RECORD ExceptionRecord,
  31. ; IN PVOID EstablisherFrame,
  32. ; IN OUT PCONTEXT ContextRecord,
  33. ; IN OUT PVOID DispatcherContext
  34. ; )
  35. ;
  36. ; Routine Description:
  37. ;
  38. ; This function is called when a nested exception occurs. Its function
  39. ; is to retrieve the establisher frame pointer from its establisher's
  40. ; call frame, store this information in the dispatcher context record,
  41. ; and return a disposition value of nested exception.
  42. ;
  43. ; Arguments:
  44. ;
  45. ; ExceptionRecord (rcx) - Supplies a pointer to an exception record.
  46. ;
  47. ; EstablisherFrame (rdx) - Supplies the frame pointer of the establisher
  48. ; of this exception handler.
  49. ;
  50. ; ContextRecord (r8) - Supplies a pointer to a context record.
  51. ;
  52. ; DispatcherContext (r9) - Supplies a pointer to the dispatcher context
  53. ; record.
  54. ;
  55. ; Return Value:
  56. ;
  57. ; A disposition value nested exception is returned if an unwind is not in
  58. ; progress. Otherwise a value of continue search is returned.
  59. ;
  60. ;--
  61. EhFrame struct
  62. P1Home dq ? ; parameter home addresses for
  63. P2Home dq ? ; called functions
  64. P3Home dq ? ;
  65. P4Home dq ? ;
  66. Context dq ? ; saved dispatcher context address
  67. EhFrame ends
  68. LEAF_ENTRY RtlpExceptionHandler, _TEXT$00
  69. mov eax, ExceptionContinueSearch ; assume unwind in progress
  70. test dword ptr ErExceptionFlags[rcx], EXCEPTION_UNWIND ; check for unwind
  71. jnz short Eh10 ; if nz, unwind in progress
  72. mov rax, EhFrame.Context[rdx] ; get establisher context address
  73. mov rax, DcEstablisherFrame[rax] ; copy the establisher frame
  74. mov DcEstablisherFrame[r9], rax ; to current dispatcher context
  75. mov eax, ExceptionNestedException ; set nested exception disposition
  76. eH10: ret ; return
  77. LEAF_END RtlpExceptionHandler, _TEXT$00
  78. subttl "Execute Handler for Exception"
  79. ;++
  80. ;
  81. ; EXCEPTION_DISPOSITION
  82. ; RtlpExecuteHandlerForException (
  83. ; IN PEXCEPTION_RECORD ExceptionRecord,
  84. ; IN PVOID EstablisherFrame,
  85. ; IN OUT PCONTEXT ContextRecord,
  86. ; IN OUT PVOID DispatcherContext
  87. ; )
  88. ;
  89. ; Routine Description:
  90. ;
  91. ; This function allocates a call frame, saves the dispatcher context address,
  92. ; establishes an exception handler, and calls the specified language specific
  93. ; handler routine. If a nested exception occurs, then the exception handler
  94. ; of this function is called and the establisher frame pointer is returned to
  95. ; the exception dispatcher via the dispatcher context parameter.
  96. ;
  97. ; Arguments:
  98. ;
  99. ; ExceptionRecord (rcx) - Supplies a pointer to an exception record.
  100. ;
  101. ; EstablisherFrame (rdx) - Supplies the frame pointer of the establisher
  102. ; of the exception handler that is to be called.
  103. ;
  104. ; ContextRecord (r8) - Supplies a pointer to a context record.
  105. ;
  106. ; DispatcherContext (r9) - Supplies a pointer to the dispatcher context
  107. ; record.
  108. ;
  109. ; Return Value:
  110. ;
  111. ; The disposition value returned by the specified exception handler is
  112. ; returned as the function value.
  113. ;
  114. ;--
  115. NESTED_ENTRY RtlpExecuteHandlerForException, _TEXT$00, RtlpExceptionHandler
  116. alloc_stack (sizeof EhFrame) ; allocate stack frame
  117. END_PROLOGUE
  118. mov EhFrame.Context[rsp], r9 ; save dispatcher context address
  119. call qword ptr DcLanguageHandler[r9] ; call language handler
  120. nop ; required fill for virtual unwind
  121. add rsp, sizeof EhFrame ; deallocate stack frame
  122. ret ; return
  123. NESTED_END RtlpExecuteHandlerForException, _TEXT$00
  124. subttl "Local Unwind Handler"
  125. ;++
  126. ;
  127. ; EXCEPTION_DISPOSITION
  128. ; RtlpUnwindHandler (
  129. ; IN PEXCEPTION_RECORD ExceptionRecord,
  130. ; IN PVOID EstablisherFrame,
  131. ; IN OUT PCONTEXT ContextRecord,
  132. ; IN OUT PVOID DispatcherContext
  133. ; )
  134. ;
  135. ; Routine Description:
  136. ;
  137. ; This function is called when a collided unwind occurs. Its function
  138. ; is to retrieve the establisher dispatcher context, copy it to the
  139. ; current dispatcher context, and return a disposition value of collided
  140. ; unwind.
  141. ;
  142. ; Arguments:
  143. ;
  144. ; ExceptionRecord (rcx) - Supplies a pointer to an exception record.
  145. ;
  146. ; EstablisherFrame (rdx) - Supplies the frame pointer of the establisher
  147. ; of this exception handler.
  148. ;
  149. ; ContextRecord (r8) - Supplies a pointer to a context record.
  150. ;
  151. ; DispatcherContext (r9) - Supplies a pointer to the dispatcher context
  152. ; record.
  153. ;
  154. ; Return Value:
  155. ;
  156. ; A disposition value collided unwind is returned if an unwind is in
  157. ; progress. Otherwise a value of continue search is returned.
  158. ;
  159. ;--
  160. LEAF_ENTRY RtlpUnwindHandler, _TEXT$00
  161. mov rax, EhFrame.Context[rdx] ; get establisher context address
  162. mov r10, DcControlPc[rax] ; copy control PC
  163. mov DcControlPc[r9], r10 ;
  164. mov r10, DcImageBase[rax] ; copy image base
  165. mov DcImageBase[r9], r10 ;
  166. mov r10, DcFunctionEntry[rax] ; copy function entry
  167. mov DcFunctionentry[r9], r10 ;
  168. mov r10, DcEstablisherFrame[rax] ; copy establisher frame
  169. mov DcEstablisherFrame[r9], r10 ;
  170. mov r10, DcContextRecord[rax] ; copy context record address
  171. mov DcContextRecord[r9], r10 ;
  172. mov r10, DcLanguageHandler[rax] ; copy language handler address
  173. mov DcLanguageHandler[r9], r10 ;
  174. mov r10, DcHandlerData[rax] ; copy handler data address
  175. mov DcHandlerData[r9], r10 ;
  176. mov r10, DcHistoryTable[rax] ; copy history table address
  177. mov DcHistoryTable[r9], r10 ;
  178. mov eax, ExceptionCollidedUnwind ; set collied unwind disposition
  179. ret ; return
  180. LEAF_END RtlpUnwindHandler, _TEXT$00
  181. subttl "Execute Handler for Unwind"
  182. ;++
  183. ;
  184. ; EXCEPTION_DISPOSITION
  185. ; RtlpExecuteHandlerForUnwind (
  186. ; IN PEXCEPTION_RECORD ExceptionRecord,
  187. ; IN PVOID EstablisherFrame,
  188. ; IN OUT PCONTEXT ContextRecord,
  189. ; IN OUT PVOID DispatcherContext
  190. ; )
  191. ;
  192. ; Routine Description:
  193. ;
  194. ; This function allocates a call frame, saves the dispatcher context address,
  195. ; establishes an exception handler, and calls the specified unwind handler.
  196. ; If a collided unwind occurs, then the exception handler of this function is
  197. ; called and the establisher dispatcher context is copied to the current
  198. ; dispatcher context via the dispatcher context parameter.
  199. ;
  200. ; Arguments:
  201. ;
  202. ; ExceptionRecord (rcx) - Supplies a pointer to an exception record.
  203. ;
  204. ; EstablisherFrame (rdx) - Supplies the frame pointer of the establisher
  205. ; of the exception handler that is to be called.
  206. ;
  207. ; ContextRecord (r8) - Supplies a pointer to a context record.
  208. ;
  209. ; DispatcherContext (r9) - Supplies a pointer to the dispatcher context
  210. ; record.
  211. ;
  212. ; ExceptionRoutine (5 * 8[rsp]) - Supplies a pointer to the exception
  213. ; handler that is to be called.
  214. ;
  215. ; Return Value:
  216. ;
  217. ; The disposition value returned by the specified exception handler is
  218. ; returned as the function value.
  219. ;
  220. ;--
  221. NESTED_ENTRY RtlpExecuteHandlerForUnwind, _TEXT$00, RtlpUnwindHandler
  222. alloc_stack (sizeof EhFrame) ; allocate stack frame
  223. END_PROLOGUE
  224. mov EhFrame.Context[rsp], r9 ; save dispatcher context address
  225. call qword ptr DcLanguageHandler[r9] ; call exception handler
  226. nop ; required fill for virtual unwind
  227. add rsp, sizeof EhFrame ; deallocate stack frame
  228. ret ; return
  229. NESTED_END RtlpExecuteHandlerForUnwind, _TEXT$00
  230. end