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.

148 lines
4.9 KiB

  1. title "Long Jump"
  2. ;++
  3. ;
  4. ; Copyright (c) 2000 Microsoft Corporation
  5. ;
  6. ; Module Name:
  7. ;
  8. ; longjmp.asm
  9. ;
  10. ; Abstract:
  11. ;
  12. ; This module implements the AMD64 specific routine to perform a long
  13. ; jump.
  14. ;
  15. ; N.B. This routine conditionally provides unsafe handling of long jump if
  16. ; structured exception handling is not being used. The determination
  17. ; is made based on the contents of the jump buffer.
  18. ;
  19. ; Author:
  20. ;
  21. ; David N. Cutler (davec) 4-Jul-2000
  22. ;
  23. ; Environment:
  24. ;
  25. ; Any mode.
  26. ;
  27. ;--
  28. include ksamd64.inc
  29. extern RtlUnwindEx:proc
  30. subttl "Long Jump"
  31. ;++
  32. ;
  33. ; VOID
  34. ; longjmp (
  35. ; IN jmp_buf Jumpbuffer
  36. ; IN int ReturnValue
  37. ; )
  38. ;
  39. ; Routine Description:
  40. ;
  41. ; This function performs a long jump to the context specified by the
  42. ; jump buffer.
  43. ;
  44. ; Arguments:
  45. ;
  46. ; JumpBuffer (rcx) - Supplies the address of a jump buffer.
  47. ;
  48. ; ReturnValue (edx) - Supplies the value that is to be returned to the
  49. ; caller of set jump.
  50. ;
  51. ; Return Value:
  52. ;
  53. ; None.
  54. ;
  55. ;--
  56. LjFrame struct
  57. P1Home dq ? ; target frame home address
  58. P2Home dq ? ; target IP home address
  59. P3Home dq ? ; exception record address home address
  60. P4Home dq ? ; return value home address
  61. P5Home dq ? ; context record address parameter
  62. P6Home dq ? ; history table address
  63. Excode dd ? ; exception code
  64. Flags dd ? ; exception flags
  65. Associate dq ? ; associated exception record
  66. Address dq ? ; exception address
  67. Number dd ? ; number of parameters
  68. Fill1 dd ? ; fill to qword boundary
  69. Jmpbuf dq ? ; address of jump buffer
  70. Fill2 dq ? ; align to 0 mod 16
  71. Context db CONTEXT_FRAME_LENGTH dup (?) ; context record
  72. Fill3 dq ? ; align to 8 mod 16
  73. LjFrame ends
  74. NESTED_ENTRY longjmp, _TEXT$00
  75. alloc_stack (sizeof LjFrame) ; allocate stack frame
  76. END_PROLOGUE
  77. test rdx, rdx ; test if return value nonzero
  78. jnz short LJ10 ; if nz, return value not zero
  79. inc rdx ; set nonzero return value
  80. LJ10: xor r10, r10 ; generate zero value
  81. cmp JbFrame[rcx], r10 ; check for safe/unsafe long jump
  82. jne LJ20 ; if ne, safe long jump
  83. ;
  84. ; Provide unsafe handling of long jump.
  85. ;
  86. mov rax, rdx ; set return value
  87. mov rbx, JbRbx[rcx] ; restore nonvolatile integer registers
  88. mov rsi, JbRsi[rcx] ;
  89. mov rdi, JbRdi[rcx] ;
  90. mov r12, JbR12[rcx] ;
  91. mov r13, JbR13[rcx] ;
  92. mov r14, JbR14[rcx] ;
  93. mov r15, JbR15[rcx] ;
  94. movdqa xmm6, JbXmm6[rcx] ; save nonvolatile floating registers
  95. movdqa xmm7, JbXmm7[rcx] ;
  96. movdqa xmm8, JbXmm8[rcx] ;
  97. movdqa xmm9, JbXmm9[rcx] ;
  98. movdqa xmm10, JbXmm10[rcx] ;
  99. movdqa xmm11, JbXmm11[rcx] ;
  100. movdqa xmm12, JbXmm12[rcx] ;
  101. movdqa xmm13, JbXmm13[rcx] ;
  102. movdqa xmm14, JbXmm14[rcx] ;
  103. movdqa xmm15, JbXmm15[rcx] ;
  104. mov rdx, JbRip[rcx] ; get return address
  105. mov rbp, JbRbp[rcx] ; set frame pointer
  106. mov rsp, JbRsp[rcx] ; set stack pointer
  107. jmp rdx ; jump back to set jump site
  108. ;
  109. ; Provide safe handling of long jump.
  110. ;
  111. ; An exception record is constructed that contains a long jump status
  112. ; code and the first exception information parameter is a pointer to
  113. ; the jump buffer.
  114. ;
  115. LJ20: mov LjFrame.Excode[rsp], STATUS_LONGJUMP ; set exception code
  116. mov LjFrame.Flags[rsp], r10d ; zero exception flags
  117. mov LjFrame.Associate[rsp], r10 ; zero associated record address
  118. mov LjFrame.Address[rsp], r10 ; zero exception address
  119. mov LjFrame.P6Home[rsp], r10 ; set address of history table
  120. inc r10d ; set number of parameters
  121. mov LjFrame.Number[rsp], r10d ;
  122. mov LjFrame.Jmpbuf[rsp], rcx ; set jump buffer address
  123. lea rax, LjFrame.Context[rsp] ; set address of context record
  124. mov LjFrame.P5Home[rsp], rax ;
  125. mov r9, rdx ; set return value
  126. lea r8, LjFrame.Excode[rsp] ; set address of exception record
  127. mov rdx, JbRip[rcx] ; set target IP
  128. mov rcx, JbFrame[rcx] ; set target frame
  129. call RtlUnwindEx ; unwind to set jump target
  130. jmp short LJ20 ;
  131. NESTED_END longjmp, _TEXT$00
  132. end