Counter Strike : Global Offensive Source Code
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
3.7 KiB

  1. ; call cpuid with args in eax, ecx
  2. ; store eax, ebx, ecx, edx to p
  3. option casemap:none
  4. PUBLIC GetStackPtr64
  5. .CODE
  6. GetStackPtr64 PROC FRAME
  7. ; unsigned char* GetStackPtr64(void);
  8. .endprolog
  9. mov rax, rsp ; get stack ptr
  10. add rax, 8h ; account for 8-byte return value of this function
  11. ret
  12. GetStackPtr64 ENDP
  13. ; Needs to match definition found in setjmp.h
  14. _JUMP_BUFFER STRUCT
  15. m_Frame QWORD ?
  16. m_Rbx QWORD ?
  17. m_Rsp QWORD ?
  18. m_Rbp QWORD ?
  19. m_Rsi QWORD ?
  20. m_Rdi QWORD ?
  21. m_R12 QWORD ?
  22. m_R13 QWORD ?
  23. m_R14 QWORD ?
  24. m_R15 QWORD ?
  25. m_Rip QWORD ?
  26. m_MxCsr DWORD ?
  27. m_FpCsr WORD ?
  28. m_Spare WORD ?
  29. m_Xmm6 XMMWORD ?
  30. m_Xmm7 XMMWORD ?
  31. m_Xmm8 XMMWORD ?
  32. m_Xmm9 XMMWORD ?
  33. m_Xmm10 XMMWORD ?
  34. m_Xmm11 XMMWORD ?
  35. m_Xmm12 XMMWORD ?
  36. m_Xmm13 XMMWORD ?
  37. m_Xmm14 XMMWORD ?
  38. m_Xmm15 XMMWORD ?
  39. _JUMP_BUFFER ENDS
  40. ;This is the reference asm for __intrinsic_setjmp() in VS2015
  41. ;mov qword ptr [rcx],rdx ; intrinsic call site does "mov rdx,rbp" followed by "add rdx,0FFFFFFFFFFFFFFC0h", looks like a nonstandard abi
  42. ;mov qword ptr [rcx+8],rbx
  43. ;mov qword ptr [rcx+18h],rbp
  44. ;mov qword ptr [rcx+20h],rsi
  45. ;mov qword ptr [rcx+28h],rdi
  46. ;mov qword ptr [rcx+30h],r12
  47. ;mov qword ptr [rcx+38h],r13
  48. ;mov qword ptr [rcx+40h],r14
  49. ;mov qword ptr [rcx+48h],r15
  50. ;lea r8,[rsp+8] ; rsp set to post-return address
  51. ;mov qword ptr [rcx+10h],r8
  52. ;mov r8,qword ptr [rsp]
  53. ;mov qword ptr [rcx+50h],r8
  54. ;stmxcsr dword ptr [rcx+58h]
  55. ;fnstcw word ptr [rcx+5Ch]
  56. ;movdqa xmmword ptr [rcx+60h],xmm6
  57. ;ovdqa xmmword ptr [rcx+70h],xmm7
  58. ;movdqa xmmword ptr [rcx+80h],xmm8
  59. ;movdqa xmmword ptr [rcx+90h],xmm9
  60. ;movdqa xmmword ptr [rcx+0A0h],xmm10
  61. ;movdqa xmmword ptr [rcx+0B0h],xmm11
  62. ;movdqa xmmword ptr [rcx+0C0h],xmm12
  63. ;movdqa xmmword ptr [rcx+0D0h],xmm13
  64. ;movdqa xmmword ptr [rcx+0E0h],xmm14
  65. ;movdqa xmmword ptr [rcx+0F0h],xmm15
  66. ;xor eax,eax
  67. ;ret
  68. ; extern "C" void NORETURN Coroutine_LongJmp_UnChecked( jmp_buf buf, int nResult )
  69. ; Per Win64 ABI, incoming params are rcx, rdx, r8, r9. initial stack pointer is half-aligned due to return address
  70. Coroutine_LongJmp_Unchecked PROC
  71. ;load nResult into result from initial setjmp()
  72. xor rax, rax
  73. mov eax, edx
  74. ;restore to setjmp() caller state
  75. mov rdx, [rcx]._JUMP_BUFFER.m_Frame ; appears to be an error checking value of (_JUMP_BUFFER.m_Rbp + 0FFFFFFFFFFFFFFC0h) passed non-standardly through rdx to setjmp()
  76. mov rbx, [rcx]._JUMP_BUFFER.m_Rbx
  77. mov rsp, [rcx]._JUMP_BUFFER.m_Rsp
  78. mov rbp, [rcx]._JUMP_BUFFER.m_Rbp
  79. mov rsi, [rcx]._JUMP_BUFFER.m_Rsi
  80. mov rdi, [rcx]._JUMP_BUFFER.m_Rdi
  81. mov r12, [rcx]._JUMP_BUFFER.m_R12
  82. mov r13, [rcx]._JUMP_BUFFER.m_R13
  83. mov r14, [rcx]._JUMP_BUFFER.m_R14
  84. mov r15, [rcx]._JUMP_BUFFER.m_R15
  85. mov r10, [rcx]._JUMP_BUFFER.m_Rip ; store return address in r10 for return
  86. ldmxcsr [rcx]._JUMP_BUFFER.m_MxCsr
  87. fldcw [rcx]._JUMP_BUFFER.m_FpCsr
  88. ;[rcx]._JUMP_BUFFER.m_Spare
  89. movaps xmm6, [rcx]._JUMP_BUFFER.m_Xmm6
  90. movaps xmm7, [rcx]._JUMP_BUFFER.m_Xmm7
  91. movaps xmm8, [rcx]._JUMP_BUFFER.m_Xmm8
  92. movaps xmm9, [rcx]._JUMP_BUFFER.m_Xmm9
  93. movaps xmm10, [rcx]._JUMP_BUFFER.m_Xmm10
  94. movaps xmm11, [rcx]._JUMP_BUFFER.m_Xmm11
  95. movaps xmm12, [rcx]._JUMP_BUFFER.m_Xmm12
  96. movaps xmm13, [rcx]._JUMP_BUFFER.m_Xmm13
  97. movaps xmm14, [rcx]._JUMP_BUFFER.m_Xmm14
  98. movaps xmm15, [rcx]._JUMP_BUFFER.m_Xmm15
  99. ;jmp instead of ret to _JUMP_BUFFER.m_Rip because setjmp() already set the _JUMP_BUFFER.m_Rsp to the post-return state
  100. db 048h ; emit a REX prefix on the jmp to ensure it's a full qword
  101. jmp qword ptr r10
  102. Coroutine_LongJmp_Unchecked ENDP
  103. _TEXT ENDS
  104. END