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.

120 lines
2.9 KiB

  1. title "Miscellaneous Exception Handling"
  2. ;++
  3. ;
  4. ; Copyright (c) 1989 Microsoft Corporation
  5. ;
  6. ; Module Name:
  7. ;
  8. ; xcptmisc.asm
  9. ;
  10. ; Abstract:
  11. ;
  12. ; This module implements miscellaneous routines that are required to
  13. ; support exception handling. Functions are provided to call an exception
  14. ; handler for an exception, call an exception handler for unwinding, get
  15. ; the caller's stack pointer, get the caller's frame pointer, get the
  16. ; caller's floating status, get the caller's processor state, get the
  17. ; caller's extended processor status, and get the current stack limits.
  18. ;
  19. ; Author:
  20. ;
  21. ; David N. Cutler (davec) 14-Aug-1989
  22. ;
  23. ; Environment:
  24. ;
  25. ; Any mode.
  26. ;
  27. ; Revision History:
  28. ;
  29. ; Keith Moore (keithmo) 12-Sep-1997
  30. ;
  31. ; Stolen from ntdll for use in IIS.
  32. ;
  33. ;--
  34. .386p
  35. .xlist
  36. include ks386.inc
  37. include callconv.inc ; calling convention macros
  38. .list
  39. _TEXT$01 SEGMENT DWORD PUBLIC 'CODE'
  40. ASSUME DS:FLAT, ES:FLAT, SS:NOTHING, FS:NOTHING, GS:NOTHING
  41. page
  42. subttl "Capture Context"
  43. ;++
  44. ;
  45. ; VOID
  46. ; PuDbgCaptureContext (PCONTEXT ContextRecord)
  47. ;
  48. ; Routine Description:
  49. ;
  50. ; This fucntion fills in the specified context record with the
  51. ; current state of the machine, except that the values of EBP
  52. ; and ESP are computed to be those of the caller's caller.
  53. ;
  54. ; N.B. This function assumes it is called from a 'C' procedure with
  55. ; the old ebp at [ebp], the return address at [ebp+4], and
  56. ; old esp = ebp + 8.
  57. ;
  58. ; Certain 'C' optimizations may cause this to not be true.
  59. ;
  60. ; N.B. This function does NOT adjust ESP to pop the arguments off
  61. ; the caller's stack. In other words, it provides a __cdecl ESP,
  62. ; NOT a __stdcall ESP. This is mainly because we can't figure
  63. ; out how many arguments the caller takes.
  64. ;
  65. ; N.B. Floating point state is NOT captured.
  66. ;
  67. ; Arguments:
  68. ;
  69. ; ContextRecord (esp+4) - Address of context record to fill in.
  70. ;
  71. ; Return Value:
  72. ;
  73. ; The caller's return address.
  74. ;
  75. ;--
  76. cPublicProc _PuDbgCaptureContext ,1
  77. push ebx
  78. mov ebx,[esp+8] ; (ebx) -> ContextRecord
  79. mov dword ptr [ebx.CsEax],eax
  80. mov dword ptr [ebx.CsEcx],ecx
  81. mov dword ptr [ebx.CsEdx],edx
  82. mov eax, [esp]
  83. mov dword ptr [ebx.CsEbx],eax
  84. mov dword ptr [ebx.CsEsi],esi
  85. mov dword ptr [ebx.CsEdi],edi
  86. mov [ebx.CsSegCs],cs
  87. mov [ebx.CsSegDs],ds
  88. mov [ebx.CsSegEs],es
  89. mov [ebx.CsSegFs],fs
  90. mov [ebx.CsSegGs],gs
  91. mov [ebx.CsSegSs],ss
  92. pushfd
  93. pop [ebx.CsEflags]
  94. mov eax,[ebp+4]
  95. mov [ebx.CsEip],eax
  96. mov eax,[ebp]
  97. mov [ebx.CsEbp],eax
  98. lea eax,[ebp+8]
  99. mov [ebx.CsEsp],eax
  100. pop ebx
  101. stdRET _PuDbgCaptureContext
  102. stdENDP _PuDbgCaptureContext
  103. _TEXT$01 ends
  104. end