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.

144 lines
3.9 KiB

  1. ;***
  2. ;setjmp3.asm
  3. ;
  4. ; Copyright (C) 1994-2001, Microsoft Corporation. All rights reserved.
  5. ;
  6. ;Purpose:
  7. ; Contains setjmp(), longjmp() & raisex() routines;
  8. ; split from exsup.asm for granularity purposes.
  9. ;
  10. ;Notes:
  11. ;
  12. ;Revision History:
  13. ; 01-12-94 PML Split from setjmp.asm, added C9.0 generic EH
  14. ; callback for unwind.
  15. ; 02-10-94 GJF -1 is the end-of-exception-handler chain marker, not 0.
  16. ; 01-11-95 SKS Remove MASM 5.X support
  17. ;
  18. ;*******************************************************************************
  19. ;hnt = -D_WIN32 -Dsmall32 -Dflat32 -Mx $this;
  20. ;Define small32 and flat32 since these are not defined in the NT build process
  21. small32 equ 1
  22. flat32 equ 1
  23. .xlist
  24. include pversion.inc
  25. ?DFDATA = 1
  26. ?NODATA = 1
  27. include cmacros.inc
  28. include exsup.inc
  29. .list
  30. assumes DS,DATA
  31. assumes FS,DATA
  32. BeginCODE
  33. ; Following symbol defined in exsup.asm
  34. extrn __except_list:near
  35. ; int
  36. ; _setjmp3 (
  37. ; OUT jmp_buf env,
  38. ; int count,
  39. ; ...)
  40. ;
  41. ; Routine Description:
  42. ;
  43. ; (New) implementation of setjmp intrinsic. Saves the current
  44. ; nonvolatile register state in the specified jump buffer and returns
  45. ; a function value of zero.
  46. ;
  47. ; Saves the callee-save registers, stack pointer and return address.
  48. ; Also saves the exception registration list head. If setjmp is
  49. ; called from a function using any form of exception handling, then
  50. ; additional data is also saved allowing some form of local unwind
  51. ; at longjmp time to restore the proper exception handling state.
  52. ;
  53. ; Arguments:
  54. ;
  55. ; env - Address of the buffer for storing the state information
  56. ; count - count of additional DWORDs of information. Zero if setjmp
  57. ; not called from a function with any form of EH.
  58. ; ... Additional data pushed by the setjmp intrinsic if called
  59. ; from a function with any form of EH. The first DWORD is
  60. ; a function ptr which will be called at longjmp time to do
  61. ; the local unwind. The second DWORD is the try level to be
  62. ; restored (if applicable). Any further data is saved in the
  63. ; generic data array in the jmp_buf for use by the local
  64. ; unwind function.
  65. ;
  66. ; Return Value:
  67. ;
  68. ; A value of zero is returned.
  69. public __setjmp3
  70. __setjmp3 PROC NEAR
  71. mov edx, [esp+4]
  72. mov [edx.saved_ebp], ebp ; old bp and the rest
  73. mov [edx.saved_ebx], ebx
  74. mov [edx.saved_edi], edi
  75. mov [edx.saved_esi], esi
  76. mov [edx.saved_esp], esp
  77. mov eax, [esp] ; return address
  78. mov [edx.saved_return], eax
  79. mov dword ptr [edx.version_cookie], JMPBUF_COOKIE
  80. mov dword ptr [edx.unwind_func], 0
  81. mov eax, dword ptr fs:__except_list
  82. mov [edx.saved_xregistration], eax
  83. cmp eax, -1 ; -1 means no higher-level handler
  84. jnz short _s3_get_count
  85. mov dword ptr [edx.saved_trylevel], -1 ;something invalid
  86. jmp short _s3_done
  87. _s3_get_count:
  88. mov ecx, [esp+8] ; count of additional data
  89. or ecx, ecx
  90. jz short _s3_default_trylevel
  91. mov eax, [esp+12] ; func to do local unwind at longjmp
  92. mov [edx.unwind_func], eax
  93. dec ecx
  94. jnz _s3_save_trylevel
  95. ; Not called from a function with any form of EH, or no trylevel
  96. ; passed. Save the TryLevel from the topmost EH node anyway,
  97. ; assuming a C8.0 SEH node. If we're linked to an obsolete CRTDLL
  98. ; and call the old longjmp, then we'll still do the right thing.
  99. _s3_default_trylevel:
  100. mov eax, [eax + C8_TRYLEVEL]
  101. mov [edx.saved_trylevel], eax
  102. jmp short _s3_done
  103. _s3_save_trylevel:
  104. mov eax, [esp+16] ; try level to unwind to
  105. mov [edx.saved_trylevel], eax
  106. dec ecx
  107. jz short _s3_done
  108. push esi
  109. push edi
  110. lea esi, [esp+20+8]
  111. lea edi, [edx.unwind_data]
  112. cmp ecx, 6 ; save up to 6 more DWORDs in jmp_buf
  113. jbe _s3_save_data
  114. mov ecx, 6
  115. _s3_save_data:
  116. rep movsd
  117. pop edi
  118. pop esi
  119. _s3_done:
  120. sub eax, eax
  121. ret
  122. __setjmp3 ENDP
  123. EndCODE
  124. END