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.

323 lines
8.7 KiB

  1. title "User Mode Dispatcher Code"
  2. ;++
  3. ;
  4. ; Copyright (c) 1989 Microsoft Corporation
  5. ;
  6. ; Module Name:
  7. ;
  8. ; userdisp.asm
  9. ;
  10. ; Abstract:
  11. ;
  12. ; The module contains procedures to do user mode dispatching
  13. ; ("trampolining") of user apcs and user exceptions.
  14. ;
  15. ; Author:
  16. ;
  17. ; Bryan M Willman (bryanwi) 31-Aug-90
  18. ;
  19. ; Environment:
  20. ;
  21. ; User mode.
  22. ;
  23. ; Revision History:
  24. ;
  25. ;--
  26. .386p
  27. .xlist
  28. include ks386.inc
  29. include callconv.inc ; calling convention macros
  30. .list
  31. ifndef WX86_i386
  32. EXTRNP _ZwCallbackReturn,3
  33. endif
  34. EXTRNP _ZwContinue,2
  35. EXTRNP _RtlDispatchException,2
  36. EXTRNP _RtlRaiseStatus,1
  37. EXTRNP _ZwRaiseException,3
  38. EXTRNP _RtlRaiseException,1
  39. ;
  40. ; Exception record size definition.
  41. ;
  42. ExceptionRecordSize = (ErNumberParameters + 4 + 3) AND 0fffffffcH ;
  43. page ,132
  44. _TEXT SEGMENT DWORD PUBLIC 'CODE'
  45. ASSUME DS:FLAT, ES:FLAT, SS:NOTHING, FS:NOTHING, GS:NOTHING
  46. ifndef WX86_i386
  47. page
  48. subttl "User APC Dispatcher"
  49. ;++
  50. ;
  51. ; VOID
  52. ; KiUserApcDispatcher (
  53. ; IN PKNORMAL_ROUTINE NormalRoutine,
  54. ; IN PVOID NormalContext,
  55. ; IN PVOID SystemArgument1,
  56. ; IN PVOID SystemArgument2,
  57. ; IN CONTEXT ContinueContext
  58. ; )
  59. ;
  60. ; Routine Description:
  61. ;
  62. ; This routine is entered on return from kernel mode to deliver an APC
  63. ; in user mode. The context frame for this routine was built when the
  64. ; APC interrupt was processed and contains the entire machine state of
  65. ; the current thread. The specified APC routine is called and then the
  66. ; machine state is restored and execution is continued.
  67. ;
  68. ; Arguments:
  69. ;
  70. ; NormalRoutine - Supplies that address of the function that is to be called.
  71. ;
  72. ; NormalContext] - Supplies the normal context parameter that was specified
  73. ; when the APC was initialized.
  74. ;
  75. ; SystemArgument1 - Supplies the first argument that was provied by the
  76. ; executive when the APC was queued.
  77. ;
  78. ; SystemArgument2 - Supplies the second argument that was provided by
  79. ; the executive when the APC was queued.
  80. ;
  81. ; ContinueContext - Context record to pass to Continue call.
  82. ;
  83. ;
  84. ; Return Value:
  85. ;
  86. ; None.
  87. ;
  88. ;--
  89. cPublicProc _KiUserApcDispatcher ,5
  90. lea edi, [esp+16] ; (edi)->context frame
  91. pop eax ; (eax)->specified function
  92. call eax ; call the specified function
  93. ; 1 - set alert argument true
  94. ; ebp - addr of context frame
  95. ; execute system service to continue
  96. stdCall _ZwContinue, <edi, 1>
  97. stdENDP _KiUserApcDispatcher
  98. page
  99. subttl "User Callback Dispatcher"
  100. ;++
  101. ;
  102. ; VOID
  103. ; KiUserCallbackDispatcher (
  104. ; IN ULONG ApiNumber,
  105. ; IN PVOID InputBuffer,
  106. ; IN ULONG INputLength
  107. ; )
  108. ;
  109. ; Routine Description:
  110. ;
  111. ; This routine is entered on a callout from kernel mode to execute a
  112. ; user mode callback function. All arguments for this function have
  113. ; been placed on the stack.
  114. ;
  115. ; Arguments:
  116. ;
  117. ; ApiNumber - Supplies the API number of the callback function that is
  118. ; executed.
  119. ;
  120. ; InputBuffer - Supplies a pointer to the input buffer.
  121. ;
  122. ; InputLength - Supplies the input buffer length.
  123. ;
  124. ; Return Value:
  125. ;
  126. ; This function returns to kernel mode.
  127. ;
  128. ;--
  129. cPublicProc _KiUserCallbackDispatcher, 3
  130. .FPO (0, 0, 0, 0, 0, 0)
  131. add esp,4 ; skip over return address
  132. pop edx ; get address of callback function
  133. ; get peb pointer from teb
  134. mov eax,fs:[PcTeb]
  135. mov eax,[eax].TebPeb
  136. mov eax,[eax].PebKernelCallbackTable ; get address of callback table
  137. call [eax+edx*4] ; call specified function
  138. ;
  139. ; If a return from the callback function occurs, then the output buffer
  140. ; address and length are returned as NULL.
  141. ;
  142. xor ecx,ecx ; clear output buffer address
  143. ifdef BUILD_WOW6432
  144. stdCall _ZwCallbackReturn, <ecx, ecx, eax>
  145. else
  146. xor edx,edx ; clear output buffer length
  147. int 02bH ; return from callback
  148. endif
  149. int 3 ; break if return occurs
  150. stdENDP _KiUserCallbackDispatcher
  151. endif ;; ndef WX86_i386
  152. page
  153. subttl "User Exception Dispatcher"
  154. ;++
  155. ;
  156. ; VOID
  157. ; KiUserExceptionDispatcher (
  158. ; IN PEXCEPTION_RECORD ExceptionRecord,
  159. ; IN PCONTEXT ContextRecord
  160. ; )
  161. ;
  162. ; Routine Description:
  163. ;
  164. ; This routine is entered on return from kernel mode to dispatch a user
  165. ; mode exception. If a frame based handler handles the exception, then
  166. ; the execution is continued. Else last chance processing is performed.
  167. ;
  168. ; NOTE: This procedure is not called, but rather dispatched to.
  169. ; It depends on there not being a return address on the stack
  170. ; (assumption w.r.t. argument offsets.)
  171. ;
  172. ; Arguments:
  173. ;
  174. ; ExceptionRecord (esp+0) - Supplies a pointer to an exception record.
  175. ;
  176. ; ContextRecord (esp+4) - Supplies a pointer to a context frame.
  177. ;
  178. ; Return Value:
  179. ;
  180. ; None.
  181. ;
  182. ;--
  183. cPublicProc _KiUserExceptionDispatcher ,2
  184. .FPO (0, 2, 0, 0, 0, 0)
  185. mov ecx, [esp+4] ; (ecx)->context record
  186. mov ebx, [esp] ; (ebx)->exception record
  187. ; attempt to dispatch the exception
  188. stdCall _RtlDispatchException, <ebx, ecx>
  189. ;
  190. ; If the return status is TRUE, then the exception was handled and execution
  191. ; should be continued with the NtContinue service in case the context was
  192. ; changed. If the return statusn is FALSE, then the exception was not handled
  193. ; and ZwRaiseException is called to perform last chance exception processing.
  194. ;
  195. or al,al
  196. je short kued10
  197. ;
  198. ; Continue execution.
  199. ;
  200. pop ebx ; (ebx)->exception record
  201. pop ecx ; (ecx)->context record
  202. ; continue execution
  203. stdCall _ZwContinue, <ecx, 0>
  204. jmp short kued20 ; join common code
  205. ;
  206. ; Last chance processing.
  207. ;
  208. ; (esp+0) = ExceptionRecord
  209. ; (esp+4) = ContextRecord
  210. ;
  211. kued10: pop ebx ; (ebx)->exception record
  212. pop ecx ; (ecx)->context record
  213. ; ecx - context record
  214. ; ebx - exception record
  215. ; perform last chance processiong
  216. stdCall _ZwRaiseException, <ebx, ecx, 0>
  217. ;
  218. ; Common code for nonsuccessful completion of the continue or raiseexception
  219. ; services. Use the return status as the exception code, set noncontinuable
  220. ; exception and attempt to raise another exception. Note the stack grows
  221. ; and eventually this loop will end.
  222. ;
  223. .FPO(0, 0, 0, 0, 0, 0)
  224. kued20: add esp, -ExceptionRecordSize ; allocate stack space
  225. mov [esp]+ErExceptionCode, eax ; set exception code
  226. mov dword ptr [esp]+ErExceptionFlags, EXCEPTION_NONCONTINUABLE
  227. mov [esp]+ErExceptionRecord,ebx ; set associated exception record
  228. mov dword ptr [esp]+ErNumberParameters, 0
  229. ; set number of parameters
  230. ; esp - addr of exception record
  231. stdCall _RtlRaiseException, <esp>
  232. ; never return
  233. stdRET _KiUserExceptionDispatcher
  234. stdENDP _KiUserExceptionDispatcher
  235. page
  236. subttl "Raise User Exception Dispatcher"
  237. ifndef WX86_i386
  238. ;++
  239. ;
  240. ; NTSTATUS
  241. ; KiUserExceptionDispatcher (
  242. ; IN PVOID ReturnAddress
  243. ; IN NTSTATUS ExceptionCode
  244. ; )
  245. ;
  246. ; Routine Description:
  247. ;
  248. ; This routine is entered on return from kernel mode to raise a user
  249. ; mode exception.
  250. ;
  251. ; NOTE: This procedure is not called, but rather dispatched to.
  252. ;
  253. ; The exception code to be raised is passed in the TEB.
  254. ;
  255. ; Arguments:
  256. ;
  257. ; ExceptionCode (TEB->ExceptionCode) - Supplies the exception code to be raised
  258. ;
  259. ; Return Value:
  260. ;
  261. ; The exception code that was raised.
  262. ;
  263. ;--
  264. cPublicProc _KiRaiseUserExceptionDispatcher
  265. push ebp ; make the debugger happy
  266. mov ebp, esp
  267. sub esp, ExceptionRecordLength ; allocate exception record
  268. mov [esp].ErExceptionAddress, eax ; set exception address
  269. mov eax,fs:[PcTeb] ; get exception code to be raised
  270. mov eax,[eax].TbExceptionCode ;
  271. mov [esp].ErExceptionCode, eax ; store exception code
  272. mov [esp].ErExceptionFlags, 0 ; set exception flags
  273. mov [esp].ErExceptionRecord, 0 ; set exception record
  274. mov [esp].ErNumberParameters, 0 ; set number of parameters
  275. ; raise the exception
  276. stdCall _RtlRaiseException, <esp>
  277. mov eax, [esp].ErExceptionCode
  278. mov esp,ebp
  279. pop ebp ; restore return code
  280. ret
  281. stdENDP _KiRaiseUserExceptionDispatcher
  282. endif ;; ndef WX86_i386
  283. _TEXT ENDS
  284. END