Windows NT 4.0 source code leak
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.

181 lines
4.2 KiB

4 years ago
  1. title "Raise Exception"
  2. ;++
  3. ;
  4. ; Copyright (c) 1989 Microsoft Corporation
  5. ;
  6. ; Module Name:
  7. ;
  8. ; raise.asm
  9. ;
  10. ; Abstract:
  11. ;
  12. ; This module implements the function to raise a software exception.
  13. ;
  14. ; Author:
  15. ;
  16. ; Bryan Willman 11 april 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 _ZwRaiseException,3
  31. _TEXT SEGMENT DWORD PUBLIC 'CODE'
  32. ASSUME DS:FLAT, ES:FLAT, SS:NOTHING, FS:NOTHING, GS:NOTHING
  33. ;
  34. ; Context flags definition.
  35. ;
  36. CONTEXT_SETTING EQU CONTEXT_INTEGER OR CONTEXT_CONTROL OR CONTEXT_SEGMENTS
  37. ;
  38. ; Exception record length definition.
  39. ;
  40. EXCEPTION_RECORD_LENGTH EQU (ErExceptionInformation + 16) AND 0fffffff0H
  41. page
  42. subttl "Raise Software Exception"
  43. ;++
  44. ;
  45. ; VOID
  46. ; RtlRaiseException (
  47. ; IN PEXCEPTION_RECORD ExceptionRecord
  48. ; )
  49. ;
  50. ; Routine Description:
  51. ;
  52. ; This function raises a software exception by building a context record,
  53. ; establishing the stack limits of the current processor mode, and calling
  54. ; the exception dispatcher. If the exception dispatcher finds a handler
  55. ; to process the exception, then control is returned to the caller using
  56. ; the NtContinue system service. Otherwise the NtLastChance system service
  57. ; is called to provide default handing.
  58. ;
  59. ; N.B. On the 386, floating point state is not defined for non-fp
  60. ; exceptions. Therefore, this routine does not attempt to
  61. ; capture it.
  62. ;
  63. ; This means this routine cannot be used to report fp exceptions.
  64. ;
  65. ; Arguments:
  66. ;
  67. ; ExceptionRecord (ebp+8) - Supplies a pointer to an exception record.
  68. ;
  69. ; Return Value:
  70. ;
  71. ; None.
  72. ;
  73. ;--
  74. cPublicProc _RtlRaiseException ,1
  75. push ebp
  76. mov ebp,esp
  77. pushfd ; save flags before sub
  78. sub esp,ContextFrameLength ; Allocate a context record
  79. ;
  80. ; Save regs we use in context record
  81. ;
  82. mov [(ebp-ContextFrameLength-4)+CsEax],eax
  83. mov [(ebp-ContextFrameLength-4)+CsEcx],ecx
  84. ;
  85. ; Get pointer to exception report record, and set the exceptionaddress
  86. ; field to be our return address
  87. ;
  88. mov eax,[ebp+8] ; (eax) -> ExceptionReportRecord
  89. mov ecx,[ebp+4]
  90. mov [eax.ErExceptionAddress],ecx
  91. ;
  92. ; Copy machine context into the context record
  93. ;
  94. lea eax,[ebp-ContextFrameLength-4] ; (eax) -> Context record
  95. mov [eax.CsEip],ecx
  96. mov [eax.CsEbx],ebx
  97. mov [eax.CsEdx],edx
  98. mov [eax.CsEsi],esi
  99. mov [eax.CsEdi],edi
  100. ;
  101. ; context record's ESP must have the argument popped off the stack
  102. ;
  103. lea ecx,[ebp+12]
  104. mov [eax.CsEsp],ecx
  105. mov ecx,[ebp]
  106. mov [eax.CsEbp],ecx
  107. mov ecx,[ebp-4]
  108. mov [eax.CsEflags],ecx
  109. mov dword ptr [eax.CsSegCs],cs
  110. mov dword ptr [eax.CsSegDs],ds
  111. mov dword ptr [eax.CsSegEs],es
  112. mov dword ptr [eax.CsSegFs],fs
  113. mov dword ptr [eax.CsSegGs],gs
  114. mov dword ptr [eax.CsSegSs],ss
  115. ;
  116. ; Set Context flags, note that FLOATING_POINT is NOT set.
  117. ;
  118. mov dword ptr [eax.CsContextFlags],CONTEXT_SETTING
  119. ;
  120. ; _ZwRaiseException(ExceptionRecord, ContextRecord, FirstChance=TRUE)
  121. ;
  122. ; 1 - TRUE
  123. ; eax - Context Record
  124. ; [ebp+8] - Exception Report Record
  125. stdCall _ZwRaiseException,<[ebp+8],eax,1>
  126. ;
  127. ; We came back, suggesting some sort of error in the call. Raise
  128. ; a status exception to report this, return from ZwRaiseException is type.
  129. ;
  130. sub esp,EXCEPTION_RECORD_LENGTH ; allocate record on stack, esp is base
  131. mov [esp.ErExceptionCode],eax ; set exception type
  132. or dword ptr [esp.ErExceptionFlags],EXCEPTION_NONCONTINUABLE
  133. mov dword ptr [esp.ErNumberParameters],0 ; no parms
  134. mov eax,[ebp+8]
  135. mov [esp.ErExceptionRecord],eax ; point back to first exception
  136. mov eax,esp
  137. stdCall _RtlRaiseException,<eax>
  138. ;
  139. ; We will never come here, because RtlRaiseException will not allow
  140. ; return if exception is non-continuable.
  141. ;
  142. stdENDP _RtlRaiseException
  143. _TEXT ends
  144. end