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.

117 lines
3.1 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. altentry setjmp
  31. ;
  32. ; Define variable that will cause setjmp/longjmp to be safe or unsafe with
  33. ; respect to structured exception handling.
  34. ;
  35. _setjmp_ segment para common 'DATA'
  36. _setjmpexused dq ? ;
  37. _setjmp_ ends
  38. subttl "Unsafe Set Jump"
  39. ;++
  40. ;
  41. ; int
  42. ; _setjmp (
  43. ; IN jmp_buf JumpBuffer,
  44. ; IN ULONG64 FrameBase
  45. ; )
  46. ;
  47. ; Routine Description:
  48. ;
  49. ; This function saved the current nonvolatile register state in the
  50. ; specified jump buffer and returns a function vlaue of zero.
  51. ;
  52. ; Arguments:
  53. ;
  54. ; JumpBuffer (rcx) - Supplies a pointer to a jump buffer.
  55. ;
  56. ; Framebase (rdx) - Supplies the base of the caller frame.
  57. ;
  58. ; Return Value:
  59. ;
  60. ; A value of zero is returned.
  61. ;
  62. ;--
  63. LEAF_ENTRY _setjmp, _TEXT$00
  64. ALTERNATE_ENTRY setjmp
  65. mov rax, _setjmpexused ; get address of safe set jump routine
  66. test rax, rax ; test is safe set jump specified
  67. jnz SJ10 ; if nz, safe set jump specified
  68. ;
  69. ; Structured exception handling is not being used - use unsafe set jump.
  70. ;
  71. mov JbFrame[rcx], rax ; zero frame register
  72. mov JbRbx[rcx], rbx ; save nonvolatile integer registers
  73. mov JbRbp[rcx], rbp ;
  74. mov JbRsi[rcx], rsi ;
  75. mov JbRdi[rcx], rdi ;
  76. mov JbR12[rcx], r12 ;
  77. mov JbR13[rcx], r13 ;
  78. mov JbR14[rcx], r14 ;
  79. mov JbR15[rcx], r15 ;
  80. lea r8, 8[rsp] ; save caller stack pointer
  81. mov JbRsp[rcx], r8 ;
  82. mov r8, [rsp] ; save caller return address
  83. mov JbRip[rcx], r8 ;
  84. movdqa JbXmm6[rcx], xmm6 ; save nonvolatile floating registers
  85. movdqa JbXmm7[rcx], xmm7 ;
  86. movdqa JbXmm8[rcx], xmm8 ;
  87. movdqa JbXmm9[rcx], xmm9 ;
  88. movdqa JbXmm10[rcx], xmm10 ;
  89. movdqa JbXmm11[rcx], xmm11 ;
  90. movdqa JbXmm12[rcx], xmm12 ;
  91. movdqa JbXmm13[rcx], xmm13 ;
  92. movdqa JbXmm14[rcx], xmm14 ;
  93. movdqa JbXmm15[rcx], xmm15 ;
  94. ret ; return
  95. ;
  96. ; Structured exception handling is being used - use safe set jump.
  97. ;
  98. SJ10: jmp rax ; execute safe set jump
  99. LEAF_END _setjmp, _TEXT$00
  100. end