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.

113 lines
2.9 KiB

  1. title "Set Jump Buffer"
  2. ;++
  3. ;
  4. ; Copyright (c) 2000 Microsoft Corporation
  5. ;
  6. ; Module Name:
  7. ;
  8. ; setjmp.asm
  9. ;
  10. ; Abstract:
  11. ;
  12. ; This module implements the AMD64 specific routine to perform unsafe set
  13. ; jump.
  14. ;
  15. ; N.B. This module conditionally provides unsafe handling of setjmp if
  16. ; structured exception handling is not being used. The determination
  17. ; is made based on whether an uninitialized variable has been set to
  18. ; the address of the safe set jump routine.
  19. ;
  20. ; Author:
  21. ;
  22. ; David N. Cutler (davec) 3-Nov-2000
  23. ;
  24. ; Environment:
  25. ;
  26. ; Any mode.
  27. ;
  28. ;--
  29. include ksamd64.inc
  30. ;
  31. ; Define variable that will cause setjmp/longjmp to be safe or unsafe with
  32. ; respect to structured exception handling.
  33. ;
  34. _setjmp_ segment para common 'DATA'
  35. _setjmpexused dq ? ;
  36. _setjmp_ ends
  37. subttl "Unsafe Set Jump"
  38. ;++
  39. ;
  40. ; int
  41. ; _setjmp (
  42. ; IN jmp_buf JumpBuffer,
  43. ; IN ULONG64 FrameBase
  44. ; )
  45. ;
  46. ; Routine Description:
  47. ;
  48. ; This function saved the current nonvolatile register state in the
  49. ; specified jump buffer and returns a function vlaue of zero.
  50. ;
  51. ; Arguments:
  52. ;
  53. ; JumpBuffer (rcx) - Supplies a pointer to a jump buffer.
  54. ;
  55. ; Framebase (rdx) - Supplies the base of the caller frame.
  56. ;
  57. ; Return Value:
  58. ;
  59. ; A value of zero is returned.
  60. ;
  61. ;--
  62. LEAF_ENTRY _setjmp, _TEXT$00
  63. mov rax, _setjmpexused ; get address of safe set jump routine
  64. test rax, rax ; test is safe set jump specified
  65. jnz SJ10 ; if nz, safe set jump specified
  66. ;
  67. ; Structured exception handling is not being used - use unsafe set jump.
  68. ;
  69. mov JbFrame[rcx], rax ; zero frame register
  70. mov JbRbx[rcx], rbx ; save nonvolatile integer registers
  71. mov JbRbp[rcx], rbp ;
  72. mov JbRsi[rcx], rsi ;
  73. mov JbRdi[rcx], rdi ;
  74. mov JbR12[rcx], r12 ;
  75. mov JbR13[rcx], r13 ;
  76. mov JbR14[rcx], r14 ;
  77. mov JbR15[rcx], r15 ;
  78. lea r8, 8[rsp] ; save caller stack pointer
  79. mov JbRsp[rcx], r8 ;
  80. mov r8, [rsp] ; save caller return address
  81. mov JbRip[rcx], r8 ;
  82. movdqa JbXmm6[rcx], xmm6 ; save nonvolatile floating registers
  83. movdqa JbXmm7[rcx], xmm7 ;
  84. movdqa JbXmm8[rcx], xmm8 ;
  85. movdqa JbXmm9[rcx], xmm9 ;
  86. movdqa JbXmm10[rcx], xmm10 ;
  87. movdqa JbXmm11[rcx], xmm11 ;
  88. movdqa JbXmm12[rcx], xmm12 ;
  89. movdqa JbXmm13[rcx], xmm13 ;
  90. movdqa JbXmm14[rcx], xmm14 ;
  91. movdqa JbXmm15[rcx], xmm15 ;
  92. ret ; return
  93. ;
  94. ; Structured exception handling is being used - use safe set jump.
  95. ;
  96. SJ10: jmp rax ; execute safe set jump
  97. LEAF_END _setjmp, _TEXT$00
  98. end