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.

316 lines
8.1 KiB

  1. title "Raise Exception"
  2. ;++
  3. ;
  4. ; Copyright (c) 1990 Microsoft Corporation
  5. ;
  6. ; Module Name:
  7. ;
  8. ; raisests.asm
  9. ;
  10. ; Abstract:
  11. ;
  12. ; This module implements the function to raise a software exception.
  13. ;
  14. ; Author:
  15. ;
  16. ; Bryan Willman 11 Nov 90
  17. ;
  18. ; Environment:
  19. ;
  20. ; Any mode.
  21. ;
  22. ; Revision History:
  23. ;
  24. ;--
  25. .386p
  26. .xlist
  27. include ks386.inc
  28. include callconv.inc ; calling convention macros
  29. .list
  30. EXTRNP _RtlDispatchException,2
  31. EXTRNP _ZwContinue,2
  32. EXTRNP _ZwRaiseException,3
  33. _TEXT$01 SEGMENT DWORD PUBLIC 'CODE'
  34. ASSUME DS:FLAT, ES:FLAT, SS:NOTHING, FS:NOTHING, GS:NOTHING
  35. ;
  36. ; Context flags definition.
  37. ;
  38. CONTEXT_SETTING EQU CONTEXT_INTEGER OR CONTEXT_CONTROL OR CONTEXT_SEGMENTS
  39. ;
  40. ; Exception record length definition.
  41. ;
  42. EXCEPTION_RECORD_LENGTH EQU (ErExceptionInformation + 16) AND 0fffffff0H
  43. page
  44. subttl "Raise Software Exception"
  45. ;++
  46. ;
  47. ; VOID
  48. ; ExRaiseException (
  49. ; IN PEXCEPTION_RECORD ExceptionRecord
  50. ; )
  51. ;
  52. ; Routine Description:
  53. ;
  54. ; This function raises a software exception by building a context record,
  55. ; establishing the stack limits of the current processor mode, and calling
  56. ; the exception dispatcher. If the exception dispatcher finds a handler
  57. ; to process the exception, then control is returned to the caller using
  58. ; the NtContinue system service. Otherwise the NtLastChance system service
  59. ; is called to provide default handing.
  60. ;
  61. ; N.B. On the 386, floating point state is not defined for non-fp
  62. ; exceptions. Therefore, this routine does not attempt to
  63. ; capture it.
  64. ;
  65. ; This means this routine cannot be used to report fp exceptions.
  66. ;
  67. ; Arguments:
  68. ;
  69. ; ExceptionRecord (ebp+8) - Supplies a pointer to an exception record.
  70. ;
  71. ; Return Value:
  72. ;
  73. ; None.
  74. ;
  75. ;--
  76. cPublicProc _ExRaiseException , 1
  77. push ebp
  78. mov ebp,esp
  79. pushfd ; save flags before sub
  80. sub esp,ContextFrameLength ; Allocate a context record
  81. ;
  82. ; Save regs we use in context record
  83. ;
  84. mov [(ebp-ContextFrameLength-4)+CsEax],eax
  85. mov [(ebp-ContextFrameLength-4)+CsEcx],ecx
  86. ;
  87. ; Get pointer to exception report record, and set the exceptionaddress
  88. ; field to be our return address
  89. ;
  90. mov eax,[ebp+8] ; (eax) -> ExceptionReportRecord
  91. mov ecx,[ebp+4]
  92. mov [eax.ErExceptionAddress],ecx
  93. ;
  94. ; Copy machine context into the context record
  95. ;
  96. lea eax,[ebp-ContextFrameLength-4] ; (eax) -> Context record
  97. mov [eax.CsEip],ecx
  98. mov [eax.CsEbx],ebx
  99. mov [eax.CsEdx],edx
  100. mov [eax.CsEsi],esi
  101. mov [eax.CsEdi],edi
  102. lea ecx,[ebp+8]
  103. mov [eax.CsEsp],ecx
  104. mov ecx,[ebp]
  105. mov [eax.CsEbp],ecx
  106. mov ecx,[ebp-4]
  107. mov [eax.CsEflags],ecx
  108. mov dword ptr [eax.CsSegCs],cs
  109. mov dword ptr [eax.CsSegDs],ds
  110. mov dword ptr [eax.CsSegEs],es
  111. mov dword ptr [eax.CsSegFs],fs
  112. mov dword ptr [eax.CsSegGs],gs
  113. mov dword ptr [eax.CsSegSs],ss
  114. ;
  115. ; Set Context flags, note that FLOATING_POINT is NOT set.
  116. ;
  117. mov dword ptr [eax.CsContextFlags],CONTEXT_SETTING
  118. ;
  119. ; _RtlDispatchException(ExceptionRecord, ContextRecord)
  120. ;
  121. stdCall _RtlDispatchException, <[ebp+8],eax>
  122. ;
  123. ; If the exception is successfully dispatched, then continue execution.
  124. ; Otherwise, give the kernel debugger a chance to handle the exception.
  125. ;
  126. lea ecx,[ebp-ContextFrameLength-4] ; (eax) -> Context record
  127. or eax, eax
  128. jz short ere10
  129. stdCall _ZwContinue, <ecx,0>
  130. jmp short ere20
  131. ere10:
  132. stdCall _ZwRaiseException, <[ebp+8],ecx,0>
  133. ere20:
  134. ;
  135. ; Either the attempt to continue execution or the attempt to give
  136. ; the kernel debugger a chance to handle the exception failed. Raise
  137. ; a noncontinuable exception.
  138. ;
  139. stdCall _ExRaiseStatus, <eax>
  140. stdENDP _ExRaiseException
  141. page
  142. subttl "Raise Software Exception"
  143. ;++
  144. ;
  145. ; VOID
  146. ; ExRaiseStatus (
  147. ; IN NTSTATUS Status
  148. ; )
  149. ;
  150. ; Routine Description:
  151. ;
  152. ; This function raises a software exception with the specified status value
  153. ; by building a context record, establishing the stack limits of the current
  154. ; processor mode, and calling the exception dispatcher. If the exception
  155. ; dispatcher finds a handler to process the exception, then control is
  156. ; returned to the caller using the NtContinue system service. Otherwise
  157. ; the NtLastChance system service is called to provide default handing.
  158. ;
  159. ; N.B. On the 386, floating point state is not defined for non-fp
  160. ; exceptions. Therefore, this routine does not attempt to
  161. ; capture it.
  162. ;
  163. ; This means this routine cannot be used to report fp exceptions.
  164. ;
  165. ; Arguments:
  166. ;
  167. ; Status - Supplies the status value to be used as the exception code
  168. ; for the exception that is to be raised.
  169. ;
  170. ; Return Value:
  171. ;
  172. ; None.
  173. ; Arguments:
  174. ;
  175. ;--
  176. cPublicProc _ExRaiseStatus,1
  177. push ebp
  178. mov ebp,esp
  179. pushfd ; save flags before sub
  180. sub esp,ContextFrameLength+ExceptionRecordLength
  181. ;
  182. ; Save regs we use in context record
  183. ;
  184. mov [(ebp-ContextFrameLength-4)+CsEax],eax
  185. mov [(ebp-ContextFrameLength-4)+CsEcx],ecx
  186. ;
  187. ; Copy machine context into the context record
  188. ;
  189. lea eax,[ebp-ContextFrameLength-4] ; (eax) -> Context record
  190. mov ecx,[ebp+4] ; [ecx] = returned address
  191. mov [eax.CsEip],ecx
  192. mov [eax.CsEbx],ebx
  193. mov [eax.CsEdx],edx
  194. mov [eax.CsEsi],esi
  195. mov [eax.CsEdi],edi
  196. lea ecx,[ebp+8]
  197. mov [eax.CsEsp],ecx
  198. mov ecx,[ebp]
  199. mov [eax.CsEbp],ecx
  200. mov ecx,[ebp-4]
  201. mov [eax.CsEflags],ecx
  202. mov dword ptr [eax.CsSegCs],cs
  203. mov dword ptr [eax.CsSegDs],ds
  204. mov dword ptr [eax.CsSegEs],es
  205. mov dword ptr [eax.CsSegFs],fs
  206. mov dword ptr [eax.CsSegGs],gs
  207. mov dword ptr [eax.CsSegSs],ss
  208. ;
  209. ; Set Context flags, note that FLOATING_POINT is NOT set.
  210. ;
  211. mov dword ptr [eax.CsContextFlags],CONTEXT_SETTING
  212. ;
  213. ; Get pointer to exception report record, and set the exceptionaddress
  214. ; field to be our return address
  215. ;
  216. lea eax,[ebp-ContextFrameLength-ExceptionRecordLength-4]
  217. ; (eax) -> ExceptionRecord
  218. mov ecx,[ebp+4]
  219. mov dword ptr [eax.ErExceptionAddress],ecx
  220. mov ecx,[ebp+8]
  221. mov dword ptr [eax.ErExceptionCode],ecx
  222. mov dword ptr [eax.ErNumberParameters], 0
  223. mov dword ptr [eax.ErExceptionRecord], 0
  224. mov dword ptr [eax.ErExceptionFlags], EXCEPTION_NONCONTINUABLE
  225. ;
  226. ; _RtlDispatchException(ExceptionRecord, ContextRecord)
  227. ;
  228. lea ecx,[ebp-ContextFrameLength-4] ; (eax) -> Context record
  229. ; ecx - Context record
  230. ; eax - Exception record
  231. stdCall _RtlDispatchException, <eax, ecx>
  232. ;
  233. ; An unwind was not initiated during the dispatching of a noncontinuable
  234. ; exception. Give the kernel debugger a chance to handle the exception.
  235. ;
  236. ;
  237. ; _ZwRaiseException(ExceptionRecord, ContextRecord, FirstChance=TRUE)
  238. ;
  239. lea ecx,[ebp-ContextFrameLength-4] ; (eax) -> Context record
  240. lea eax,[ebp-ContextFrameLength-ExceptionRecordLength-4]
  241. ; 1 - TRUE
  242. ; ecx - Context Record
  243. ; eax - Exception Report Record
  244. stdCall _ZwRaiseException, <eax, ecx, 1>
  245. ;
  246. ; We came back, suggesting some sort of error in the call. Raise
  247. ; a status exception to report this, return from ZwRaiseException is type.
  248. ;
  249. stdCall _ExRaiseStatus, <eax>
  250. stdENDP _ExRaiseStatus
  251. _TEXT$01 ends
  252. end
  253.