Thunks.asm 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. ;-------------------------------------------------------------------------------------------------------
  2. ; Copyright (C) Microsoft. All rights reserved.
  3. ; Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. ;-------------------------------------------------------------------------------------------------------
  5. include ksamd64.inc
  6. _TEXT SEGMENT
  7. ifdef _CONTROL_FLOW_GUARD
  8. extrn __guard_check_icall_fptr:QWORD
  9. endif
  10. ;;============================================================================================================
  11. ;; NativeCodeGenerator::CheckCodeGenThunk
  12. ;;============================================================================================================
  13. extrn ?CheckCodeGen@NativeCodeGenerator@@SAP6APEAXPEAVRecyclableObject@Js@@UCallInfo@3@ZZPEAVScriptFunction@3@@Z : PROC
  14. align 16
  15. ?CheckCodeGenThunk@NativeCodeGenerator@@SAPEAXPEAVRecyclableObject@Js@@UCallInfo@3@ZZ PROC FRAME
  16. ;; save volatile registers
  17. mov qword ptr [rsp + 8h], rcx
  18. mov qword ptr [rsp + 10h], rdx
  19. mov qword ptr [rsp + 18h], r8
  20. mov qword ptr [rsp + 20h], r9
  21. push rbp
  22. .pushreg rbp
  23. lea rbp, [rsp]
  24. .setframe rbp, 0
  25. .endprolog
  26. ifdef _CONTROL_FLOW_GUARD
  27. sub rsp, 20h ; allocate stack space for the callee params(min 4 slots is mandate)
  28. call ?CheckCodeGen@NativeCodeGenerator@@SAP6APEAXPEAVRecyclableObject@Js@@UCallInfo@3@ZZPEAVScriptFunction@3@@Z
  29. mov rcx, rax ; __guard_check_icall_fptr requires the call target in rcx.
  30. call [__guard_check_icall_fptr] ; verify that the call target is valid
  31. add rsp, 20h ;de-allocate stack space for the callee params(min 4 slots is mandate + 1 for alignment )
  32. mov rax, rcx
  33. else
  34. sub rsp, 20h ;allocate stack space for the callee params(min 4 slots is mandate)
  35. call ?CheckCodeGen@NativeCodeGenerator@@SAP6APEAXPEAVRecyclableObject@Js@@UCallInfo@3@ZZPEAVScriptFunction@3@@Z
  36. add rsp, 20h ;de-allocate stack space for the callee params(min 4 slots is mandate)
  37. endif
  38. ;EPILOGUE starts here
  39. lea rsp, [rbp]
  40. pop rbp
  41. ;; restore volatile registers
  42. mov rcx, qword ptr [rsp + 8h]
  43. mov rdx, qword ptr [rsp + 10h]
  44. mov r8, qword ptr [rsp + 18h]
  45. mov r9, qword ptr [rsp + 20h]
  46. rex_jmp_reg rax
  47. ?CheckCodeGenThunk@NativeCodeGenerator@@SAPEAXPEAVRecyclableObject@Js@@UCallInfo@3@ZZ ENDP
  48. ;;============================================================================================================
  49. ;; NativeCodeGenerator::CheckAsmJsCodeGenThunk
  50. ;;============================================================================================================
  51. extrn ?CheckAsmJsCodeGen@NativeCodeGenerator@@SAPEAXPEAVScriptFunction@Js@@@Z : PROC
  52. align 16
  53. ?CheckAsmJsCodeGenThunk@NativeCodeGenerator@@SAPEAXPEAVRecyclableObject@Js@@UCallInfo@3@ZZ PROC FRAME
  54. ;; save volatile registers
  55. mov qword ptr [rsp + 8h], rcx
  56. mov qword ptr [rsp + 10h], rdx
  57. mov qword ptr [rsp + 18h], r8
  58. mov qword ptr [rsp + 20h], r9
  59. push rbp
  60. .pushreg rbp
  61. lea rbp, [rsp]
  62. .setframe rbp, 0
  63. .endprolog
  64. sub rsp, 60h
  65. ; spill potential floating point arguments to stack
  66. movups xmmword ptr [rsp + 30h], xmm1
  67. movups xmmword ptr [rsp + 40h], xmm2
  68. movups xmmword ptr [rsp + 50h], xmm3
  69. ifdef _CONTROL_FLOW_GUARD
  70. call ?CheckAsmJsCodeGen@NativeCodeGenerator@@SAPEAXPEAVScriptFunction@Js@@@Z
  71. mov rcx, rax ; __guard_check_icall_fptr requires the call target in rcx.
  72. call [__guard_check_icall_fptr] ; verify that the call target is valid
  73. mov rax, rcx ; CFG is guaranteed not to mess up rcx
  74. else
  75. call ?CheckAsmJsCodeGen@NativeCodeGenerator@@SAPEAXPEAVScriptFunction@Js@@@Z
  76. endif
  77. ;EPILOGUE starts here
  78. movups xmm1, xmmword ptr [rsp + 30h]
  79. movups xmm2, xmmword ptr [rsp + 40h]
  80. movups xmm3, xmmword ptr [rsp + 50h]
  81. lea rsp, [rbp]
  82. pop rbp
  83. ;; restore volatile registers
  84. mov rcx, qword ptr [rsp + 8h]
  85. mov rdx, qword ptr [rsp + 10h]
  86. mov r8, qword ptr [rsp + 18h]
  87. mov r9, qword ptr [rsp + 20h]
  88. rex_jmp_reg rax
  89. ?CheckAsmJsCodeGenThunk@NativeCodeGenerator@@SAPEAXPEAVRecyclableObject@Js@@UCallInfo@3@ZZ ENDP
  90. ;;============================================================================================================
  91. _TEXT ENDS
  92. end